generated from latipun7/webcomponents-webpack-ts
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
43 lines (34 loc) · 1.17 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
import { mergeWithCustomize } from 'webpack-merge';
import type { Configuration } from 'webpack';
import type { ICustomizeOptions } from 'webpack-merge/dist/types';
import commonConfig from './configs/webpack.common';
import devConfig from './configs/webpack.dev';
import productionConfig from './configs/webpack.prod';
const custom: ICustomizeOptions = {
customizeArray(
common: typeof commonConfig['plugins'],
merged: Configuration['plugins'],
key
) {
if (key === 'plugins' && common && merged) {
const [cleanPlugin, ...restCommon] = common;
const [miniCSSPlugin, ...restMerged] = merged;
return [cleanPlugin, ...restMerged, ...restCommon, miniCSSPlugin];
}
return undefined;
},
};
interface CLIOptions {
mode: Configuration['mode'];
}
const config = async (env: CLIOptions): Promise<Configuration> => {
switch (env.mode) {
case 'development':
return mergeWithCustomize(custom)(commonConfig, await devConfig());
case 'production':
return mergeWithCustomize(custom)(commonConfig, await productionConfig());
default:
throw new Error('No matching configuration was found!');
}
};
export default config;