forked from rangle/angular2-starter
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
121 lines (105 loc) · 2.68 KB
/
webpack.config.js
File metadata and controls
121 lines (105 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
'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 SplitByPathPlugin = require('webpack-split-by-path');
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 SplitByPathPlugin([
{ name: 'vendor', path: [__dirname + '/node_modules/'] },
]),
new HtmlWebpackPlugin({
template: './src/index.html',
inject: 'body',
minify: false,
}),
];
const devPlugins = [
new webpack.NoErrorsPlugin(),
new StyleLintPlugin({
configFile: './.stylelintrc',
files: ['src/**/*.css'],
failOnError: false,
}),
];
const prodPlugins = [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
mangle: {
keep_fnames: 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',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].[hash].js',
publicPath: '/',
sourceMapFilename: '[name].[hash].js.map',
chunkFilename: '[id].chunk.js',
},
devtool: 'source-map',
resolve: {
extensions: ['', '.webpack.js', '.web.js', '.ts', '.js'],
},
plugins: plugins,
devServer: {
historyApiFallback: { index: '/' },
proxy: proxy(),
},
module: {
preLoaders: [
loaders.tslint,
],
loaders: [
loaders.ts,
loaders.html,
loaders.css,
loaders.svg,
loaders.eot,
loaders.woff,
loaders.woff2,
loaders.ttf,
],
noParse: [ /zone\.js\/dist\/.+/, /angular2\/bundles\/.+/ ],
},
postcss: () => {
return postcssPlugins;
},
};