Skip to content

Instantly share code, notes, and snippets.

@jamesmfriedman
Last active April 25, 2017 20:59
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 jamesmfriedman/74cdc354560df65b7b8a19359f4ba8d8 to your computer and use it in GitHub Desktop.
Save jamesmfriedman/74cdc354560df65b7b8a19359f4ba8d8 to your computer and use it in GitHub Desktop.
medium/webpack-inline-styles/config
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = function(env) {
// merge together build and environment variables
// to be made available in process.env
const processEnv = Object.assign({}, env, require('./env.' + env.NODE_ENV));
// define our entries
const entries = {
'polyfills': ['./src/polyfills.ts'],
'app': ['./src/main.ts']
};
// add in the styles js file if we're doing dev
if (~process.env.BUILD_ENV.search('dev')) {
entries['styles'] = ['./src/styles.js'];
}
return {
entry: entries
output: {...},
module: {...},
devServer: {...}
plugins: [
// This will generate an index.html file for us and emit it into our
// output director
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'src/index.ejs' //point our template to a .ejs file
}),
// we need process.env available in our template
new webpack.DefinePlugin({
'process.env': JSON.stringify(processEnv)
}),
]
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment