-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
90 lines (81 loc) · 1.91 KB
/
webpack.config.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
import path from 'path';
import ESBuild from 'esbuild';
import { EsbuildPlugin } from 'esbuild-loader';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
const esbuildConfig = {
implementation: ESBuild,
charset: 'utf8',
target: 'esnext'
};
const tsCheckerConfig = {
typescript: {
configFile: './src/tsconfig.json'
}
};
const commonConfig = {
entry: './src/core/Slider89.ts',
target: [ 'web', 'es2023' ],
experiments: {
outputModule: true,
},
output: {
filename: 'Slider89.js',
path: path.resolve('./dist'),
library: {
type: 'window',
},
},
resolve: {
extensions: [ '.ts', '.js' ],
},
plugins: [ new ForkTsCheckerWebpackPlugin(tsCheckerConfig) ],
module: {
rules: [
{
test: /\.tsx?$/i,
loader: 'esbuild-loader',
include: path.resolve('./src'),
options: esbuildConfig
}
]
}
};
const config = {
dev: {
mode: 'development',
devtool: 'inline-source-map',
},
prod: {
mode: 'production',
optimization: {
minimizer: [ new EsbuildPlugin(esbuildConfig) ]
},
}
};
export default Object.keys(config).map(key => {
config[key].name = key;
return deepMergeCopy(commonConfig, config[key]);
});
/**
* Merge all plain object and array properties of two
* objects deeply, returning a new copy.
* Opinionated, effortless, works perfectly.
*/
function deepMergeCopy(target, source) {
if (!source) return;
if (!target) return source;
if (Array.isArray(source) && Array.isArray(target)) {
return [ ...target, ...source ];
}
if (target.toString() === '[object Object]' && source.toString() === '[object Object]') {
const newTarget = Object.assign({}, target);
for (const key in source) {
const result = deepMergeCopy(target[key], source[key]);
if (result != null) {
newTarget[key] = result;
}
}
return newTarget;
}
return source;
}