2016-11-01 5 views
1

Ich erhalte einen Fehler, wenn ich versuche, mein Webpack für Produktion zu laufen.Fehler von UglifyJs: SyntaxError: Unerwartetes Token: Operator (>)

ERROR in js/main.21dbce548a76ffc14cfb.js from UglifyJs 
SyntaxError: Unexpected token: operator (>) [./~/tmi.js/lib/utils.js:3,0][js/main.21dbce548a76ffc14cfb.js:3529,20] 

utils.js: 3,0 (die die gleiche wie in meinem minified js ist) ist:

// Return the second value if the first value is undefined.. 
    get: (obj1, obj2) => { return typeof obj1 === "undefined" ? obj2 : obj1; }, 

Also von Ich gehe davon aus, dass der Fehler ausgelöst wird, weil es ES6 liest, aber es doesn verstehe ES6 nicht? (Der Pfeil-Funktion)

Ich sehe nicht, was falsch hier vor sich geht, das ist mein webpack.config.js

// changed some loader syntax after reading 
// https://webpack.js.org/how-to/upgrade-from-webpack-1/ 

const path = require(`path`); 

const webpack = require(`webpack`); 
const {UglifyJsPlugin} = webpack.optimize; 

const CopyWebpackPlugin = require(`copy-webpack-plugin`); 
const ExtractTextWebpackPlugin = require(`extract-text-webpack-plugin`); 
const configHtmls = require(`webpack-config-htmls`)(); 

const extractCSS = new ExtractTextWebpackPlugin(`css/style.css`); 

// change for production build on different server path 
const publicPath = `/`; 

// hard copy assets folder for: 
// - srcset images (not loaded through html-loader) 
// - json files (through fetch) 
// - fonts via WebFontLoader 

const copy = new CopyWebpackPlugin([{ 
    from: `./src/assets`, 
    to: `assets` 
}], { 
    ignore: [ `.DS_Store` ] 
}); 

const config = { 

    entry: [ 
    `./src/css/style.css`, 
    `./src/js/script.js` 
    ], 

    resolve: { 
    // import files without extension import ... from './Test' 
    extensions: [`.js`, `.jsx`, `.css`] 
    }, 

    output: { 
    path: path.join(__dirname, `server`, `public`), 
    filename: `js/[name].[hash].js`, 
    publicPath 
    }, 

    devtool: `sourcemap`, 

    module: { 

    rules: [ 
     { 
     test: /\.css$/, 
     loader: extractCSS.extract([ 
      { 
      loader: `css`, 
      options: { 
       importLoaders: 1 
      } 
      }, 
      { 
      loader: `postcss` 
      } 
     ]) 
     }, 
     { 
     test: /\.html$/, 
     loader: `html`, 
     options: { 
      attrs: [ 
      `audio:src`, 
      `img:src`, 
      `video:src`, 
      `source:srcset` 
      ] // read src from video, img & audio tag 
     } 
     }, 
     { 
     test: /\.(jsx?)$/, 
     exclude: /node_modules/, 
     use: [ 
      { 
      loader: `babel` 
      }, 
      { 
      loader: `eslint`, 
      options: { 
       fix: true 
      } 
      } 
     ] 
     }, 
     { 
     test: /\.(svg|png|jpe?g|gif|webp)$/, 
     loader: `url`, 
     options: { 
      limit: 1000, // inline if < 1 kb 
      context: `./src`, 
      name: `[path][name].[ext]` 
     } 
     }, 
     { 
     test: /\.(mp3|mp4)$/, 
     loader: `file`, 
     options: { 
      context: `./src`, 
      name: `[path][name].[ext]` 
     } 
     } 
    ] 

    }, 

    plugins: [ 
    extractCSS, 
    copy 
    ] 

}; 

if(process.env.NODE_ENV === `production`){ 

    //image optimizing 
    config.module.rules.push({ 
    test: /\.(svg|png|jpe?g|gif)$/, 
    loader: `image-webpack`, 
    enforce: `pre` 
    }); 

    config.plugins = [ 
    ...config.plugins, 
    new UglifyJsPlugin({ 
     sourceMap: true, // false returns errors.. -p + plugin conflict 
     comments: false 
    }) 
    ]; 

} 

config.plugins = [...config.plugins, ...configHtmls.plugins]; 

module.exports = config; 
+2

Sie geben 'Presets' in der 'Babel'-Sektion nicht mit' query' an, also haben Sie '.babelrc' mit' "Presets": ["es2015"] 'drin? –

+0

@clk Antwort veröffentlicht: 3 –

+0

Antwort akzeptiert: 3 – Kevin

Antwort

2

OP-Fehler ist von UglifyJs, wie in der angenommenen Antwort gelöst wird, können einige Leute auf dieser Seite den Fehler von Babel erhalten, in diesem Fall, beheben Sie es mit: fügen "presets": ["es2015"] entweder options.presets Abschnitt von babel-loader, oder zu .babelrc.

1

UglifyJs2 hat eine Harmony Zweig, der ES6 Syntax minimierte werden akzeptiert. In diesem Moment müssen Sie einen Fork von Webpack erstellen und Webpack auf diesen Fork zeigen.

Ich habe vor kurzem ein paar ähnliche Fragen beantwortet. Detaillierte Anweisungen finden Sie unter #38387544 oder #39064441.

Verwandte Themen