나는 다음 Webpack.config.js 있습니다Webpack.config.js process.env.NODE_ENV가 작동하지 않습니다. - 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;
및 다음 스크립트 : 항상 ELSE에서에 결코 IF (나는 npm run production
을 실행할 때)에서에
"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"
},
하지만를 (실행 내가 실행하는 스크립트). 왜 그럴 수 있죠? (위에서 NODE_ENV = 'production'이라고 선언했는데 왜 작동하지 않는지 이해할 수 없습니다 ...).
감사합니다.
어떤 OS 경우
및 웹팩 설정 파일에
이및 삼항 조건
을 사용하거나 사용이 시도 할 수 있습니다 일하는거야? –
Windows 10. 버전 "webpack": "^ 1.13.2", "webpack-dev-server": "^ 1.15.2"' – JuMoGar
"생산"을 시도하십시오 : "SET NODE_ENV = production & webpack --progress -p "' –