似乎是一个真正愚蠢的问题,必须在某个地方得到答案,但我已经搜索了几个小时无济于事。我是ReactJS的新手并且使用Webpack构建,一般来说构建配置。我使用Webpack链接和捆绑整个项目,包括ReactJS。它工作得很好,但是我无法弄清楚是否有任何方法可以使捆绑软件无法解决,以便在出现问题时对其进行调试。
这是我的Webpack配置:
var webpack = require('webpack');
var path = require('path');
var BUILD_DIR = path.resolve(__dirname, 'public/js');
var APP_DIR = path.resolve(__dirname, 'build-source/js');
var config = {
entry: APP_DIR + '\\main.js',
output: {
path: BUILD_DIR,
filename: 'build.js' // want this output file to end un-minified
},
module: {
loaders: [
{
test: /\.jsx?/,
include: APP_DIR,
loader: 'babel'
}
]
}
};
module.exports = config;
我使用npm run dev
或npm run build
运行捆绑执行,从我的package.json中调用以下内容:
{
/* blah blah */,
"scripts": {
"start": "node ./bin/www",
"dev": "webpack -d --watch",
"build": "webpack -p"
},
"dependencies": {
"babel-core": "^6.16.0",
"babel-loader": "^6.2.5",
"babel-preset-react": "^6.16.0",
"body-parser": "~1.15.1",
"cookie-parser": "~1.4.3",
"debug": "~2.2.0",
"express": "~4.13.4",
"helmet": "^3.1.0",
"morgan": "~1.7.0",
"mysql": "^2.11.1",
"querystring": "^0.2.0",
"react": "^15.3.2",
"react-dom": "^15.3.2",
"request": "^2.75.0",
"serve-favicon": "~2.3.0",
"webpack": "^1.13.2"
}
}
我需要更改什么才能从我的Webpack执行中获取未缩小的 JavaScript包?
答案 0 :(得分:2)
当您对webpack' s cli使用-p标志时,您告诉webpack使用UglifyJSPlugin
(behind the scenes)
相反,我会有一个单独的构建任务,它运行webpack而不使用-p标志,而是在您的配置中传递以下内容。
var webpack = require('webpack');
module.exports = {
plugins: [
new webpack.optimize.UglifyJsPlugin({
options: {
compress: {drop_debugger: false}
}
})
]
};
此外,您可以看到我已将自定义选项传递给UglifyJsPlugin(它与UglifyJs' s compression options对应)。
答案 1 :(得分:0)
你应该添加到你的 webpack.build.js 文件中
开发工具:'inline-source-map',