Skip to content

Instantly share code, notes, and snippets.

@epaillous
Created June 28, 2017 14:22
Show Gist options
  • Save epaillous/1eb79204f0626dec75eaa69204119080 to your computer and use it in GitHub Desktop.
Save epaillous/1eb79204f0626dec75eaa69204119080 to your computer and use it in GitHub Desktop.
var webpack = require('webpack');
var webpackMerge = require('webpack-merge');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var commonConfig = require('./webpack.common.js');
var helpers = require('./helpers');
var AotPlugin = require('@ngtools/webpack').AotPlugin;
module.exports = function(env) {
return webpackMerge({
plugins: [
new AotPlugin({
tsConfigPath: 'tsconfig-aot.json',
entryModule: helpers.root('src/app/app.module#AppModule')
}),
]
}, commonConfig, {
devtool: 'source-map',
output: {
path: helpers.root('dist'),
publicPath: '/',
filename: '[name].[hash].js',
chunkFilename: '[id].[hash].chunk.js'
},
module: {
rules: [
{
test: /index\.html$/,
loader: 'string-replace-loader',
query: {
multiple: [
{
search: 'PIWIK_URL',
replace: credentials_file(env).PIWIK_URL,
flags: 'g'
},
{
search: 'PIWIK_SITE_ID',
replace: credentials_file(env).PIWIK_SITE_ID,
flags: 'g'
},
{
search: '{{GTM_ID}}',
replace: credentials_file(env).GTM_ID,
flags: 'g'
}
]
}
},
{
test: /\.ts$/,
use: ['@ngtools/webpack']
}
]
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new webpack.optimize.UglifyJsPlugin({ // https://github.com/angular/angular/issues/10618
compress: { warnings: false },
mangle: {
keep_fnames: true
}
}),
new webpack.LoaderOptionsPlugin({
htmlLoader: {
minimize: false // workaround for ng2
}
}),
new ExtractTextPlugin('[name].[hash].css'),
new webpack.EnvironmentPlugin(credentials_file(env))
]
});
};
function credentials_file(env) {
return credentials = require('./credentials/' + env + '.json');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment