Skip to content

Commit

Permalink
Fix webpack config for NODE_ENV use in code
Browse files Browse the repository at this point in the history
  • Loading branch information
David Le Jolly committed May 6, 2016
1 parent ccbb672 commit 157e3bc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
9 changes: 9 additions & 0 deletions internals/webpack/webpack.base.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ module.exports = (options) => ({
// make fetch available
fetch: 'exports?self.fetch!whatwg-fetch',
}),

// Always expose NODE_ENV to webpack, in order tocuse `process.env.NODE_ENV`
// inside your code for any environment checks; UglifyJS will automatically
// drop any unreachable code.
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
},
}),
]),
postcss: () => options.postcssPlugins,
resolve: {
Expand Down
8 changes: 0 additions & 8 deletions internals/webpack/webpack.prod.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,6 @@ module.exports = require('./webpack.base.babel')({
// Extract the CSS into a seperate file
new ExtractTextPlugin('[name].[contenthash].css'),

// Set the process.env to production so React includes the production
// version of itself
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
},
}),

// Put it in the end to capture all the HtmlWebpackPlugin's
// assets manipulations and do leak its manipulations to HtmlWebpackPlugin
new OfflinePlugin({
Expand Down
13 changes: 12 additions & 1 deletion internals/webpack/webpack.test.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

const path = require('path');

const webpack = require('webpack');
const modules = [
'app',
'node_modules',
Expand Down Expand Up @@ -49,6 +49,17 @@ module.exports = {
],
},

plugins: [

// Always expose NODE_ENV to webpack, in order tocuse `process.env.NODE_ENV`
// inside your code for any environment checks; UglifyJS will automatically
// drop any unreachable code.
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
},
})],

// Some node_modules pull in Node-specific dependencies.
// Since we're running in a browser we have to stub them out. See:
// https://webpack.github.io/docs/configuration.html#node
Expand Down

0 comments on commit 157e3bc

Please sign in to comment.