Webpack UglifyJs意外令牌

时间:2018-04-15 08:51:52

标签: webpack uglifyjs

我在执行library(text2vec) lda_model <- LDA$new( n_topics = 10, doc_topic_prior = 0.1, topic_word_prior = 0.01 ) doc_topic_distr <- lda_model$fit_transform( x = m, n_iter = 1000, convergence_tol = 0.001, n_check_convergence = 25, progressbar = FALSE ) INFO [2018-04-15 10:40:00] iter 25 loglikelihood = -32949.882 INFO [2018-04-15 10:40:00] iter 50 loglikelihood = -32901.801 INFO [2018-04-15 10:40:00] iter 75 loglikelihood = -32922.208 INFO [2018-04-15 10:40:00] early stopping at 75 iteration 时遇到此错误 真正奇怪的是,当我运行npm run build时,编译成功完成。

npm run watch

这是我的package.json依赖项和脚本:

ERROR in rbz_bundle.js from UglifyJs
Unexpected token: punc (,) [xxx.js:102316,12]

由于一些不明原因,我无法解决此问题,我看到有人建议添加{ "scripts": { "build": "webpack -p --define process.env.NODE_ENV='\"production\"' --progress --colors --config ./webpack.prod.config.js", "watch": "webpack-dev-server -d --hot --inline --define process.env.NODE_ENV='\"development\"' --progress --colors --watch --config ./webpack.dev.config.js", "test": "react-scripts test" }, "dependencies": { "axios": "^0.17.1", "classnames": "^2.2.5", "firebase": "^4.10.0", "material-ui": "^1.0.0-beta.34", "material-ui-icons": "^1.0.0-beta.17", "npm": "^5.8.0", "prop-types": "^15.6.0", "react": "^16.2.0", "react-dom": "^16.2.0", "react-redux": "^5.0.7", "react-router-dom": "^4.2.2", "redux": "^3.7.2", "redux-thunk": "^2.2.0" }, "devDependencies": { "babel-core": "^6.26.0", "babel-eslint": "^8.2.2", "babel-loader": "^7.1.2", "babel-polyfill": "^6.26.0", "babel-preset-es2015": "^6.24.1", "babel-preset-es2017": "^6.24.1", "babel-preset-react": "^6.24.1", "babel-preset-stage-0": "^6.24.1", "compression-webpack-plugin": "^1.1.7", "css-loader": "^0.28.9", "eslint": "^4.18.0", "eslint-config-react-app": "^2.1.0", "eslint-loader": "^1.9.0", "eslint-plugin-jsx-a11y": "^6.0.3", "eslint-plugin-react": "^7.6.1", "extract-text-webpack-plugin": "^3.0.2", "html-replace-webpack-plugin": "^2.2.8", "node-sass": "^4.7.2", "react-hot-loader": "^3.1.3", "react-scripts": "^1.1.1", "sass-loader": "^6.0.6", "style-loader": "^0.19.1", "uglifyjs-webpack-plugin": "^1.2.0", "webpack": "^3.11.0", "webpack-dev-server": "^2.11.1", "webpack-watch-livereload-plugin": "0.0.1", "write-file-webpack-plugin": "^4.2.0" } } ,但它对我没有任何作用。

------编辑:Webpack.prod.js ------

"uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony"

1 个答案:

答案 0 :(得分:0)

似乎webpack不支持这种方式webpack.optimize.UglifyJsPlugin

您可以尝试以这种方式使用:

const WebpackUglifyJsPlugin = require('webpack-uglify-js-plugin');

放入顶部以声明插件

module.exports.plugins.push(

        new WebpackUglifyJsPlugin({
            cacheFolder: path.resolve(__dirname, 'target'),
            debug: true,
            minimize: true,
            sourceMap: false,
            output: {
                comments: false
            },
            compressor: {
                warnings: false
            }
        })
    );

请参阅uglifyjs-webpack-plugin

中的文件