-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathutils.js
27 lines (25 loc) · 1.01 KB
/
utils.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
const pageConfig = require('./page.config.js');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
exports.pushHtmlWebpackPlugins = (webpackConfig, options = {}) => {
if (pageConfig && Array.isArray(pageConfig)) {
pageConfig.map(page => {
webpackConfig.entry[page.name] = `./src/pages/${page.jsEntry}`;
let template = path.join(__dirname, `/src/pages/${page.html}`);
// 如果是ejs文件,启用ejs-loader编译
if (path.extname(page.html) === '.ejs') {
template = `!!ejs-loader!${template}`;
}
webpackConfig.plugins.push(new HtmlWebpackPlugin({
filename: path.join(__dirname, `/dist/${page.name}.html`),
template,
inject: true,
chunks: [page.name],
inlineSource: '.(js|css)$',
chunksSortMode: 'dependency',
...options
}))
})
}
return webpackConfig
}