Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit bb05226

Browse files
authored
Fix support for legacy browsers (#1525)
1 parent b7a0b02 commit bb05226

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"dependencies": {
2222
"html-minifier": "^4.0.0",
2323
"http-link-header": "^1.0.2",
24-
"shimport": "^1.0.1",
24+
"shimport": "^2.0.3",
2525
"source-map": "^0.6.1",
2626
"sourcemap-codec": "^1.4.6",
2727
"string-hash": "^1.1.3"

src/core/create_compilers/RollupCompiler.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ import { CompileResult } from './interfaces';
1515
import RollupResult from './RollupResult';
1616

1717
const stderr = console.error.bind(console);
18-
const INJECT_STYLES_ID = 'inject_styles';
18+
const INJECT_STYLES_NAME = 'inject_styles';
19+
const INJECT_STYLES_ID = 'inject_styles.js';
1920

2021
let rollup: any;
2122

2223
const inject_styles = `
23-
export default files => {
24-
return Promise.all(files.map(file => new Promise((fulfil, reject) => {
25-
const href = new URL(file, import.meta.url);
26-
let link = document.querySelector('link[rel=stylesheet][href="' + href + '"]');
24+
export default function(files) {
25+
return Promise.all(files.map(function(file) { return new Promise(function(fulfil, reject) {
26+
var href = new URL(file, import.meta.url);
27+
var link = document.querySelector('link[rel=stylesheet][href="' + href + '"]');
2728
if (!link) {
2829
link = document.createElement('link');
2930
link.rel = 'stylesheet';
@@ -33,10 +34,10 @@ export default files => {
3334
if (link.sheet) {
3435
fulfil();
3536
} else {
36-
link.onload = () => fulfil();
37+
link.onload = function() { return fulfil() };
3738
link.onerror = reject;
3839
}
39-
})));
40+
})}));
4041
};`.trim();
4142

4243
const get_entry_point_output_chunk = (bundle: OutputBundle, entry_point?: string) => {
@@ -128,12 +129,12 @@ export default class RollupCompiler {
128129
this.emitFile({
129130
type: 'chunk',
130131
id: INJECT_STYLES_ID,
131-
name: INJECT_STYLES_ID,
132-
preserveSignature: 'strict'
132+
name: INJECT_STYLES_NAME,
133+
preserveSignature: 'allow-extension'
133134
});
134135
},
135136
load(id: string) {
136-
return id === INJECT_STYLES_ID ? { code: inject_styles, moduleSideEffects: 'no-treeshake' } : null;
137+
return id === INJECT_STYLES_ID ? inject_styles : null;
137138
},
138139
resolveId(importee: string, importer: string) {
139140
return importee === INJECT_STYLES_ID ? INJECT_STYLES_ID : null;
@@ -145,7 +146,7 @@ export default class RollupCompiler {
145146
if (targetModuleId) {
146147
return {
147148
left: 'Promise.all([import(',
148-
right: `), ___SAPPER_CSS_INJECTION___${Buffer.from(targetModuleId).toString('hex')}___]).then(x => x[0])`
149+
right: `), ___SAPPER_CSS_INJECTION___${Buffer.from(targetModuleId).toString('hex')}___]).then(function(x) { return x[0]; })`
149150
};
150151
} else {
151152
return {

0 commit comments

Comments
 (0)