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 1
/
webpack.common.js
230 lines (190 loc) · 5.02 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
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var path = require('path');
var autoprefixer = require('autoprefixer');
// TODO delete watchpack explicit dependency from package.json when
// webpack fixes issue https://github.com/webpack/webpack/issues/4341
var tsLoaderJit = 'awesome-typescript-loader';
/*
var tsLoaderJit = 'ts-loader';
*/
var ports = {
// local dev server port
default: 51254,
// local hot reload dev server port
reload: 3000,
};
var urls = {
public: '/',
};
var clientRoot = path.resolve(__dirname);
var clientSrc = path.join(clientRoot, 'src');
var absPaths = {
clientSrc: clientSrc,
buildOutput: path.join(clientRoot, 'dist'),
nodeModules: path.join(clientRoot, 'node_modules'),
coverage: path.join(clientRoot, 'coverage'),
staticFiles: path.join(clientSrc, 'static'),
};
var relPaths = {
localDevRoot: 'dist/',
// keep leading `./` in entry point relative paths
mainEntryJit: './src/main.browser.ts',
vendorEntryJit: './src/vendor-jit.ts',
mainEntryAot: './src/main.browser.ts',
vendorEntryAot: './src/vendor-aot.ts',
// allow for multiple entry points, hence multiple outputs
bundleJs: 'js/[name]-bundle.js',
chunk: 'js/[id]-chunk.js',
bundleCss: 'css/[name]-bundle.css',
};
var patterns = {
// See https://github.com/angular/angular/issues/11580
// https://github.com/angular/angular/issues/14898
// https://github.com/angular/angular.io/issues/3514
// The (\\|\/) piece accounts for path separators in *nix and Windows
angularContext: /angular(\\|\/)core(\\|\/)@angular/,
clientSrc: /src/,
styles: /styles/,
nodeModules: /node_modules/,
};
var rules = {
// pre-loaders
// None
// normal loaders
typescript: {
// all `.ts` files will be compiled through tsc by chosen tsLoaderJit.
// `angular2-template-loader` converts template/style URLs into inlined template/styles.
// `angular-router-loader` replaces string-based module lazy loading routes with actual
// `loadChildren` router instructions
jit: {
test: /\.ts$/,
use: [{
loader: tsLoaderJit,
options: {
compilerOptions: {
noEmit: false,
},
},
}, {
loader: 'angular2-template-loader',
}, {
loader: 'angular-router-loader',
}],
include: [
patterns.clientSrc,
],
},
aot: {
test: /\.ts$/,
// use @ngtools loader
use: [{
loader: '@ngtools/webpack',
}],
include: [
patterns.clientSrc,
],
},
},
css: {
// support for requiring component-scoped CSS as raw text
// NOTE: this assumes that they're within client source folder
component: {
test: /\.css$/,
use: [
'raw-loader',
'postcss-loader',
],
include: [
patterns.clientSrc,
],
},
// support for requiring global, crosswide CSS styles as <style> tag
// NOTE: this assumes that they're within global styles folder or node modules folder
global: {
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
'to-string-loader',
'css-loader',
'postcss-loader',
],
}),
include: [
patterns.styles, // include global styles
patterns.nodeModules, // allow importing from third-party libraries
],
},
},
sass: {
// support for requiring component-scoped Sass as raw text
// NOTE: this assumes that they're within client source folder
component: {
test: /\.scss$/,
use: [
'raw-loader',
'postcss-loader',
'sass-loader',
],
include: [
patterns.clientSrc,
],
},
// support for requiring global, crosswide Sass styles as <style> tag
// NOTE: this assumes that they're within global styles folder or in a library
global: {
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
'to-string-loader',
'css-loader',
'postcss-loader',
'sass-loader',
],
}),
include: [
patterns.styles, // include global styles
patterns.nodeModules, // allow importing from third-party libraries
],
},
},
// support for requiring HTML as raw text
html: {
test: /\.html$/,
use: [
'raw-loader',
],
include: [
patterns.clientSrc,
],
},
// post-loaders
// None
};
var noParse = [
/.+zone\.js\/dist\/.+/,
];
var resolve = {
// resolve files using only those extensions
extensions: ['.ts', '.js', '.json'],
};
var common = {
urls: urls,
ports: ports,
relPaths: relPaths,
absPaths: absPaths,
patterns: patterns,
rules: rules,
noParse: noParse,
resolve: resolve,
};
exports.common = common;
function buildDefines() {
var packageDef = require('./package.json');
return {
'NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'VERSION': JSON.stringify(packageDef.version),
};
}
exports.buildDefines = buildDefines;