Skip to content

Commit 8ee736d

Browse files
fix: embed the es-module-shims script
1 parent 77f5fcc commit 8ee736d

4 files changed

+37
-4
lines changed

js/es-module-shims.txt

+2
Large diffs are not rendered by default.

js/src/esmVueTemplate.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as Vue from 'vue'
22
import { parse } from 'vue/compiler-sfc'
3+
import esModuleShims from '../es-module-shims.txt'
34

45
window.esmsInitOptions = { shimMode: true };
56

@@ -71,19 +72,19 @@ async function init() {
7172
init();
7273

7374
async function loadShim() {
74-
if (document.querySelectorAll("script[src*=es-module-shims][type=module]").length) {
75+
if (document.querySelectorAll("script[src*=es-module-shims][type=module]").length || document.getElementById("es-module-shims")) {
7576
console.log("shim was already loadedLoaded");
7677
return;
7778
}
78-
return loadScript("module", "https://ga.jspm.io/npm:es-module-shims@1.7.0/dist/es-module-shims.js")
79+
return loadScript("module", toModuleUrl(esModuleShims), "es-module-shims")
7980
}
8081

81-
async function loadScript(type, src) {
82+
async function loadScript(type, src, id) {
8283
return new Promise((onload, onerror) => {
8384
document.head.appendChild(
8485
Object.assign(
8586
document.createElement("script"),
86-
{type, src, onload, onerror, defer: true }))
87+
{type, src, onload, onerror, defer: true, ...id && { id } }))
8788
})
8889
}
8990

js/webpack.config.js

+22
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ var path = require('path');
22
var version = require('./package.json').version;
33
const webpack = require('webpack');
44

5+
const rules = [
6+
{
7+
test: /.txt$/,
8+
type: 'asset/source',
9+
},
10+
];
11+
512
const plugins = [
613
new webpack.DefinePlugin({
714
__VUE_OPTIONS_API__: true,
@@ -19,6 +26,9 @@ module.exports = [
1926
},
2027
mode: 'production',
2128
plugins,
29+
module: {
30+
rules,
31+
},
2232
},
2333
{
2434
entry: './lib/index.js',
@@ -40,6 +50,9 @@ module.exports = [
4050
},
4151
},
4252
plugins,
53+
module: {
54+
rules,
55+
},
4356
},
4457
{
4558
entry: './lib/nodeps.js',
@@ -62,6 +75,9 @@ module.exports = [
6275
},
6376
},
6477
plugins,
78+
module: {
79+
rules,
80+
},
6581
},
6682
{
6783
entry: './lib/nodeps.js',
@@ -85,6 +101,9 @@ module.exports = [
85101
},
86102
},
87103
plugins,
104+
module: {
105+
rules,
106+
},
88107
},
89108
{
90109
entry: './lib/embed.js',
@@ -102,5 +121,8 @@ module.exports = [
102121
maxAssetSize: 1400000
103122
},
104123
plugins,
124+
module: {
125+
rules,
126+
},
105127
},
106128
];

js/webpack.config.lab.js

+8
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,12 @@ module.exports = {
1313
__VUE_PROD_DEVTOOLS__: false,
1414
})
1515
],
16+
module: {
17+
rules: [
18+
{
19+
test: /.txt$/,
20+
type: 'asset/source',
21+
},
22+
],
23+
},
1624
};

0 commit comments

Comments
 (0)