-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.ts
94 lines (84 loc) · 2.11 KB
/
webpack.config.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
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
import * as fs from 'fs';
import * as path from 'path';
import * as webpack from 'webpack';
const _ = require('lodash');
const minimist = require('minimist');
const NodemonPlugin = require('nodemon-webpack-plugin');
const { TsConfigPathsPlugin, CheckerPlugin } = require('awesome-typescript-loader');
const DEFAULT_TARGET = 'node';
const nodeModules = fs.readdirSync('node_modules')
.reduce(function (acc: any, mod: any) {
if (mod === '.bin') {
return acc;
}
acc[mod] = 'commonjs ' + mod;
return acc;
}, {});
const DEFAULT_PARAMS: webpack.Configuration = {
mode: 'production',
context: path.join(__dirname, `src`),
target: 'node',
externals: nodeModules,
resolve: {
extensions: ['.ts', '.js']
},
optimization: {
minimize: false
},
module: {
rules: [
{
test: /\.ts$/,
use: [
{
loader: 'awesome-typescript-loader',
options: {
configFileName: 'tsconfig.json'
}
}
]
}
]
}
};
const PARAMS_PER_TARGET: any = {
node: {
target: 'node',
entry: {
App: './server.ts'
},
output: {
path: path.join(__dirname, 'dist'),
libraryTarget: 'commonjs',
filename: `[name].js`
},
plugins: [
new NodemonPlugin(), // Dong
],
node: {
console: false,
global: false,
process: false,
crypto: false,
Buffer: false,
__filename: false,
__dirname: false
}
}
};
const target: string = _resolveBuildTarget(DEFAULT_TARGET);
const params: any = _.merge(DEFAULT_PARAMS, PARAMS_PER_TARGET[target], _mergeArraysCustomizer);
export default params;
function _resolveBuildTarget (defaultTarget: string): string {
let target = minimist(process.argv.slice(2)).target;
if (!target) {
console.log('No build target provided, using default target instead\n\n');
target = defaultTarget;
}
return target;
}
function _mergeArraysCustomizer (a: any, b: any): any {
if (_.isArray(a)) {
return a.concat(b);
}
}