【问题标题】:Webpack throws warning when running npm run buildWebpack 在运行 npm run build 时抛出警告
【发布时间】:2016-10-09 20:28:07
【问题描述】:

我有以下:

var webpack = require('webpack');
var path = require('path');

var BUILD_DIR = path.resolve(__dirname, 'src/client/public');
var APP_DIR = path.resolve(__dirname, 'src/client/app');

var config = {
  entry: APP_DIR + '/index.jsx',
  output: {
    path: BUILD_DIR,
    filename: 'bundle.js'
  },
  module : {
    loaders : [
      {
        test : /\.jsx?/,
        include : APP_DIR,
        loader : 'babel'
      }
    ]
  }
};

module.exports = config;

当我运行“npm run build”时:

{
  "name": "whitbread",
  "version": "1.0.0",
  "description": "technical test",
  "main": "index.js",
  "scripts": {
    "dev": "webpack -d --watch",
    "build": "webpack -p"
  },
  "author": "Alessandro Santese",
  "license": "ISC",
  "dependencies": {
    "babel-core": "^6.17.0",
    "babel-loader": "^6.2.5",
    "babel-preset-es2015": "^6.16.0",
    "babel-preset-react": "^6.16.0",
    "react": "^15.3.2",
    "react-dom": "^15.3.2",
    "webpack": "^1.13.2"
  }
}

我收到此警告消息:

警告:您似乎正在使用 React 开发版本的缩小副本。将 React 应用程序部署到生产环境时,请确保使用可跳过开发警告且速度更快的生产构建版本。

我怎样才能摆脱它?

【问题讨论】:

    标签: reactjs webpack


    【解决方案1】:

    您需要为生产环境准备 react,因此请尝试将以下几行添加到您的 webpack 配置中。

    new webpack.DefinePlugin({
      "process.env": { 
        NODE_ENV: JSON.stringify("production") 
      }
    })
    

    【讨论】:

      猜你喜欢
      • 2021-03-03
      • 2022-06-16
      • 1970-01-01
      • 1970-01-01
      • 2020-03-21
      • 2017-01-18
      • 2020-09-14
      • 1970-01-01
      • 2021-09-15
      相关资源
      最近更新 更多