我目前正在尝试使用Webpack解决我们的生产版本的一些问题。尽管明确告诉uglifyjs不压缩或破坏,我的包被压缩和破坏。 Webpack / UglifyJS可能忽略我正在使用的选项对象的任何原因?
package.json脚本
NODE_ENV=production CONFIGS_PATH=$CONFIGS_PATH webpack -p --progress --config ./config/webpack/backend/production.babel.js
配置/的WebPack /后端/ production.babel.js :
const production = {
target: 'node',
devtool: 'cheap-module-source-map',
node: {
console: true,
fs: 'empty'
},
entry: {
server: `${rootPath}/src/server/server`,
},
output: {
path: `${rootPath}/_dist/`,
filename: '[name].js'
},
module: {
loaders: [
{
test: /react-icons\/(.)*(.js)$/,
loader: 'babel',
include: 'node_modules/react-icons'
},
{
test: /\.css$/,
loader: 'style-loader!css-loader'
},
{
test: /\.json$/,
loader: 'json'
},
{
test: /\.js$/,
loaders: ['babel', 'strip-loader?strip[]=debug,strip[]=console.log'],
exclude: /node_modules/
},
],
},
resolve: {
root: rootPath,
extensions: ['', '.js', '.json'],
alias: {
app: `${sourcePath}/app`,
actions: `${sourcePath}/app/actions`,
components: `${sourcePath}/app/routes/common`,
containers: `${sourcePath}/app/containers`,
middleware: `${sourcePath}/app/middleware`,
reducers: `${sourcePath}/app/reducers`,
routes: `${sourcePath}/app/routes`,
store: `${sourcePath}/app/store`,
utils: `${sourcePath}/app/utils`,
assets: `${sourcePath}/assets`,
server: `${sourcePath}/serve`
}
},
externals: [externals()],
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: false,
mangle: false
}),
new ExtendedDefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
APP_SETTINGS: settings,
API_SETTINGS: apiSettings
},
__DEVELOPMENT__: false,
__PRODUCTION__: true,
__DEVTOOLS__: false,
__TESTING__: false
}),
],
};
我还测试了从我的构建脚本中删除-p
,但最终仍然使用了缩小和损坏的捆绑包。