我知道您可以在反应中使用REACT_APP_NAMEOFYOURKEY或Dotenv,但是我想弄清楚为什么我不能使用它:
const config = require('config');
const webpack = require('webpack');
const GLOBALS = {
'process.env': {
NODE_ENV: JSON.stringify(config.get('NODE_ENV')),
RANDOM_ID: JSON.stringify(config.get('RANDOM_ID'))
}
};
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html'
}),
new MiniCssPlugin({
filename: '[name].css',
chunkFilename: '[id].css'
}),
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin(GLOBALS),
new Dotenv()
]
//my .env
NODE_ENV=production
RANDOM_ID = 0980
我遇到的错误:
throw new Error('Configuration property "' + property + '" is not defined');
^
Error: Configuration property "NODE_ENV" is not defined