Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 将React-dev模式更改为生产模式_Reactjs_Webpack_Webpack Production - Fatal编程技术网

Reactjs 将React-dev模式更改为生产模式

Reactjs 将React-dev模式更改为生产模式,reactjs,webpack,webpack-production,Reactjs,Webpack,Webpack Production,我找不到任何有用的东西来帮助我理解如何在React中将开发模式更改为生产模式。我是否需要安装其他软件包?缩小js和css文件的最佳插件是什么 这是我的webpack.config: module.exports = { entry: ["whatwg-fetch", "./js/app.jsx"], output: { filename: "./js/out.js" }, devServer: { inline: true, contentBase: './',

我找不到任何有用的东西来帮助我理解如何在React中将开发模式更改为生产模式。我是否需要安装其他软件包?缩小js和css文件的最佳插件是什么

这是我的webpack.config:

module.exports = {
entry: ["whatwg-fetch", "./js/app.jsx"],
output: {
    filename: "./js/out.js"
},
devServer: {
    inline: true,
    contentBase: './',
    port: 3001
},
watch: true,

module: {
    loaders: [{
        test: /\.jsx$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        query: {
            presets: ['es2015','stage-2', 'react']
        }
    }, {
        test: /\.scss$/,
        loader: ['style-loader', 'css-loader' , 'sass-loader',]
    },
        {
            test: /\.(jpe?g|png|gif|svg)$/i,
            exclude: /node_modules/,
            use: [
                {
                    loader: 'file-loader',
                    options: {
                        name: '[path][name].[ext]'
                    }
                }
            ]
        }
    ]
}
};

对于webpack v4,请使用
模式

module.exports = {
  mode: 'production',
  entry: ["whatwg-fetch", "./js/app.jsx"],
  output: {
    filename: "./js/out.js"
  },
这将把
process.env.NODE\u env
设置为
production

对于早期版本,使用
WebpackDefinePlugin
设置
NODE\u ENV

plugins: [
    new webpack.DefinePlugin({
        'process.env': {
            'NODE_ENV': JSON.stringify('production')
        }
    }),
]

Web包的哪个版本?版本-3.11.0在react中的开发模式和生产模式之间进行更改有什么作用?