error in static/js/xxx.js from uglifyjs

4,268 阅读1分钟

解决上线webpack打包出现的这个问题 error in static/js/xxx.js from uglifyjs

公司管理后台上线,用的webpack打包,上线打包 node build.js 出现很严重的问题,如下:

===================================================================================

ERROR in static/js/app.d906119eedb53628d1bf.js from UglifyJs

Unexpected token: punc (() [static/js/app.d906119eedb53628d1bf.js:121,6]

Build failed with errors.

npm ERR!code ELIFECYCLE

npm ERR!errno 1

npm ERR! jx-plan@1.0.0 build: node build/build.js

npm ERR! Exit status 1

npm ERR!

npm ERR! Failed at the jx-plan@1.0.0 build script.

npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

解决方法很简单,加入babel-preset-es2015插件即可 我是由于本地的webpack打包没有问题,直接把代码更新线上代码,唯独没有更新的是带 '.'的这个【.babelrc】 文件。

最根本的原因需要以下三点:

1、安装依赖包

npm install --save babel-preset-es2015

2、配置webpack.base.conf.js

 loaders: [
             {
                test: /\.js$/,
                loader: 'babel',
                query:{
                    presets:['es2015']
                },
                include: projectRoot,
                exclude: /node_modules/
            }
 ]

3、在项目根目录添加【.babelrc】文件:

{
    presets: ['es2015']
 }

当以上三步都确认没有问题,重新node build.js打包,发现奇迹的事情发生了。完美解决~~

最后不得不说的是,感谢网友大神的分享:

https://segmentfault.com/a/1190000011212544