我遇到了 2 个相关问题:
第一:当我跑步时npm run build
the bundle.js
文件没有缩小,但我确实得到了bundle.js.map
file.
第二:当我跑步时webpack -d
我只得到一个缩小版bundle.js
文件(并且没有错误)但是当我运行时webpack -p
然后我得到一个bundle.js
那是not缩小化,一个bundle.js.map
,以及那些错误:
ERROR in ./public/bundle.js from UglifyJs
Unexpected character '`' [./app/config.js:5,0][./public/bundle.js:76,14]
ERROR in ./public/bundle.js from UglifyJs
Unexpected character '`' [./app/config.js:5,0][./public/bundle.js:76,14]
我的问题:
- 不应该的行为
webpack -p
and webpack -d
成为
对面的?
- why is
bundle.js
当我跑步时没有缩小npm run build
?
- 为什么我会得到那些
Unexpected character
当我在模块中使用模板字符串时出现错误?
package.json
看起来像这样:
{
...,
"scripts": {
"build": "webpack --progress --watch"
},
"devDependencies": {
"babel-core": "^6.13.2",
"babel-loader": "^6.2.5",
"babel-preset-es2015-native-modules": "^6.9.4",
"eslint": "^3.3.1",
"eslint-config-airbnb": "^10.0.1",
"eslint-plugin-html": "^1.5.2",
"eslint-plugin-import": "^1.13.0",
"eslint-plugin-jsx-a11y": "^2.1.0",
"eslint-plugin-react": "^6.1.2",
"webpack": "^2.1.0-beta.21"
}
}
while webpack.config.js
是这样的:
const webpack = require('webpack'); // eslint-disable-line import/no-extraneous-dependencies
const nodeEnv = process.env.NODE_ENV || 'production';
module.exports = {
entry: {
filename: './app/app.js'
},
output: {
filename: './public/bundle.js'
},
modules: {
loaders: [
{
test: /\.js?$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['es2015-native-modules']
}
}
]
},
devtool: 'source-map',
plugins: [
// uglify
new webpack.optimize.UglifyJsPlugin({
compress: { warnings: false },
output: { comments: false },
sourceMap: true
}),
new webpack.DefinePlugin({
'process.env': { NODE_ENV: JSON.stringify(nodeEnv) }
})
]
};
我确实在这里和谷歌(和 webpack 文档......)进行了搜索,但我找不到任何对我有用的东西。谢谢!!