-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
45 lines (37 loc) · 1.05 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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const { template } = require('lodash');
//这里注册页面
let entry_path=['./src/index.html','./test/example.html']
let html_pages = entry_path.map((str)=>{
let filename=/([^\/]+)(?=\.\w+$)/gm.exec(str)[0]
return new HtmlWebpackPlugin(
{
filename:filename + '.html',
template:str,
chunks:[filename]
}
)
})
let entrys={}
html_pages.forEach((value)=>{
entrys[value.userOptions.chunks] = value.userOptions.template.replace(/(\.\w+$)/igm,'.js')
})
module.exports = {
mode: 'development',
entry: entrys,//入口js文件
devServer: {
static: './dist',
},
plugins: [
...html_pages,//html文件
new CopyPlugin({patterns:
[{from:'asset',to:'asset'},{from:'style',to:'style'}]})
],
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
clean: true
},
};