Skip to content

Commit 772dc8c

Browse files
committed
fix: correctly ignore html templates in copy-webpack-plugin
Fixes vuejs#3597. Fixes vuejs#4299.
1 parent 2e1e92b commit 772dc8c

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
@@ -158,6 +158,11 @@ module.exports = (api, options) => {
158158
? htmlPath
159159
: defaultHtmlPath
160160

161+
publicCopyIgnore.push({
162+
glob: path.relative(api.resolve('public'), api.resolve(htmlOptions.template)),
163+
matchBase: false
164+
})
165+
161166
webpackConfig
162167
.plugin('html')
163168
.use(HTMLPlugin, [htmlOptions])
@@ -214,15 +219,17 @@ module.exports = (api, options) => {
214219

215220
// resolve page index template
216221
const hasDedicatedTemplate = fs.existsSync(api.resolve(template))
217-
if (hasDedicatedTemplate) {
218-
publicCopyIgnore.push(template)
219-
}
220222
const templatePath = hasDedicatedTemplate
221223
? template
222224
: fs.existsSync(htmlPath)
223225
? htmlPath
224226
: defaultHtmlPath
225227

228+
publicCopyIgnore.push({
229+
glob: path.relative(api.resolve('public'), api.resolve(templatePath)),
230+
matchBase: false
231+
})
232+
226233
// inject html plugin for the page
227234
const pageHtmlOptions = Object.assign(
228235
{},

0 commit comments

Comments
 (0)