-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.ts
101 lines (93 loc) · 1.99 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
95
96
97
98
99
100
101
import { Configuration, DefinePlugin } from 'webpack';
import nodeExternals from 'webpack-node-externals';
import * as path from 'path';
/* -----------------------------------
*
* Output
*
* -------------------------------- */
const outputFiles = [
{ target: 'es5', filename: '[name].es5.js' },
// { target: 'es2016', filename: '[name].js' },
];
/* -----------------------------------
*
* Default
*
* -------------------------------- */
const defaultConfig = {
entry: {
index: path.join(__dirname, './src/index.ts'),
},
externals: [nodeExternals()],
context: path.join(__dirname, './src'),
output: {
path: path.join(__dirname, './dist'),
filename: '[name].js',
libraryTarget: 'umd',
globalObject: 'this',
},
resolve: {
extensions: ['.ts', '.tsx', 'json'],
alias: {
'@': path.join(__dirname, './src'),
},
},
node: {
__filename: true,
__dirname: true,
},
stats: {
colors: true,
timings: true,
},
};
/* -----------------------------------
*
* Config
*
* -------------------------------- */
const config = ({ mode }): Configuration[] =>
outputFiles.map(({ target, filename, ...config }) => ({
...defaultConfig,
mode,
target,
devtool: mode === 'development' ? 'eval-source-map' : void 0,
cache: mode === 'development',
output: {
...defaultConfig.output,
filename,
},
module: {
rules: [
{
test: /\.ts$/,
use: [
{
loader: 'ts-loader',
options: {
compilerOptions: {
target,
},
},
},
],
},
],
},
performance: {
hints: mode === 'development' ? 'warning' : void 0,
},
plugins: [
new DefinePlugin({
__DEV__: mode === 'development',
}),
],
...config,
}));
/* -----------------------------------
*
* Export
*
* -------------------------------- */
module.exports = config;