I have read all of the articles here at stack overflow and about 200 more from google searches and i, for the life of me, can't get my head around process.env. No matter what i do it's always an empty object.
const path = require("path");
const webpack = require('webpack');
module.exports = {
entry: {
search: './src/search/search_index.js',
// search: './src/search/search_index.js'
},
output: {
path: path.join(__dirname, "../website/public/javascript/react"),
publicPath: '/',
filename: "[name].bundle.js"
},
module: {
loaders: [{
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['react', 'es2015', 'stage-1']
}
}]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
devServer: {
historyApiFallback: true,
contentBase: './'
},
plugins: [
new webpack.DefinePlugin({
"process.env" : {
'NODE_ENV': '"production"'
}
})
]
};
"scripts": {
"start": "webpack-dev-server --inline --hot --content-base src/search",
"test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test",
"test:watch": "npm run test -- --watch"
}
console.log(process.env);
// from a render method in the running application started with "npm start"
Always returns {}
I am trying to get NODE_ENV set to production on my build and have had zero luck %NODE_ENV% show production but regardless i get the warning message in console about it running on a slower build to use NODE_ENV production.
To try and unwind what's happening i just wanted to see what my app was getting in process.env and it's an empty object. So then i tried hard coding it with defineplugin to again just test whats going on and it's the same result.
Been banging my head against this for about 3 hours now. Any help is appreciated.