-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathwebpack.config.js
More file actions
64 lines (56 loc) · 1.91 KB
/
webpack.config.js
File metadata and controls
64 lines (56 loc) · 1.91 KB
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
/* eslint-disable no-console */
import { merge } from 'webpack-merge';
import * as utils from '@talend/scripts-utils';
import { getPresetApi } from '../utils/preset.js';
function getPluginInfo(a) {
return {
name: a.constructor.name,
simpleattr: Object.keys(a)
.filter(key => ['string', 'boolean'].includes(typeof a[key]))
.filter(key => !Array.isArray(a[key]))
.map(key => [key, a[key]]),
};
}
export default async (env = {}) => {
const presetApi = getPresetApi();
let webpackConfigurations = [];
const defaultConfig = await import('@talend/scripts-config-react-webpack');
webpackConfigurations = webpackConfigurations.concat(
defaultConfig.default(presetApi, { umd: env.umd }),
);
// User configuration file
const userConfigPath = presetApi.getUserConfig(['webpack', 'config', presetApi.mode]);
if (userConfigPath) {
let userConfigAbsolutePath = utils.path.getAbsolutePath(userConfigPath);
if (process.platform === 'win32') {
userConfigAbsolutePath = `file:///${userConfigAbsolutePath}`;
}
console.log(
`Merge ${presetApi.mode} webpack config with custom one (${userConfigAbsolutePath})`,
);
const config = await import(userConfigAbsolutePath);
webpackConfigurations.push(config.default);
}
webpackConfigurations = await Promise.all(
webpackConfigurations.map(async conf => {
if (typeof conf === 'function') {
const asyncConf = await conf(env);
return asyncConf;
}
return conf;
}),
);
// Merge all configuration. User config can override preset ones,
const config = merge(...webpackConfigurations);
if (presetApi.getUserConfig(['webpack', 'debug'], false)) {
const light = Object.keys(config)
.filter(key => key !== 'plugins')
.reduce((acc, key) => {
acc[key] = config[key];
return acc;
}, {});
console.log(JSON.stringify(light, null, 2));
console.log('plugins:', JSON.stringify(config.plugins.map(getPluginInfo), null, 2));
}
return config;
};