-
Notifications
You must be signed in to change notification settings - Fork 23
/
webpack.config.js
67 lines (62 loc) · 1.83 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
var samplesList = [];
var path = require('path');
var glob = require('glob');
var webpack = require('webpack');
var files = glob.sync('./src/**/sample.json', {
silent: true
});
var fs = require('fs');
var sampleList;
if (fs.existsSync('./controlWiseSample.json')) {
sampleList = JSON.parse(fs.readFileSync('./controlWiseSample.json'));
}
if (sampleList && sampleList.length) {
files = getControlWiseBundle();
}
for (var inx = 0; inx < files.length; inx++) {
samplesList.push(require(files[inx]));
}
function getControlWiseBundle() {
var bundleList = JSON.parse(fs.readFileSync('./sampleList.json'));
var controlWiseBundleList = [];
for (var i = 0; i < bundleList.length; i++) {
controlWiseBundleList.push('./src/' + bundleList[i] + '/sample.json');
}
return controlWiseBundleList;
}
module.exports = webpackConfig({
mode : 'development',
entry: {
'src/common/index.min': './src/common/index'
},
devtool: false,
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
test: /node_modules/,
chunks: 'initial',
name: 'src/common.min',
priority: 10,
enforce: true
}
}
},
runtimeChunk: false
},
output: {
path: path.join(__dirname, '/'),
filename: '[name].js'
}
});
function webpackConfig(conf) {
for (var i = 0; i < samplesList.length; i++) {
var dirname = samplesList[i].directory;
var samples = samplesList[i].samples;
for (var j = 0; samples && j < samples.length; j++) {
var entryPoint = 'src/' + dirname + '/' + samples[j].url;
conf.entry['src/'+ dirname + '/' +samples[j].url] = './' + entryPoint;
}
}
return conf;
}