forked from 1337programming/angular2.0-Wepack-App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
222 lines (190 loc) · 4.93 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
// @AngularClass
// Helper
var sliceArgs = Function.prototype.call.bind(Array.prototype.slice);
var NODE_ENV = process.env.NODE_ENV || 'development';
// Node
var webpack = require('webpack');
var path = require('path');
var pkg = require('./package.json');
// Webpack Plugins
var OccurenceOrderPlugin = webpack.optimize.OccurenceOrderPlugin;
var CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;
var UglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
var DedupePlugin = webpack.optimize.DedupePlugin;
var DefinePlugin = webpack.DefinePlugin;
var BannerPlugin = webpack.BannerPlugin;
/*
* Config
*/
var config = {
devtool: 'source-map',
// devtool: 'eval',
watch: true,
debug: true,
cache: true,
// our Development Server configs
/*devServer: {
inline: true,
colors: true,
historyApiFallback: true,
contentBase: 'src/public',
publicPath: '/__build__',
hot: true
},*/
//
entry: {
'angular2': [
// Angular 2 Deps
'zone.js',
'reflect-metadata',
'rtts_assert/rtts_assert',
'angular2/angular2'
],
'app': [
// App
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/dev-server',
'./src/app/bootstrap'
]
},
// Config for our build files
output: {
path: root('__build__'),
filename: 'app.js',
// filename: '[name].[hash].js',
sourceMapFilename: 'app.js.map',
chunkFilename: '[id].chunk.js',
publicPath: '/__build__/'
},
resolve: {
root: __dirname,
extensions: ['', '.ts', '.js', '.json'],
alias: {
// we can switch between development and production
// 'angular2': 'node_modules/angular2/ts',
// 'angular2': 'angular2/ts/dev',
'app': 'src/app',
'common': 'src/common',
// 'components': 'src/app/components'
// 'services': '/app/services/*.js',
// 'stores/*': '/app/stores/*.js'
// 'angular2': 'angular2/es6/dev'
}
},
/*
* When using `templateUrl` and `styleUrls` please use `__filename`
* rather than `module.id` for `moduleId` in `@View`
*/
node: {
__filename: true
},
module: {
loaders: [
// Support for *.json files.
{
test: /\.json$/,
loader: 'json'
},
// Support for CSS as raw text
{
test: /\.css$/,
loader: 'raw'
},
// support for .html as raw text
{
test: /\.html$/,
loader: 'raw'
},
// Support for .ts files.
{
test: /\.ts$/,
loader: 'typescript-simple?ignoreWarnings[]=2345',
exclude: [
/\.spec\.ts$/,
/\.e2e\.ts$/,
/web_modules/,
/node_modules/
]
}
],
noParse: [
/rtts_assert\/src\/rtts_assert/
]
},
context: __dirname,
stats: {
colors: true,
reasons: true
}
};
var commons_chunks_plugins = [
{
name: 'angular2',
minChunks: Infinity,
filename: 'angular2.js'
},
{
name: 'common',
filename: 'common.js'
}
]
//
var environment_plugins = {
all: [
new DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(NODE_ENV),
'VERSION': pkg.version
}),
new OccurenceOrderPlugin(),
new DedupePlugin(),
],
production: [
new UglifyJsPlugin({
compress: {
warnings: false,
drop_debugger: false
},
output: {
comments: false
},
beautify: false
}),
new BannerPlugin(getBanner(), {
entryOnly: true
})
],
development: [
/* Dev Plugin */
new webpack.HotModuleReplacementPlugin(),
]
} //env
if (NODE_ENV === 'production') {
// replace filename `.js` with `.min.js`
config.output.filename = config.output.filename.replace('.js', '.min.js');
config.output.sourceMapFilename = config.output.sourceMapFilename.replace('.js', '.min.js');
commons_chunks_plugins = commons_chunks_plugins.map(function (chunk) {
return chunk.filename.replace('.js', '.min.js');
});
} else if (NODE_ENV === 'development') {
// any development actions here
}
// create CommonsChunkPlugin instance for each config
var combine_common_chunks = commons_chunks_plugins.map(function (config) {
return new CommonsChunkPlugin(config);
});
console.log('NODE_ENV', NODE_ENV);
// conbine everything
config.plugins = [].concat(combine_common_chunks, environment_plugins.all, environment_plugins[NODE_ENV]);
module.exports = config;
// Helper functions
function getBanner() {
return 'Angular2.0 App v' + pkg.version;
}
function root(args) {
args = sliceArgs(arguments, 0);
return path.join.apply(path, [__dirname].concat(args));
}
function rootNode(args) {
args = sliceArgs(arguments, 0);
return root.apply(path, ['node_modules'].concat(args));
}