gpt4 book ai didi

javascript - webpack -p 无法丑化 es2015 代码

转载 作者:数据小太阳 更新时间:2023-10-29 05:35:17 29 4
gpt4 key购买 nike

webpack -p cli 命令无法对 es2015 代码进行 uglify

包.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

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模板字符串使用)

运行 webpack -d 工作正常。

最佳答案

github 上的一位用户 (fulls1z3) 提出了一个 solution不需要 babel(参见 2016 年 11 月 26 日的帖子):

这是一个副本:

webpack#2 users, I'm hereby trying to help by providing detailed instructions to use the Harmony branch of UglifyJs2 with webpack:

  • 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.

  • Commit changes,

  • Finally, point webpack in your package.json to your custom fork: "webpack": "[USERNAME]/webpack#master"

OR,

  • Point webpack in your package.json to fulls1z3/webpack (ES6/ES2015 friendly webpack fork): "webpack": "fulls1z3/webpack#v2.1.0-beta.27-harmony"

我在全局范围内使用 webpack,所以我也必须运行它:

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 文件夹替换为来自 https://github.com/fulls1z3/webpack/releaseswebpack-2.1.0-beta.27-harmony.zip

最后,我将全局 uglify-js npm 文件夹替换为来自 https://github.com/mishoo/UglifyJS2/tree/harmonyUglifyJS2-harmony.zip

关于javascript - webpack -p 无法丑化 es2015 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38883700/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com