-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
66 lines (61 loc) · 1.9 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
const path = require('path');
// 自定义NODE_ENV变量将其设置为开发模式
process.env.NODE_ENV = 'development';
const multiConfig = [
{
name: 'demo',
entry: './src/index.js',
mode: "development",
output: {
path: path.resolve(__dirname, 'dist'),
filename: "md-reverse.demo.js",
library: 'MdReverse',
libraryTarget: 'umd',
libraryExport: 'default',
},
devServer: {
contentBase: './demo',
publicPath: '/dist/',
},
devtool: "eval-source-map"
},
{
name: 'browser',
entry: './src/index.js',
mode: "development",
output: {
path: path.resolve(__dirname, 'dist'),
filename: "md-reverse.browser.js",
library: 'MdReverse',
libraryTarget: 'umd',
libraryExport: 'default',
},
},
{
name: 'browser-min',
entry: './src/index.js',
mode: "production",
output: {
path: path.resolve(__dirname, 'dist'),
filename: "md-reverse.browser.min.js",
library: 'MdReverse',
libraryTarget: 'umd',
libraryExport: 'default',
},
}
];
module.exports = (envArgs) => {
let configs;
if (!envArgs) {
configs = multiConfig;
} else {
const enabledConfigNames = Object.keys(envArgs);
const enabledConfigs = multiConfig.filter((config) => enabledConfigNames.includes(config.name));
if (!enabledConfigs.length) {
throw new Error(`找不到名为 ${JSON.stringify(enabledConfigNames)} 的配置. 可用的所有配置: ${multiConfig.map(config => config.name).join(', ')}`);
}
configs = enabledConfigs;
}
console.log(`正在构建的配置: ${configs.map(config => config.name).join(', ')}.\n`);
return configs;
};