-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
113 lines (95 loc) · 1.97 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const path = require('path');
const webpack = require('webpack');
const babelLoader = {
loader: 'babel-loader',
test: /\.js$/
};
const cssLoader = {
test: /\.css$/,
use: ['style-loader','css-loader'],
};
const rules = [
babelLoader,
cssLoader
];
const resolve = {
extensions: ['.js']
};
const entry = './src/bundle.js';
const configs = [
//custom bundle build
{
entry: './src/separate.js',
module: {
rules
},
resolve,
output: {
filename: 'separated.js',
path: path.resolve(__dirname, 'dist')
}
},
// setup top load UIkit internally
{
entry: './src/bundle.css.js',
module: {
rules
},
resolve,
output: {
filename: 'bundle.css.js',
path: path.resolve(__dirname, 'dist')
}
},
{
entry: './src/bundle.js',
module: {
rules
},
resolve,
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
}
},
// setup top load UIkit externally
{
entry: './src/extern.js',
module: {
rules
},
resolve,
output: {
filename: 'external.js',
path: path.resolve(__dirname, 'dist')
},
externals: {
'uikit': 'UIkit',
}
}
];
//add typescript related settings
// module.exports = configs;
module.exports = configs.concat(configs.map(conf => {
const alteration = JSON.parse(JSON.stringify(conf)); // clone deep
//add typescript settings
alteration.entry = alteration.entry.replace('.js', '.ts');
alteration.output.filename = alteration.output.filename.replace('.js', '.ts.js');
const advancedCSSLoader = Object.assign({}, cssLoader);
advancedCSSLoader.use = ['style-loader',{
loader: 'typings-for-css-modules-loader',
options: {
modules: true,
namedExport: true,
camelCase: true
}
},'css-loader'];
alteration.module.rules = [advancedCSSLoader, {
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/
}].concat(conf.module.rules);//.concat()
alteration.plugins = conf.plugins; //restore plugins
alteration.resolve.extensions = ['.ts'];
return alteration;
}));