-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.base.js
78 lines (73 loc) · 1.78 KB
/
webpack.base.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
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const path = require('path')
const glob = require('glob')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const setMPA = () => {
const entry = {}
const htmlWebpackPlugins = []
const entryFiles = glob.sync(path.join(__dirname, './src/pages/*/index.js'))
entryFiles.forEach((item) => {
const pageName = item.match(/pages\/(.*)\/index.js/)[1]
entry[pageName] = item
htmlWebpackPlugins.push(
new HtmlWebpackPlugin({
template: path.join(__dirname, `./src/pages/${pageName}/index.html`),
filename: `${pageName}.html`,
chunks: [pageName],
inject: true,
favicon: path.join(__dirname, './src/assets/favicon.ico'),
minify: {
html5: true,
collapseWhitespace: true,
preserveLineBreaks: false,
minifyCSS: true,
minifyJS: true,
removeComments: false
}
})
)
})
return {
entry,
htmlWebpackPlugins
}
}
const { entry, htmlWebpackPlugins } = setMPA()
const baseModuleRules = [
{
test: /\.js$/,
use: ['babel-loader', 'eslint-loader']
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
{
loader: 'url-loader',
options: {
esModule: false,
name: '[name][hash:8].[ext]',
limit: 10240,
outputPath: './assets/images/'
}
}
]
}
]
const basePlugins = [
...htmlWebpackPlugins,
new CleanWebpackPlugin(),
new CopyWebpackPlugin({
patterns: [
{
from: path.join(__dirname, 'src/lib/markdown-it'),
to: path.join(__dirname, 'dist/js/markdown-it')
}
]
})
]
module.exports = {
entry,
baseModuleRules,
basePlugins
}