繁体   English   中英

reactjs的生产Webpack版本-看起来您正在使用React开发版本的缩小版本

[英]Production webpack build of reactjs - It looks like you're using a minified copy of the development build of React

我在应用程序上使用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": {
    "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.

错误在于您正在运行的命令。

"pack:prod": "webpack -p --progress --cofig webpack.prod.config.js"

它应该是--config

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM