Created
September 23, 2016 06:34
-
-
Save gucheen/40a62bf937710e47ee69ef41e6f37d07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var webpack = require('webpack'); | |
var path = require('path'); | |
var HtmlWebpackPlugin = require('html-webpack-plugin'); | |
var ExtractTextPlugin = require("extract-text-webpack-plugin"); | |
// Webpack Config | |
var webpackConfig = { | |
entry: { | |
'polyfills': './src/polyfills.browser.ts', | |
'vendor': './src/vendor.browser.ts', | |
'main': './src/main.browser.ts', | |
}, | |
output: { | |
path: './dist', | |
}, | |
plugins: [ | |
new webpack.optimize.OccurenceOrderPlugin(true), | |
new webpack.optimize.CommonsChunkPlugin({ name: ['main', 'vendor', 'polyfills'], minChunks: Infinity }), | |
new HtmlWebpackPlugin({ | |
template: 'src/index.html' | |
}), | |
], | |
module: { | |
loaders: [ | |
// .ts files for TypeScript | |
{ test: /\.ts$/, loaders: ['awesome-typescript-loader', 'angular2-template-loader'] }, | |
{ | |
test: /\.css$/, | |
loaders: ['to-string-loader', 'css-loader'], | |
exclude: [ | |
/material-design-icons/, | |
/ng2-toasty/, | |
/@angular2-material\/core\/overlay\/overlay.css/, | |
/src\/app\/shared\/styles/, | |
] | |
}, | |
{ | |
test: /\.css$/, | |
loaders: ['style-loader', 'css-loader'], | |
include: [ | |
/material-design-icons/, | |
/ng2-toasty/, | |
/@angular2-material\/core\/overlay\/overlay.css/, | |
/src\/app\/shared\/styles/, | |
] | |
}, | |
{ test: /\.html$/, loader: 'raw-loader' }, | |
{ test: /\.(woff(2)?|svg|ttf|eot)$/, loader: 'url-loader?limit=10000&name=fonts/[name].[ext]' }, | |
], | |
noParse: [/moment-with-locales/] | |
} | |
}; | |
if (process.env.NODE_ENV === 'production') { | |
webpackConfig.output = { | |
path: './dist', | |
filename: '[name].[hash].js', | |
sourceMapFilename: '[name].map', | |
chunkFilename: '[id].[hash].js' | |
}; | |
webpackConfig.module.loaders.forEach(function (loader) { | |
if (loader.test.test('.css') && loader.include) { | |
loader.loader = ExtractTextPlugin.extract( | |
loader.loaders.filter(function (loaderName) { | |
return loaderName !== 'style-loader'; | |
}) | |
); | |
loader.loaders = undefined; | |
} | |
}); | |
webpackConfig.plugins.push(new webpack.optimize.UglifyJsPlugin({ | |
beautify: false, | |
mangle: { screw_ie8 : true, keep_fnames: true }, | |
compress: { screw_ie8: true }, | |
comments: false | |
})); | |
webpackConfig.plugins.push(new ExtractTextPlugin('[name].[contenthash].css')); | |
webpackConfig.plugins.push(new webpack.DefinePlugin({ | |
'process.env': JSON.stringify('production') | |
})); | |
} | |
// Our Webpack Defaults | |
var defaultConfig = { | |
devtool: 'cheap-module-source-map', | |
cache: true, | |
debug: true, | |
output: { | |
filename: '[name].bundle.js', | |
sourceMapFilename: '[name].map', | |
chunkFilename: '[id].chunk.js' | |
}, | |
resolve: { | |
root: [path.join(__dirname, 'src')], | |
extensions: ['', '.ts', '.js'], | |
alias: { | |
moment: 'moment/min/moment-with-locales.min.js' | |
} | |
}, | |
devServer: { | |
historyApiFallback: true, | |
watchOptions: { aggregateTimeout: 300, poll: 1000 }, | |
proxy: { | |
'/kapacitor/*': { | |
target: 'http://127.0.0.1:9092' | |
} | |
} | |
}, | |
node: { | |
global: 1, | |
crypto: 'empty', | |
module: 0, | |
Buffer: 0, | |
clearImmediate: 0, | |
setImmediate: 0 | |
} | |
}; | |
var webpackMerge = require('webpack-merge'); | |
module.exports = webpackMerge(defaultConfig, webpackConfig); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment