2017-08-06 13 views
0

私はReactプロジェクトをプロダクション用にビルドしようとしています。私は私の生産コマンドを実行すると、私はUglifyJSPluginについてのエラーを得る:Unexpected token: keyword (const)。以下、package.json & webpack.config.jsファイルからすべてのコードを追加しました。この問題に関連するいくつかの質問がありますが、それらのどれも働いていません。どんな提案も素晴らしいだろう。Webpack - UglifyJSPluginに反応、予期しないトークン:キーワード(const)

package.json

{ 
    ... 
    "scripts": { 
     ... 
     "prod": "NODE_ENV=production webpack -p" 
    }, 
    "dependencies": { 
     "babel-plugin-add-module-exports": "^0.2.1", 
     "babel-plugin-react-html-attrs": "^2.0.0", 
     "babel-plugin-transform-class-properties": "^6.24.1", 
     "babel-plugin-transform-decorators-legacy": "^1.3.4", 
     "babel-preset-stage-0": "^6.24.1", 
     "babel-preset-stage-2": "^6.24.1", 
     ... 
     "webpack": "^3.4.1", 
     "webpack-dev-server": "^2.6.1" 
    }, 
    "devDependencies": { 
     "babel-core": "^6.25.0", 
     "babel-loader": "^7.1.1", 
     "babel-preset-es2015": "^6.24.1", 
     "babel-preset-react": "^6.24.1", 
     "uglify-js": "git://github.com/mishoo/UglifyJS2#harmony-v2.8.22", 
     "uglifyjs-webpack-plugin": "^0.4.6" 
    } 
} 

webpack.config.js

var path = require('path'); 
var webpack = require('webpack'); 

const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); 

var debug = process.env.NODE_ENV !== 'production'; 

module.exports = { 
    context: path.join(__dirname, "src"), 
    devtool: debug ? "inline-sourcemap" : false, 
    entry: './js/client.js', 
    module: { 
     loaders: [ 
      { 
       test: /\.js?$/, 
       exclude: /(node_modules|bower_components)/, 
       loader: 'babel-loader', 
       options: { 
        presets: ['stage-2', 'es2015', 'react'], 
        plugins: ['react-html-attrs', 'transform-class-properties', 'transform-decorators-legacy'] 
       } 
      }, 
      { 
       test: /\.css$/, 
       loader: ['style-loader/url', 'file-loader'] 
      } 
     ] 
    }, 
    output: { 
     path: __dirname + "/src/", 
     filename: 'client.min.js' 
    }, 
    plugins: debug ? [] : [ 
     new webpack.optimize.OccurrenceOrderPlugin(), 
     new UglifyJSPlugin({ 
      mangle: false, 
      sourceMap: false 
     }) 
    ], 
}; 

.babelrc

{ 
    "presets": [ 
     ["stage-2"], 
     ["es2015", {"modules": false}], 
     ["react"] 
    ] 
} 
+0

どのノードのバージョンを実行していますか? –

+0

@ManasJayanthノードv6.11.0 – AJDEV

答えて

0

を交換とvar UglifyJSPlugin = require('uglifyjs-webpack-plugin');

関連する問題