Skip to content

Instantly share code, notes, and snippets.

@yamsellem
Last active March 8, 2018 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yamsellem/6c0a6550588b5b32add7bb5341585fb6 to your computer and use it in GitHub Desktop.
Save yamsellem/6c0a6550588b5b32add7bb5341585fb6 to your computer and use it in GitHub Desktop.
Environment variables
var webpack = require('webpack');
var path = require('path');
var LiveReloadPlugin = require('webpack-livereload-plugin');
var BUILD_DIR = path.resolve(__dirname, 'assets/built');
var APP_DIR = path.resolve(__dirname, 'assets/js');
let variables = {};
if (process.env.NODE_ENV === 'production') {
variables = { // could be a file
stripe: {
key: 'pk_live_...'
}
};
} else {
variables = {
stripe: { // could be a file
key: 'pk_test_...'
}
};
}
var config = {
entry: APP_DIR + '/app.jsx',
output: {
path: BUILD_DIR,
filename: '[name].js'
},
module: {
rules: [
{
test: /\.jsx?/,
include: APP_DIR,
loader: 'babel-loader'
}
]
},
plugins: [
new webpack.DefinePlugin({'process.env': JSON.stringify(variables)})
]
};
module.exports = config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment