Last active
June 9, 2016 18:24
-
-
Save bennett000/b22311fef670b5a51de3dfe39d5bcae5 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
'use strict'; | |
const path = require('path'); | |
const webpack = require('webpack'); | |
const HtmlWebpackPlugin = require('html-webpack-plugin'); | |
const proxy = require('./server/webpack-dev-proxy'); | |
const StyleLintPlugin = require('stylelint-webpack-plugin'); | |
const loaders = require('./webpack/loaders'); | |
const basePlugins = [ | |
new webpack.DefinePlugin({ | |
__DEV__: process.env.NODE_ENV !== 'production', | |
__PRODUCTION__: process.env.NODE_ENV === 'production', | |
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV), | |
}), | |
new webpack.optimize.CommonsChunkPlugin('vendor', '[name].js'), | |
new HtmlWebpackPlugin({ | |
template: './src/index.html', | |
inject: false, | |
minify: false, | |
}), | |
new webpack.NoErrorsPlugin(), | |
]; | |
const devPlugins = [ | |
new StyleLintPlugin({ | |
configFile: './.stylelintrc', | |
files: 'src/**/*.css', | |
failOnError: false, | |
}), | |
]; | |
const prodPlugins = [ | |
new webpack.optimize.OccurenceOrderPlugin(), | |
new webpack.optimize.DedupePlugin(), | |
new webpack.optimize.UglifyJsPlugin({ | |
mangle: true, | |
compress: { | |
warnings: false, | |
}, | |
}), | |
]; | |
const plugins = basePlugins | |
.concat(process.env.NODE_ENV === 'production' ? prodPlugins : []) | |
.concat(process.env.NODE_ENV === 'development' ? devPlugins : []); | |
const postcssBasePlugins = [ | |
require('postcss-import')({ | |
addDependencyTo: webpack, | |
}), | |
require('postcss-cssnext')({ | |
browsers: ['ie >= 8', 'last 2 versions'], | |
}), | |
]; | |
const postcssDevPlugins = []; | |
const postcssProdPlugins = [ | |
require('cssnano')({ | |
safe: true, | |
sourcemap: true, | |
autoprefixer: false, | |
}), | |
]; | |
const postcssPlugins = postcssBasePlugins | |
.concat(process.env.NODE_ENV === 'production' ? postcssProdPlugins : []) | |
.concat(process.env.NODE_ENV === 'development' ? postcssDevPlugins : []); | |
module.exports = { | |
entry: { | |
app: './src/index.ts', | |
vendor: [ | |
'./shims/shims_for_IE', | |
'zone.js/dist/zone', | |
'reflect-metadata', | |
'core-js/es7/reflect', | |
'@angular/core', | |
'@angular/platform-browser-dynamic', | |
'@angular/http', | |
'@angular/router-deprecated', | |
'@angular/common/index', | |
'rxjs/Observable' | |
], | |
}, | |
output: { | |
path: path.resolve(__dirname, 'dist'), | |
filename: '[name].js', | |
publicPath: '/', | |
sourceMapFilename: '[name].js.map', | |
chunkFilename: '[id].chunk.js', | |
}, | |
devtool: process.env.NODE_ENV === 'production' ? | |
'source-map' : | |
'inline-source-map', | |
resolve: { | |
extensions: ['', '.webpack.js', '.web.js', '.ts', '.js'], | |
}, | |
plugins: plugins, | |
devServer: { | |
historyApiFallback: { index: '/' }, | |
proxy: Object.assign({}, proxy(), { '/api/*': 'http://localhost:3000' }), | |
}, | |
module: { | |
preLoaders: [ | |
loaders.tslint, | |
], | |
loaders: [ | |
loaders.ts, | |
loaders.html, | |
loaders.css, | |
loaders.svg, | |
loaders.eot, | |
loaders.woff, | |
loaders.woff2, | |
loaders.ttf, | |
loaders.png | |
], | |
noParse: [ /zone\.js\/dist\/.+/, /angular2\/bundles\/.+/ ], | |
}, | |
postcss: function postcssInit() { | |
return postcssPlugins; | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment