Skip to content

Commit 8b0a2ad

Browse files
authored
Merge pull request webpack#6225 from neeharv/feature/async-script-type
add support for new output option jsonpScriptType
2 parents 9a0da7b + 21b5a02 commit 8b0a2ad

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

lib/JsonpMainTemplatePlugin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class JsonpMainTemplatePlugin {
2929
const chunkMaps = chunk.getChunkMaps();
3030
const crossOriginLoading = this.outputOptions.crossOriginLoading;
3131
const chunkLoadTimeout = this.outputOptions.chunkLoadTimeout;
32+
const jsonpScriptType = this.outputOptions.jsonpScriptType;
3233
const scriptSrcPath = this.applyPluginsWaterfall("asset-path", JSON.stringify(chunkFilename), {
3334
hash: `" + ${this.renderCurrentHashCode(hash)} + "`,
3435
hashWithLength: length => `" + ${this.renderCurrentHashCode(hash, length)} + "`,
@@ -48,7 +49,7 @@ class JsonpMainTemplatePlugin {
4849
});
4950
return this.asString([
5051
"var script = document.createElement('script');",
51-
"script.type = 'text/javascript';",
52+
`script.type = ${JSON.stringify(jsonpScriptType)};`,
5253
"script.charset = 'utf-8';",
5354
"script.async = true;",
5455
`script.timeout = ${chunkLoadTimeout};`,

lib/WebpackOptionsDefaulter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
6161
this.set("output.hotUpdateChunkFilename", "[id].[hash].hot-update.js");
6262
this.set("output.hotUpdateMainFilename", "[hash].hot-update.json");
6363
this.set("output.crossOriginLoading", false);
64+
this.set("output.jsonpScriptType", "text/javascript");
6465
this.set("output.chunkLoadTimeout", 120000);
6566
this.set("output.hashFunction", "md5");
6667
this.set("output.hashDigest", "hex");

schemas/webpackOptionsSchema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,13 @@
314314
"use-credentials"
315315
]
316316
},
317+
"jsonpScriptType": {
318+
"description": "This option enables loading async chunks via a custom script type, such as script type=\"module\"",
319+
"enum": [
320+
"text/javascript",
321+
"module"
322+
]
323+
},
317324
"chunkLoadTimeout": {
318325
"description": "Number of milliseconds before chunk request expires",
319326
"type": "number"

0 commit comments

Comments
 (0)