Skip to content

Commit

Permalink
fix: correctly ignore html templates in copy-webpack-plugin (#4613)
Browse files Browse the repository at this point in the history
Fixes #3597.
Fixes #4299.

(cherry picked from commit cb740ae)
  • Loading branch information
sodatea committed Oct 10, 2019
1 parent ceeac16 commit a3225ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 12 additions & 1 deletion packages/@vue/cli-service/__tests__/multiPage.spec.js
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
Expand Up @@ -148,6 +148,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 @@ -204,15 +209,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

0 comments on commit a3225ac

Please sign in to comment.