-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack.config.js
156 lines (145 loc) · 3.56 KB
/
webpack.config.js
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin');
const os = require('os');
const SERVER = {
host: 'localhost',
port: '3000'
};
module.exports = {
cache: true,
devtool: 'cheap-module-eval-source-map',
entry: {
app: './sample/main.ts',
vendor: './sample/vendor.ts',
polyfills: './sample/polyfills.ts'
},
output: {
path: path.resolve(__dirname, 'dist'),
publicPath: `http://${SERVER.host}:${SERVER.port}/`,
filename: '[name].js',
chunkFilename: '[id].chunk.js'
},
resolve: {
extensions: ['.ts', '.js', '.json']
},
module: {
rules: [
{
enforce: 'pre',
test: /\.ts$/,
use: [
{
loader: 'tslint-loader',
options: {
tsConfigFile: path.resolve(__dirname, 'tsconfig.json')
}
}
]
},
{
test: /\.ts$/,
loaders: [
{
loader: 'awesome-typescript-loader',
options: {
configFileName: path.resolve(__dirname, 'tsconfig.json')
}
},
'angular2-template-loader'
]
},
{
test: /\.html$/,
loader: 'html-loader',
include: [path.resolve(__dirname, 'src'), path.resolve(__dirname, 'sample')]
},
{
test: /\.(ttf|eot|woff|woff2|svg)([\w\?=\.]*)?$/,
use: 'file-loader',
include: [path.resolve(__dirname, 'node_modules/bootstrap/dist/fonts')]
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
sourceMap: true
}
},
{
loader: 'postcss-loader',
options: {
plugins: () => {
return [require('precss'), require('autoprefixer')];
},
sourceMap: true
}
}
]
})
}
]
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jquery': 'jquery'
}),
// 用于去掉浏览器console的warning
new webpack.ContextReplacementPlugin(/angular(\\|\/)core(\\|\/)@angular/, './sample', {}),
new webpack.optimize.CommonsChunkPlugin({
name: ['vendor']
// minChunks: 2
}),
new HtmlWebpackPlugin({
template: 'sample/index.html',
chunksSortMode: 'dependency'
}),
new webpack.LoaderOptionsPlugin({
htmlLoader: {
minimize: true // workaround for ng2
},
debug: true,
options: {
context: __dirname
}
}),
new ParallelUglifyPlugin({
workerCount: os.cpus().length,
cacheDir: '.cache/',
sourceMap: true,
uglifyJS: {
compress: {
warnings: true,
drop_debugger: false,
drop_console: false
},
// comments: DEVELOPMENT,
mangle: {
// Skip mangling these
reserved: ['$super', '$', 'exports', 'require'],
keep_fnames: true
}
}
}),
new ExtractTextPlugin('[name].css')
],
devServer: {
historyApiFallback: true,
stats: 'minimal',
compress: true,
watchOptions: {
aggregateTimeout: 300,
poll: 1000
},
host: SERVER.host,
port: SERVER.port
}
};