Skip to content

Instantly share code, notes, and snippets.

@diem1
Created June 22, 2016 09:31
Show Gist options
  • Save diem1/c752080db8ea2a1b59cc3822fbce9de1 to your computer and use it in GitHub Desktop.
Save diem1/c752080db8ea2a1b59cc3822fbce9de1 to your computer and use it in GitHub Desktop.
Webpack config to support environment variables in JS app
var domain = process.env.DOMAIN || null;
console.log(domain);
var ExtractTextPlugin = require("extract-text-webpack-plugin"),
webpack = require('webpack');
module.exports = {
node: {
fs: "empty"
},
entry: './index',
output: {
path: __dirname,
filename: 'bundle.js'
},
module: {
loaders: [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader')
},
{
test: /.js?$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['es2015', 'react']
}
}
]
},
plugins: [
new ExtractTextPlugin('bundle.css'),
new webpack.DefinePlugin({
'process.env': {
'DOMAIN': JSON.stringify(process.env.DOMAIN)
}
})
],
devServer: {
port: 8080,
historyApiFallback: true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment