This repository has been archived by the owner on Mar 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
304 lines (267 loc) · 7.44 KB
/
webpack.common.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
var path = require('path');
var autoprefixer = require('autoprefixer');
var ports = {
// local dev server port
default: 8081,
// local hot reload dev server port
reload: 3000,
};
var urls = {
public: '/',
};
var projectRoot = path.resolve(__dirname);
var clientSrc = path.join(projectRoot, 'src', 'client');
var absPaths = {
clientSrc: clientSrc,
buildOutput: path.join(projectRoot, 'buildOutput'),
codegen: path.join(projectRoot, 'codegen'),
nodeModules: path.join(projectRoot, 'node_modules'),
coverage: path.join(projectRoot, 'coverage'),
serverRoot: path.join(projectRoot, 'src', 'server'),
mainEntryJit: path.join(clientSrc, 'main.browser-jit.ts'),
vendorEntryJit: path.join(clientSrc, 'vendor-jit.ts'),
mainEntryAot: path.join(clientSrc, 'main.browser-aot.ts'),
vendorEntryAot: path.join(clientSrc, 'vendor-aot.ts'),
testEntry: path.join(clientSrc, 'karma-entry.js'),
staticFiles: path.join(clientSrc, 'static'),
};
var relPaths = {
localDevRoot: 'buildOutput/',
main: 'js/main-bundle.js',
vendor: 'js/vendor-bundle.js',
// allow for multiple entry points, hence multiple outputs
bundle: 'js/[name]-bundle.js',
sourceMap: 'js/[name]-bundle.js.map',
chunk: 'js/[id]-chunk.js',
};
var patterns = {
testSources: path.join(absPaths.clientSrc, '**/*.spec.ts'),
appSources: path.join(absPaths.clientSrc, '**/!(*.spec).ts'),
// The (\\|\/) piece accounts for path separators in *nix and Windows
angularContext: /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
};
var rules = {
// pre-loaders
tslint: {
enforce: 'pre',
test: /\.ts$/,
loader: 'tslint-loader',
include: [
absPaths.clientSrc,
],
exclude: [
absPaths.nodeModules, // skip all node modules
absPaths.buildOutput, // skip output
absPaths.codegen, // skip (AOT) generated code
absPaths.serverRoot, // skip server
],
},
// Source map loader support for *.js files
// Extracts SourceMaps for source files that are added as sourceMappingURL comment.
javascriptTest: {
enforce: 'pre',
test: /\.js$/,
loader: 'source-map-loader',
exclude: [
// these packages have problems with their sourcemaps
path.join(absPaths.nodeModules, '@angular'),
path.join(absPaths.nodeModules, 'rxjs'),
],
},
// normal loaders
// all `.ts` files will be compiled through tsc by `awesome-typescript-loader`.
// `angular2-template-loader` converts template/style URLs into inlined template/styles.
typescriptJit: {
test: /\.ts$/,
use: [
'awesome-typescript-loader',
'angular2-template-loader'
],
include: [
absPaths.clientSrc,
],
exclude: [
absPaths.nodeModules, // skip all node modules
absPaths.buildOutput, // skip output
absPaths.codegen, // skip (AOT) generated code
absPaths.serverRoot, // skip server
/\.(spec|e2e|async)\.ts$/, // skip all test and async TS files
],
},
typescriptAot: {
test: /\.ts$/,
use: [{
loader: 'awesome-typescript-loader',
options: {
configFileName: './tsconfig-aot.json',
},
}, {
loader: 'angular2-template-loader',
}],
include: [
absPaths.clientSrc,
absPaths.codegen, // include (AOT) generated code
],
exclude: [
absPaths.nodeModules, // skip all node modules
absPaths.buildOutput, // skip output
absPaths.serverRoot, // skip server
/\.(spec|e2e|async)\.ts$/, // skip all test and async TS files
],
},
typescriptTest: {
test: /\.ts$/,
use: [
'awesome-typescript-loader',
'angular2-template-loader',
],
include: [
absPaths.clientSrc,
],
exclude: [
absPaths.nodeModules, // skip all node modules
absPaths.buildOutput, // skip output
absPaths.codegen, // skip (AOT) generated code
absPaths.serverRoot, // skip server
/\.(e2e|async)\.ts$/, // skip end-to-end test and async TS files
],
},
// support for requiring component-scoped CSS as raw text
// NOTE: this assumes that their filename ends in '.component.css'
componentCss: {
test: /\.component\.css$/,
use: [
'raw-loader',
'postcss-loader',
],
include: [
absPaths.clientSrc,
],
exclude: [
absPaths.nodeModules, // skip all node modules
absPaths.buildOutput, // skip output
absPaths.codegen, // skip (AOT) generated code
absPaths.serverRoot, // skip server
],
},
// support for requiring component-scoped Sass as raw text
// NOTE: this assumes that their filename ends in 'component.scss'
componentSass: {
test: [/component\.scss$/, /color-picker\.scss$/],
use: [
'raw-loader',
'postcss-loader',
'sass-loader',
],
include: [
absPaths.clientSrc,
],
exclude: [
absPaths.nodeModules, // skip all node modules
absPaths.buildOutput, // skip output
absPaths.codegen, // skip (AOT) generated code
absPaths.serverRoot, // skip server
],
},
// support for requiring global, crosswide CSS as <style> tag
// NOTE: this assumes that their filename don't contain `component`
globalCss: {
test: /^(?!.*component).*\.css$/,
/*
use: [
{
loader: 'style-loader',
}, {
loader: 'css-loader',
options: {
sourceMap: true,
},
}, {
loader: 'postcss-loader',
options: {
sourceMap: true,
},
},
],
*/
use: [
'style-loader',
'css-loader',
'postcss-loader',
],
include: [
absPaths.clientSrc,
absPaths.nodeModules, // allow to import CSS from third-party libraries
],
exclude: [
absPaths.buildOutput, // skip output
absPaths.codegen, // skip (AOT) generated code
absPaths.serverRoot, // skip server
],
},
// support for requiring HTML as raw text
html: {
test: /\.html$/,
loader: 'raw-loader',
include: [
absPaths.clientSrc,
],
exclude: [
absPaths.nodeModules, // skip all node modules
absPaths.buildOutput, // skip output
absPaths.codegen, // skip (AOT) generated code
absPaths.serverRoot, // skip server
],
},
// instrument only code that isn't test or third-party
// delay coverage until after tests are run, fixing transpiled source coverage error
istanbul: {
enforce: 'post',
test: /\.(js|ts)$/,
loader: 'istanbul-instrumenter-loader',
include: [
absPaths.clientSrc,
],
exclude: [
/\.(e2e|spec)\.ts$/, // skip all test files
absPaths.nodeModules, // skip all node modules
absPaths.buildOutput, // skip output
absPaths.codegen, // skip (AOT) generated code
absPaths.serverRoot, // skip server
],
},
};
var noParse = [
/.+zone\.js\/dist\/.+/,
];
var postcss = [
autoprefixer({
browsers: ['last 2 versions'],
}),
];
var resolve = {
// resolve files using only those extensions
extensions: ['.ts', '.js', '.json'],
// resolve modules also looking in those paths
modules: [absPaths.nodeModules],
};
function buildDefines() {
var packageDef = require('./package.json');
return {
'NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'VERSION': JSON.stringify(packageDef.version),
};
}
var common = {
urls: urls,
ports: ports,
absPaths: absPaths,
relPaths: relPaths,
patterns: patterns,
rules: rules,
noParse: noParse,
postcss: postcss,
resolve: resolve,
buildDefines: buildDefines,
};
module.exports = common;