Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dpikt committed Dec 13, 2023
0 parents commit 8e46a34
Show file tree
Hide file tree
Showing 11 changed files with 460 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
41 changes: 41 additions & 0 deletions README.md
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>
```
25 changes: 25 additions & 0 deletions cli.js
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()

183 changes: 183 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions package.json
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"
}
}
Loading

0 comments on commit 8e46a34

Please sign in to comment.