-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
53 lines (46 loc) · 1.35 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
'use strict';
const globule = require('globule');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const targetTypes = { ejs : 'html', js : 'js' };
const getEntriesList = (targetTypes) => {
const entriesList = {};
for(const [ srcType, targetType ] of Object.entries(targetTypes)) {
const filesMatched = globule.find([`**/*.${srcType}`, `!**/_*.${srcType}`], { cwd : `${__dirname}/src` });
for(const srcName of filesMatched) {
const targetName = srcName.replace(new RegExp(`.${srcType}$`, 'i'), `.${targetType}`);
entriesList[targetName] = `${__dirname}/src/${srcName}`;
}
}
return entriesList;
}
const app = {
entry : getEntriesList(targetTypes),
output : {
filename : '[name]',
path : `${__dirname}/public`
},
module : {
rules : [{
test : /\.ejs$/,
use : [
'html-loader',
'ejs-html-loader'
]
}]
},
plugins : [
new CopyWebpackPlugin(
[{ from : `${__dirname}/src` }],
{ ignore : Object.keys(targetTypes).map((ext) => `*.${ext}`) }
)
]
};
for(const [ targetName, srcName ] of Object.entries(getEntriesList({ ejs : 'html' }))) {
app.plugins.push(new HtmlWebpackPlugin({
filename : targetName,
template : srcName
}));
}
module.exports = app;