我在应用程序上使用Reactjs,是时候构建它用于生产了。 如下所示,我的package.json有pack:prod命令,该命令使用webpack和特定的webpack.config.js文件在“生产”环境中构建应用程序。 它只是工作,但“反应开发工具”chrome插件一直在说我正在使用缩小的开发版本而不是生产版本。
有没有人知道我还能做些什么来让它在我的环境中工作? 我从另一个项目获得了相同的命令和webpack文件,这些文件在prod版本中没有显示此错误。
我的webpack配置文件和package.json如下:
webpack.config.js
module.exports = {
entry: ['./src/App.js.jsx'],
output: {
path: '../static',
filename: 'index.bundled.js',
publicPath: '/static/'
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.scss$/,
loaders: ["style-loader", "css-loader", "sass-loader"]
}
]
},
devServer: {
headers: { "Access-Control-Allow-Origin": "*" },
proxy: {
'/': {
target: 'http://localhost:8080',
changeOrigin: true
}
}
},
plugins: []
}
webpack.prod.config.js
let config = require('./webpack.config.js');
let webpack = require('webpack');
config.plugins = [
new webpack.DefinePlugin({
"process.env": {
"NODE_ENV": JSON.stringify('production')
}
}),
new webpack.optimize.UglifyJsPlugin()
]
module.exports = config;
package.json
- “scripts”e“dependencies”部分
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"pack": "webpack --progress",
"pack:prod": "webpack -p --progress --cofig webpack.prod.config.js",
"dev-server": "webpack-dev-server --content-base static/ --port 9999 --hot --inline"
},
"author": "",
"license": "ISC",
"devDependencies": {
"axios": "^0.15.3",
"babel-core": "^6.22.1",
"babel-loader": "^6.2.10",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.22.0",
"classnames": "^2.2.5",
"css-loader": "^0.26.1",
"js-cookie": "^2.1.3",
"material-ui": "^0.17.1",
"moment": "^2.18.1",
"node-sass": "^4.3.0",
"qs": "^6.3.1",
"react": "^15.3.2",
"react-dom": "^15.4.2",
"react-maskedinput": "^3.3.4",
"react-router": "^3.0.2",
"react-tap-event-plugin": "^2.0.1",
"react-text-mask": "^3.0.0",
"sass-loader": "^4.1.1",
"style-loader": "^0.13.1",
"webpack": "^1.14.0",
"webpack-dev-server": "^1.16.2"
}
我在浏览器控制台上看到的消息是
index.bundled.js:2 Warning: It looks like you're using a minified copy of the development build of React. When deploying React apps to production, make sure to use the production build which skips development warnings and is faster. See https: // fb.me/react-minification for more details.
答案 0 :(得分:0)
错误在于您正在运行的命令中。即
"pack:prod": "webpack -p --progress --cofig webpack.prod.config.js"
应为--config
。