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.
  • Loading branch information
sodatea committed Sep 24, 2019
1 parent 8705885 commit cb740ae
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 @@ -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

3 comments on commit cb740ae

@lzm0x219
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sodatea 手动@大佬。4.0版本预计什么时候发版捏?

@sodatea
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

等文档写完……

@lzm0x219
Copy link

@lzm0x219 lzm0x219 commented on cb740ae Sep 24, 2019 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.