-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8e46a34
Showing
11 changed files
with
460 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# modulepreload | ||
|
||
Inject modulepreload tags into HTML to remove the waterfall problem in loading web modules. | ||
|
||
```sh | ||
$ npm install --save-dev modulepreload | ||
$ npx modulepreload inject -w index.html | ||
``` | ||
|
||
Before injection: | ||
```html | ||
<!-- index.html --> | ||
<html> | ||
<head> | ||
<title>Example</title> | ||
</head> | ||
<body> | ||
<script type="module"> | ||
import './dep.js'; // imports ./another-dep.js | ||
</script> | ||
</body> | ||
</html> | ||
``` | ||
|
||
After injection: | ||
|
||
```html | ||
<!-- index.html --> | ||
<html> | ||
<head> | ||
<title>Example</title> | ||
<link rel="modulepreload" href="/dep.js" /> | ||
<link rel="modulepreload" href="/another-dep.js" /> | ||
</head> | ||
<body> | ||
<script type="module"> | ||
import './dep.js'; // imports ./another-dep.js | ||
</script> | ||
</body> | ||
</html> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env node | ||
|
||
import cac from 'cac' | ||
import { inject } from './src/inject.js' | ||
|
||
const cli = cac('module_preload') | ||
|
||
cli.option('--root <root>', 'Root') | ||
cli.option('--no-fetch', 'No fetch') | ||
cli.option('--w', 'Write') | ||
cli.option('--o <out>', 'Out') | ||
|
||
cli.command('inject [...files]', 'Inject files') | ||
.action(async (files, options) => { | ||
const { root, fetch: doFetch } = options | ||
files.forEach(async filePath => { | ||
const defaultOut = options.w ? filePath : null | ||
const out = options.o ? options.o : defaultOut | ||
await inject(filePath, { root, out, noFetch: !doFetch }) | ||
}) | ||
}) | ||
|
||
cli.help() | ||
cli.parse() | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "modulepreload", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "cli.js", | ||
"bin": { | ||
"modulepreload": "./cli.js" | ||
}, | ||
"scripts": { | ||
"test": "node --test" | ||
}, | ||
"type": "module", | ||
"author": "", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@import-maps/resolve": "^2.0.0", | ||
"cac": "^6.7.14", | ||
"es-module-lexer": "^1.4.1", | ||
"htmlparser2": "^9.0.0" | ||
} | ||
} |
Oops, something went wrong.