Skip to content

Commit a3225ac

Browse files
committed
fix: correctly ignore html templates in copy-webpack-plugin (#4613)
Fixes #3597. Fixes #4299. (cherry picked from commit cb740ae)
1 parent ceeac16 commit a3225ac

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

packages/@vue/cli-service/__tests__/multiPage.spec.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ async function makeProjectMultiPage (project) {
1515
index: { entry: 'src/main.js' },
1616
foo: { entry: 'src/foo.js' },
1717
bar: { entry: 'src/bar.js' },
18-
foobar: { entry: ['src/foobar.js'] }
18+
foobar: { entry: ['src/foobar.js'] },
19+
baz: {
20+
entry: 'src/main.js',
21+
template: 'public/baz.html',
22+
filename: 'qux.html'
23+
}
1924
},
2025
chainWebpack: config => {
2126
const splitOptions = config.optimization.get('splitChunks')
@@ -25,6 +30,7 @@ async function makeProjectMultiPage (project) {
2530
}
2631
}
2732
`)
33+
await project.write('public/baz.html', await project.read('public/index.html'))
2834
await project.write('src/foo.js', `
2935
import Vue from 'vue'
3036
new Vue({
@@ -96,6 +102,11 @@ test('build w/ multi page', async () => {
96102
expect(project.has('dist/foo.html')).toBe(true)
97103
expect(project.has('dist/bar.html')).toBe(true)
98104

105+
// should properly ignore the template file
106+
expect(project.has('dist/baz.html')).toBe(false)
107+
// should respect the `filename` field in a multi-page config
108+
expect(project.has('dist/qux.html')).toBe(true)
109+
99110
const assertSharedAssets = file => {
100111
// should split and preload vendor chunk
101112
expect(file).toMatch(/<link [^>]*js\/chunk-vendors[^>]*\.js rel=preload as=script>/)

packages/@vue/cli-service/lib/config/app.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ module.exports = (api, options) => {
148148
? htmlPath
149149
: defaultHtmlPath
150150

151+
publicCopyIgnore.push({
152+
glob: path.relative(api.resolve('public'), api.resolve(htmlOptions.template)),
153+
matchBase: false
154+
})
155+
151156
webpackConfig
152157
.plugin('html')
153158
.use(HTMLPlugin, [htmlOptions])
@@ -204,15 +209,17 @@ module.exports = (api, options) => {
204209

205210
// resolve page index template
206211
const hasDedicatedTemplate = fs.existsSync(api.resolve(template))
207-
if (hasDedicatedTemplate) {
208-
publicCopyIgnore.push(template)
209-
}
210212
const templatePath = hasDedicatedTemplate
211213
? template
212214
: fs.existsSync(htmlPath)
213215
? htmlPath
214216
: defaultHtmlPath
215217

218+
publicCopyIgnore.push({
219+
glob: path.relative(api.resolve('public'), api.resolve(templatePath)),
220+
matchBase: false
221+
})
222+
216223
// inject html plugin for the page
217224
const pageHtmlOptions = Object.assign(
218225
{},

0 commit comments

Comments
 (0)