Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.