Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7effc30

Browse files
authored
feat: Added supporttype=systemjs-module via thescriptLoading option (#1822)
1 parent318cd4d commit7effc30

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Allowed values are as follows:
151151
|**`templateParameters`**|`{Boolean\|Object\|Function}`|`false`| Allows to overwrite the parameters used in the template - see[example](https://github.com/jantimon/html-webpack-plugin/tree/master/examples/template-parameters)|
152152
|**`inject`**|`{Boolean\|String}`|`true`|`true \|\| 'head' \|\| 'body' \|\| false` Inject all assets into the given`template` or`templateContent`. When passing`'body'` all javascript resources will be placed at the bottom of the body element.`'head'` will place the scripts in the head element. Passing`true` will add it to the head/body depending on the`scriptLoading` option. Passing`false` will disable automatic injections. - see the[inject:false example](https://github.com/jantimon/html-webpack-plugin/tree/master/examples/custom-insertion-position)|
153153
|**`publicPath`**|`{String\|'auto'}`|`'auto'`|The publicPath used for script and link tags|
154-
|**`scriptLoading`**|`{'blocking'\|'defer'\|'module'}`|`'defer'`| Modern browsers support non blocking javascript loading (`'defer'`) to improve the page startup performance. Setting to`'module'` adds attribute[`type="module"`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#applying_the_module_to_your_html). This also implies "defer", since modules are automatically deferred.|
154+
|**`scriptLoading`**|`{'blocking'\|'defer'\|'module'\|'systemjs-module'}`|`'defer'`| Modern browsers support non blocking javascript loading (`'defer'`) to improve the page startup performance. Setting to`'module'` adds attribute[`type="module"`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#applying_the_module_to_your_html). This also implies "defer", since modules are automatically deferred.|
155155
|**`favicon`**|`{String}`|``|Adds the given favicon path to the output HTML|
156156
|**`meta`**|`{Object}`|`{}`|Allows to inject`meta`-tags. E.g.`meta: {viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'}`|
157157
|**`base`**|`{Object\|String\|false}`|`false`|Inject a[`base`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base) tag. E.g.`base: "https://example.com/path/page.html`|

‎index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ class HtmlWebpackPlugin {
7878
options.template=this.getTemplatePath(this.options.template,compiler.context);
7979

8080
// Assert correct option spelling
81-
if(options.scriptLoading!=='defer'&&options.scriptLoading!=='blocking'&&options.scriptLoading!=='module'){
81+
if(options.scriptLoading!=='defer'&&options.scriptLoading!=='blocking'&&options.scriptLoading!=='module'&&options.scriptLoading!=='systemjs-module'){
8282
/**@type {Logger} */
83-
(this.logger).error('The "scriptLoading" option need to be set to "defer", "blocking" or "module"');
83+
(this.logger).error('The "scriptLoading" option need to be set to "defer", "blocking" or "module" or "systemjs-module"');
8484
}
8585

8686
if(options.inject!==true&&options.inject!==false&&options.inject!=='head'&&options.inject!=='body'){
@@ -794,6 +794,8 @@ class HtmlWebpackPlugin {
794794
attributes.defer=true;
795795
}elseif(this.options.scriptLoading==='module'){
796796
attributes.type='module';
797+
}elseif(this.options.scriptLoading==='systemjs-module'){
798+
attributes.type='systemjs-module';
797799
}
798800

799801
attributes.src=src;

‎spec/basic.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,6 +2572,20 @@ describe('HtmlWebpackPlugin', () => {
25722572
},[/<scripttype="module"src="index_bundle.js"><\/script>.+<body>/],null,done);
25732573
});
25742574

2575+
it('should allow to inject scripts with a type="systemjs-module" attribute',done=>{
2576+
testHtmlPlugin({
2577+
mode:'production',
2578+
entry:path.join(__dirname,'fixtures/index.js'),
2579+
output:{
2580+
path:OUTPUT_DIR,
2581+
filename:'index_bundle.js'
2582+
},
2583+
plugins:[newHtmlWebpackPlugin({
2584+
scriptLoading:'systemjs-module'
2585+
})]
2586+
},[/<scripttype="systemjs-module"src="index_bundle.js"><\/script>.+<body>/],null,done);
2587+
});
2588+
25752589
it('should allow to inject scripts with a defer="defer" attribute to the body',done=>{
25762590
testHtmlPlugin({
25772591
mode:'production',

‎typings.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ declare namespace HtmlWebpackPlugin {
9898
*
9999
*@default 'defer'
100100
*/
101-
scriptLoading?:"blocking"|"defer"|"module";
101+
scriptLoading?:"blocking"|"defer"|"module"|"systemjs-module";
102102
/**
103103
* Inject meta tags
104104
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp