From 811ccd4399966b1b0c06f0ceaddea3bf865e701d Mon Sep 17 00:00:00 2001 From: zero <68810266+zllkjc@users.noreply.github.com> Date: Fri, 16 Jun 2023 10:47:47 +0800 Subject: [PATCH] fix: add attributes for inline runtime script (#3987) docs: change changeset --- .changeset/shaggy-tools-add.md | 6 ++++++ .../builder-shared/src/plugins/InlineChunkHtmlPlugin.ts | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 .changeset/shaggy-tools-add.md diff --git a/.changeset/shaggy-tools-add.md b/.changeset/shaggy-tools-add.md new file mode 100644 index 000000000000..d0ca6d446930 --- /dev/null +++ b/.changeset/shaggy-tools-add.md @@ -0,0 +1,6 @@ +--- +'@modern-js/builder-shared': patch +--- + +fix: add attributes for inline runtime script +fix: 为 inline runtime 脚本添加属性 diff --git a/packages/builder/builder-shared/src/plugins/InlineChunkHtmlPlugin.ts b/packages/builder/builder-shared/src/plugins/InlineChunkHtmlPlugin.ts index 98cf14dcc402..00dd36641292 100644 --- a/packages/builder/builder-shared/src/plugins/InlineChunkHtmlPlugin.ts +++ b/packages/builder/builder-shared/src/plugins/InlineChunkHtmlPlugin.ts @@ -90,9 +90,8 @@ export class InlineChunkHtmlPlugin { if (!(tag?.attributes.src && isString(tag.attributes.src))) { return tag; } - const scriptName = publicPath - ? tag.attributes.src.replace(publicPath, '') - : tag.attributes.src; + const { src, ...otherAttrs } = tag.attributes; + const scriptName = publicPath ? src.replace(publicPath, '') : src; if (!this.tests.some(test => test.exec(scriptName))) { return tag; @@ -112,6 +111,9 @@ export class InlineChunkHtmlPlugin { publicPath, type: 'js', }), + attributes: { + ...otherAttrs, + }, closeTag: true, };