From 9a58fe628ac7cd3e4068fd5e828efd38b2d69311 Mon Sep 17 00:00:00 2001 From: ylc395 Date: Fri, 23 Oct 2020 14:33:10 +0800 Subject: [PATCH 1/2] feat(cli-service): add inline loader support for html-webpack-plugin --- packages/@vue/cli-service/lib/config/app.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/@vue/cli-service/lib/config/app.js b/packages/@vue/cli-service/lib/config/app.js index 44f3809c49..ab116ee4ca 100644 --- a/packages/@vue/cli-service/lib/config/app.js +++ b/packages/@vue/cli-service/lib/config/app.js @@ -214,15 +214,20 @@ module.exports = (api, options) => { const entries = Array.isArray(entry) ? entry : [entry] webpackConfig.entry(name).merge(entries.map(e => api.resolve(e))) + // test whether use inline loader + // * See https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md#2-setting-a-loader-directly-for-the-template + const inlineLoaderReg = /[-!]?!.+!/ + const isWithInlineLoader = /^[-!]?!/.test(template) + // resolve page index template - const hasDedicatedTemplate = fs.existsSync(api.resolve(template)) + const hasDedicatedTemplate = fs.existsSync(api.resolve(isWithInlineLoader ? template.replace(inlineLoaderReg, '') : template)) const templatePath = hasDedicatedTemplate ? template : fs.existsSync(htmlPath) ? htmlPath : defaultHtmlPath - publicCopyIgnore.push(api.resolve(templatePath).replace(/\\/g, '/')) + publicCopyIgnore.push(api.resolve(templatePath).replace(/\\/g, '/').replace(inlineLoaderReg, '')) // inject html plugin for the page const pageHtmlOptions = Object.assign( From 364996d03d2897c4a2ec070649eb34afb512c797 Mon Sep 17 00:00:00 2001 From: ylc395 Date: Thu, 25 Mar 2021 12:40:24 +0800 Subject: [PATCH 2/2] fix: loader name trimmed correctly --- packages/@vue/cli-service/lib/config/app.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/@vue/cli-service/lib/config/app.js b/packages/@vue/cli-service/lib/config/app.js index ab116ee4ca..8c7fe39a34 100644 --- a/packages/@vue/cli-service/lib/config/app.js +++ b/packages/@vue/cli-service/lib/config/app.js @@ -214,20 +214,19 @@ module.exports = (api, options) => { const entries = Array.isArray(entry) ? entry : [entry] webpackConfig.entry(name).merge(entries.map(e => api.resolve(e))) - // test whether use inline loader + // trim inline loader // * See https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md#2-setting-a-loader-directly-for-the-template - const inlineLoaderReg = /[-!]?!.+!/ - const isWithInlineLoader = /^[-!]?!/.test(template) + const templateWithoutLoader = template.replace(/^.+!/, '').replace(/\?.+$/, '') // resolve page index template - const hasDedicatedTemplate = fs.existsSync(api.resolve(isWithInlineLoader ? template.replace(inlineLoaderReg, '') : template)) + const hasDedicatedTemplate = fs.existsSync(api.resolve(templateWithoutLoader)) const templatePath = hasDedicatedTemplate ? template : fs.existsSync(htmlPath) ? htmlPath : defaultHtmlPath - publicCopyIgnore.push(api.resolve(templatePath).replace(/\\/g, '/').replace(inlineLoaderReg, '')) + publicCopyIgnore.push(api.resolve(templateWithoutLoader).replace(/\\/g, '/')) // inject html plugin for the page const pageHtmlOptions = Object.assign(