1 | const path = require('path')
|
2 | const fs = require('fs')
|
3 |
|
4 | exports.extend = api => {
|
5 | if (api.config.target !== 'app') return
|
6 |
|
7 | api.chainWebpack(config => {
|
8 |
|
9 | if (api.isCommand('build')) {
|
10 | config.optimization.splitChunks({
|
11 | cacheGroups: {
|
12 | vendors: {
|
13 | name: `chunk-vendors`,
|
14 | test: /[\\/]node_modules[\\/]/,
|
15 | priority: -10,
|
16 | chunks: 'initial'
|
17 | },
|
18 | common: {
|
19 | name: `chunk-common`,
|
20 | minChunks: 2,
|
21 | priority: -20,
|
22 | chunks: 'initial',
|
23 | reuseExistingChunk: true
|
24 | }
|
25 | }
|
26 | })
|
27 | }
|
28 |
|
29 |
|
30 | const HtmlPlugin = require('html-webpack-plugin')
|
31 | HtmlPlugin.__expression = `require('html-webpack-plugin')`
|
32 |
|
33 | for (const entryName of Object.keys(api.config.pages)) {
|
34 | const page = Object.assign(
|
35 | {
|
36 | template: 'public/index.html',
|
37 | title: api.projectPkg.data.name || 'Poi App',
|
38 | filename: `${entryName}.html`
|
39 | },
|
40 | api.config.pages[entryName]
|
41 | )
|
42 |
|
43 |
|
44 | page.template = api.resolveBaseDir(page.template)
|
45 | if (!fs.existsSync(page.template)) {
|
46 | page.template = path.join(__dirname, '../default-template.html')
|
47 | }
|
48 | config.plugin(`html-${entryName}`).use(HtmlPlugin, [page])
|
49 | }
|
50 | })
|
51 | }
|
52 |
|
53 | exports.name = 'builtin:config-app'
|