Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 1a03029

Browse files
author
Je
committed
refactor: improve nomodule polyfill
1 parent 6b27e40 commit 1a03029

File tree

3 files changed

+37
-32
lines changed

3 files changed

+37
-32
lines changed

nomodule.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
var el = document.createElement('div')
2+
var style = {
3+
position: 'fixed',
4+
top: '0',
5+
left: '0',
6+
zIndex: '999',
7+
width: '100%',
8+
margin: '0',
9+
padding: '30px 0',
10+
lineHeight: '1.5',
11+
fontSize: '14px',
12+
color: '#666',
13+
backgroundColor: '#fff9cc',
14+
textAlign: 'center',
15+
boxShadow: '0 1px 5px rgba(0,0,0,0.1)'
16+
}
17+
for (var key in style) {
18+
el.style[key] = style[key]
19+
}
20+
var scripts = document.getElementsByTagName('script')
21+
var isDev = false
22+
for (let i = 0; i < scripts.length; i++) {
23+
const s = scripts[i]
24+
if (/nomodule\.js\?dev$/.test(s.src)) {
25+
isDev = true
26+
}
27+
}
28+
el.innerHTML = '<h2 style="margin:0;paddding:0;line-height:1;font-size:24px;font-weight:700;color:#000;">Your browser is out of date.</h2>'
29+
if (!isDev) {
30+
el.innerHTML += '<p>Aleph.js requires <a href="https://caniuse.com/es6-module" style="font-weight:500;color:#000;">ES module</a> support during development.</p>'
31+
} else {
32+
el.innerHTML += '<p>Update your browser for more security, speed and the best experience on this site.</p>'
33+
}
34+
document.body.appendChild(el)

polyfill.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

project.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { AlephAPIRequest, AlephAPIResponse } from './api.ts'
55
import { EventEmitter } from './events.ts'
66
import { createHtml } from './html.ts'
77
import log from './log.ts'
8-
import { nomoduleJS } from './polyfill.ts'
98
import { Routing } from './router.ts'
109
import { colors, ensureDir, path, ServerRequest, Sha1, walk } from './std.ts'
1110
import { compile } from './tsc/compile.ts'
@@ -195,7 +194,7 @@ export class Project {
195194
head: head,
196195
scripts: [
197196
{ src: path.join(baseUrl, `/_aleph/main.${mainModule.hash.slice(0, hashShort)}.js`), type: 'module' },
198-
{ innerText: nomoduleJS(this.isDev), nomodule: true },
197+
{ src: path.join(baseUrl, `/_aleph/-/deno.land/x/aleph/nomodule.js${this.isDev ? '?dev' : ''}`), nomodule: true },
199198
],
200199
body,
201200
minify: !this.isDev
@@ -210,7 +209,7 @@ export class Project {
210209
lang: defaultLocale,
211210
scripts: [
212211
{ src: path.join(baseUrl, `/_aleph/main.${mainModule.hash.slice(0, hashShort)}.js`), type: 'module' },
213-
{ innerText: nomoduleJS(this.isDev), nomodule: true },
212+
{ src: path.join(baseUrl, `/_aleph/-/deno.land/x/aleph/nomodule.js${this.isDev ? '?dev' : ''}`), nomodule: true },
214213
],
215214
body: `<main></main>`,
216215
minify: !this.isDev
@@ -441,6 +440,7 @@ export class Project {
441440
const precompileUrls = [
442441
'https://deno.land/x/aleph/bootstrap.ts',
443442
'https://deno.land/x/aleph/renderer.ts',
443+
'https://deno.land/x/aleph/nomodule.js',
444444
'https://deno.land/x/aleph/tsc/tslib.js',
445445
]
446446
if (this.isDev) {

0 commit comments

Comments
 (0)