Skip to content

Commit b1331ee

Browse files
snadnAkryum
authored andcommitted
fix: when script has no attributes (vuejs#1628)
when use webpack `htmlWebpackIncludeAssetsPlugin` include script. the script has no attributes, and build throw error.
1 parent 050fe2a commit b1331ee

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

packages/@vue/cli-service/lib/webpack/ModernModePlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ModernModePlugin {
3737
compiler.hooks.compilation.tap(ID, compilation => {
3838
compilation.hooks.htmlWebpackPluginAlterAssetTags.tapAsync(ID, async (data, cb) => {
3939
// use <script type="module"> for modern assets
40-
const modernAssets = data.body.filter(a => a.tagName === 'script')
40+
const modernAssets = data.body.filter(a => a.tagName === 'script' && a.attributes)
4141
modernAssets.forEach(a => {
4242
a.attributes.type = 'module'
4343
a.attributes.crossorigin = 'use-credentials'
@@ -54,7 +54,7 @@ class ModernModePlugin {
5454
const htmlName = path.basename(data.plugin.options.filename)
5555
const tempFilename = path.join(this.targetDir, `legacy-assets-${htmlName}.json`)
5656
const legacyAssets = JSON.parse(await fs.readFile(tempFilename, 'utf-8'))
57-
.filter(a => a.tagName === 'script')
57+
.filter(a => a.tagName === 'script' && a.attributes)
5858
legacyAssets.forEach(a => { a.attributes.nomodule = '' })
5959
data.body.push(...legacyAssets)
6060
await fs.remove(tempFilename)

0 commit comments

Comments
 (0)