/
server.ts
62 lines (56 loc) · 1.63 KB
/
server.ts
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
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Configuration } from 'webpack';
import { WebpackConfigOptions } from '../build-options';
/**
* Returns a partial specific to creating a bundle for node
* @param wco Options which are include the build options and app config
*/
export function getServerConfig(wco: WebpackConfigOptions) {
const config: Configuration = {
devtool: wco.buildOptions.sourceMap ? 'source-map' : false,
resolve: {
mainFields: [
...(wco.supportES2015 ? ['es2015'] : []),
'main', 'module',
],
},
target: 'node',
output: {
libraryTarget: 'commonjs',
},
node: false,
};
if (wco.buildOptions.bundleDependencies == 'none') {
config.externals = [
/^@angular/,
// tslint:disable-next-line:no-any
(_: any, request: any, callback: (error?: any, result?: any) => void) => {
// Absolute & Relative paths are not externals
if (request.match(/^\.{0,2}\//)) {
return callback();
}
try {
// Attempt to resolve the module via Node
const e = require.resolve(request);
if (/node_modules/.test(e)) {
// It's a node_module
callback(null, request);
} else {
// It's a system thing (.ie util, fs...)
callback();
}
} catch {
// Node couldn't find it, so it must be user-aliased
callback();
}
},
];
}
return config;
}