webpack -p无法uglify es2015代码 [英] webpack -p fails to uglify es2015 code
问题描述
webpack -p cli命令无法uglify es2015代码
The webpack -p cli command fails to uglify es2015 code
package.json
package.json
"devDependencies": {
"babel": "^6.5.2",
"babel-core": "^6.13.2",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.13.2"
}
webpack.config.js
webpack.config.js
var webpack = require("webpack");
var config = {
entry: './src/app.js',
devtool: "source-map",
output: {
path: '../Scripts',
filename: 'bundle.js'
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel-loader',
query: {
presets: ['es2015']
},
include: ["./src"],
exclude: /node_modules/
}
]
}
}
module.exports = config;
运行 webpack -p
时出错
ERROR in bundle.js from UglifyJs
Unexpected character '`' [./src/LineEndRenderer.js:33,0]
(使用es2015模板字符串)
(es2015 template string use)
运行 webpack -d
工作正常。
推荐答案
用户(fulls1z3) )在github提出了一个不需要babel的解决方案(参见11 / 26/2016):
A user (fulls1z3) at github came up with a solution that does not require babel (see post from 11/26/2016):
这是一份副本:
webpack# 2位用户,我特此试图提供详细说明,使用UglifyJs2的Harmony分支和webpack:
webpack#2 users, I'm hereby trying to help by providing detailed instructions to use the Harmony branch of UglifyJs2 with webpack:
- Fork webpack,
- 在该分支上,删除除master之外的所有分支,
- 将主分支克隆到本地文件夹,
- 在本地文件夹中,删除所有fil es,
- 提交空本地文件夹,
- 下载最新版本(例如:v2.1.0-beta.27)
- 将zip文件的内容解压缩到本地文件夹,
-
在本地文件夹中,编辑forked package.json,更改
uglify-js:git + https://github.com/mishoo/UglifyJS2.git#harmony
指向UglifyJs2(和谐分支)依赖关系该分支。
- Fork webpack,
- On that fork, delete all branches except master,
- Clone master branch to a local folder,
- On the local folder, delete all files,
- Commit the empty local folder,
- Download the latest release (ex: v2.1.0-beta.27 at the moment)
- Extract contents of zip file to the local folder,
On the local folder, edit forked package.json, change
"uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony"
to point UglifyJs2 (harmony branch) dependency to that branch.
提交更改,
OR,
- 将package.json中的webpack指向 fulls1z3 / webpack (ES6 / ES2015友好的webpack fork):
webpack:fulls1z3 / webpack#v2.1.0 -beta.27-harmony
- Point webpack in your package.json to fulls1z3/webpack (ES6/ES2015 friendly webpack fork):
"webpack": "fulls1z3/webpack#v2.1.0-beta.27-harmony"
我使用的是webpack globa lly,所以我也必须运行它:
I was using webpack globally, so I had to run this too:
npm install yargs support-color enhanced-resolve explain tapable webpack-sources source-map uglify -js object-assign async loader-runner acorn watchpack mkdirp ajv ajv-keywords node-libs-browser -g
npm install yargs supports-color enhanced-resolve interpret tapable webpack-sources source-map uglify-js object-assign async loader-runner acorn watchpack mkdirp ajv ajv-keywords node-libs-browser -g
然后我更换了我的全局 webpack
npm文件夹, webpack-2.1.0-beta.27-harmony.zip
来自 https://github.com/fulls1z3/webpack/releases
Then I replaced my global webpack
npm folder with webpack-2.1.0-beta.27-harmony.zip
from https://github.com/fulls1z3/webpack/releases
Lastly, I replaced my global uglify-js
npm folder with UglifyJS2-harmony.zip
from https://github.com/mishoo/UglifyJS2/tree/harmony
这篇关于webpack -p无法uglify es2015代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!