Skip to content

fix: correctly ignore html templates in copy-webpack-plugin #4613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/@vue/cli-service/__tests__/multiPage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ async function makeProjectMultiPage (project) {
index: { entry: 'src/main.js' },
foo: { entry: 'src/foo.js' },
bar: { entry: 'src/bar.js' },
foobar: { entry: ['src/foobar.js'] }
foobar: { entry: ['src/foobar.js'] },
baz: {
entry: 'src/main.js',
template: 'public/baz.html',
filename: 'qux.html'
}
},
chainWebpack: config => {
const splitOptions = config.optimization.get('splitChunks')
Expand All @@ -25,6 +30,7 @@ async function makeProjectMultiPage (project) {
}
}
`)
await project.write('public/baz.html', await project.read('public/index.html'))
await project.write('src/foo.js', `
import Vue from 'vue'
new Vue({
Expand Down Expand Up @@ -96,6 +102,11 @@ test('build w/ multi page', async () => {
expect(project.has('dist/foo.html')).toBe(true)
expect(project.has('dist/bar.html')).toBe(true)

// should properly ignore the template file
expect(project.has('dist/baz.html')).toBe(false)
// should respect the `filename` field in a multi-page config
expect(project.has('dist/qux.html')).toBe(true)

const assertSharedAssets = file => {
// should split and preload vendor chunk
expect(file).toMatch(/<link [^>]*js\/chunk-vendors[^>]*\.js rel=preload as=script>/)
Expand Down
13 changes: 10 additions & 3 deletions packages/@vue/cli-service/lib/config/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ module.exports = (api, options) => {
? htmlPath
: defaultHtmlPath

publicCopyIgnore.push({
glob: path.relative(api.resolve('public'), api.resolve(htmlOptions.template)),
matchBase: false
})

webpackConfig
.plugin('html')
.use(HTMLPlugin, [htmlOptions])
Expand Down Expand Up @@ -214,15 +219,17 @@ module.exports = (api, options) => {

// resolve page index template
const hasDedicatedTemplate = fs.existsSync(api.resolve(template))
if (hasDedicatedTemplate) {
publicCopyIgnore.push(template)
}
const templatePath = hasDedicatedTemplate
? template
: fs.existsSync(htmlPath)
? htmlPath
: defaultHtmlPath

publicCopyIgnore.push({
glob: path.relative(api.resolve('public'), api.resolve(templatePath)),
matchBase: false
})

// inject html plugin for the page
const pageHtmlOptions = Object.assign(
{},
Expand Down