Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/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
Node.js 网页包产品vs开发_Node.js_Reactjs_Webpack - Fatal编程技术网

Node.js 网页包产品vs开发

Node.js 网页包产品vs开发,node.js,reactjs,webpack,Node.js,Reactjs,Webpack,在我的网页包配置中,我尝试对我的prod和dev环境进行单独的配置。我试图为每个任务创建不同的JS文件。这意味着,当我构建它时,我需要我的代码以一个特定的名称“lib.js”进入prod环境,当我运行我的Dev环境时,我希望编译的文件进入“dist”文件夹。 这是我的webpack.config.js文件: const webpack = require('webpack') const ExtractTextPlugin = require("extract-text-webpack-

在我的网页包配置中,我尝试对我的prod和dev环境进行单独的配置。我试图为每个任务创建不同的JS文件。这意味着,当我构建它时,我需要我的代码以一个特定的名称“lib.js”进入prod环境,当我运行我的Dev环境时,我希望编译的文件进入“dist”文件夹。 这是我的webpack.config.js文件:

    const webpack = require('webpack')
const ExtractTextPlugin = require("extract-text-webpack-plugin")
let path = require('path');
let config = {
    entry: [

        './src/index.js'
    ],
    module: {
        rules: [{
                test: /\.jsx?$/,
                exclude: /node_modules/,
                use: [
                    'react-hot-loader',
                    'babel-loader'
                ]
            },
            {
                test: /\.(css)$/,
                use: ExtractTextPlugin.extract({
                    fallback: 'style-loader',
                    use: 'css-loader'

                })
            },
            {
                test: /\.less$/,
                use:ExtractTextPlugin.extract({
                    use: 'less-loader'
                })

            },
            {
                test: /\.(eot|svg|ttf|woff|woff2)$/,
                loader: 'file-loader',
              },
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: ['babel-loader', 'eslint-loader']
            }
        ],

    },
    resolve: {
        extensions: ['*', '.js', '.jsx', '.css'],
    },
    plugins: [
        new webpack.DefinePlugin({
            'process.env': {
                'NODE_ENV': JSON.stringify(process.env.NODE_ENV)
            }
        })
    ],
    devServer: {
        contentBase: './dist',
        historyApiFallback: true
    },
    devtool : "cheap-module-source-map",


}
if (process.env.NODE_ENV === 'production') {
    config.output= {
        path: path.join(__dirname, '/build/'),
        filename: 'lib.js',
        library: ['MyLibrary'],
        libraryTarget: 'umd'
    };
    config.plugins.push(
        new webpack.optimize.UglifyJsPlugin({ sourceMap: true }),
        new ExtractTextPlugin({
            filename: 'bundle.css',
            disable: false,
            allChunks: true
        }),
        new webpack.optimize.AggressiveMergingPlugin({
            minSizeReduce: 1,
            moveToParents: true

        })
    )

} else {
    config.output= {
        path: path.join(__dirname, '/dist/'),
        filename: 'bundle.js',
        library: ['MyLibrary'],
        libraryTarget: 'umd',
        publicPath: '/dist/'

    };
    config.plugins.push(
        new webpack.optimize.UglifyJsPlugin({ sourceMap: true }),
        new ExtractTextPlugin({ disable: true })
    )
}

module.exports = config
以下是我的脚本:

  "scripts": {
"dev": "webpack-dev-server -d --env.platform=default --progress --hot",
"build": "set NODE_ENV=production && webpack -p --progress --hot"
  }
实际情况是,只有在构建时,文件才会转到dist文件夹,即使我已将NODE_ENV param设置为“production”。 我很高兴能得到帮助。
谢谢

它可能是您在
NODE_ENV=production
之后的尾随空格,这可能会将
NODE_ENV
设置为
production
,后面的空格在
网页包中不匹配。尝试在package.json中进行如下更改:

"build": "set NODE_ENV=production&& webpack -p --progress --hot"

@daw对SO-answer的评论中提到了这一点。

@Prakashsharma移除&实际上阻止了它的建造。顺便说一句,我使用SET是因为windows机器