我旁邊Webpack.config.js:Webpack.config.js process.env.NODE_ENV not workinkg。 - ReactJS -
'use strict';
const WEBPACK = require('webpack');
const PATH = require('path');
const CopyFiles = require('copy-webpack-plugin');
const BaseName = "/upct";
const CONFIG = {
resolve: {
extensions: ['', '.js', '.jsx']
},
context: __dirname,
entry: {
app: ['./src/index.jsx']
},
/*
output: {
path: PATH.join(__dirname, '/public'),
/*path: './public',*//*
publicPath: BaseName+'/',
filename: 'index.js'
},
/*
devServer: {
host: 'localhost',
port: 3000,
contentBase: PATH.join(__dirname, '/public'),
inline: true,
historyApiFallback: true,
headers: {
"Access-Control-Allow-Origin": "*"
}
},
*/
module: {
loaders: [
{
test: /(\.js|.jsx)$/,
loader: 'babel',
query: {
"presets": [
"es2015",
"react",
"stage-0"
],
"plugins": [
"react-html-attrs",
"transform-decorators-legacy",
"transform-class-properties"
]
}
}
]
},
plugins: [
new WEBPACK.DefinePlugin({
BASENAME: JSON.stringify(BaseName),
'process.env': {
/*'NODE_ENV': JSON.stringify(process.env.NODE_ENV)*/
'NODE_ENV': JSON.stringify('production')
}
})
]
}
if (process.env.NODE_ENV === 'production') {
CONFIG.output = {
path: PATH.join(__dirname, '/publicProduction'),
publicPath: BaseName+'/',
filename: 'index.js'
};
CONFIG.plugins.push(
new WEBPACK.optimize.UglifyJsPlugin({
beautify: false,
mangle: {
screw_ie8: true,
keep_fnames: true
},
compress: {
screw_ie8: true,
warnings: false
},
comments: false
})
);
//babelSettings.plugins.push("transform-react-inline-elements");
//babelSettings.plugins.push("transform-react-constant-elements");
} else {
//CONFIG.devtool = "#cheap-module-source-map"
CONFIG.output = {
path: PATH.join(__dirname, '/publicDeveloping'),
publicPath: BaseName+'/',
filename: 'index.js'
};
CONFIG.devServer = {
host: 'localhost',
port: 3000,
contentBase: PATH.join(__dirname, '/src'),
inline: true,
historyApiFallback: true,
headers: {
"Access-Control-Allow-Origin": "*"
}
}
/*
CONFIG.plugins.push(
new webpack.HotModuleReplacementPlugin()
);*/
}
module.exports = CONFIG;
和明年腳本:
"scripts": {
"build": "SET NODE_ENV='building' && webpack --progress --watch --colors",
"serve": "SET NODE_ENV='testing' && webpack-dev-server --progress --colors",
"production": "SET NODE_ENV='production' && webpack --progress -p"
},
但從來沒有到IF(當我運行npm run production
),一直到ELSE(運行我運行的腳本)。爲什麼會這樣? (上面我宣佈NODE_ENV ='生產',我不明白爲什麼它不工作...)。
謝謝。
哪個操作系統是你的在工作? –
的Windows 10.版本:' 「的WebPack」: 「^ 1.13.2」,'和' 「的WebPack-dev的服務器」: 「^ 1.15.2」' – JuMoGar
嘗試' 「生產」:「SET NODE_ENV =生產& webpack --progress -p「' –