html-bundle 6.2.3 → 6.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/dependabot.yml +7 -7
- package/LICENSE +21 -21
- package/README.md +198 -198
- package/dist/bundle.mjs +386 -386
- package/dist/utils.mjs +176 -119
- package/package.json +60 -56
- package/src/bundle.mts +478 -478
- package/src/index.d.ts +3 -3
- package/src/utils.mts +339 -279
- package/tests/bundle.test.mjs +226 -0
- package/tsconfig.json +15 -15
- package/types/static.d.ts +1 -1
package/.github/dependabot.yml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
version: 2
|
|
2
|
-
updates:
|
|
3
|
-
- package-ecosystem: npm
|
|
4
|
-
directory: "/"
|
|
5
|
-
schedule:
|
|
6
|
-
interval: daily
|
|
7
|
-
open-pull-requests-limit: 99
|
|
1
|
+
version: 2
|
|
2
|
+
updates:
|
|
3
|
+
- package-ecosystem: npm
|
|
4
|
+
directory: "/"
|
|
5
|
+
schedule:
|
|
6
|
+
interval: daily
|
|
7
|
+
open-pull-requests-limit: 99
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020 Fabian Klingenberg
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Fabian Klingenberg
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,198 +1,198 @@
|
|
|
1
|
-
# html-bundle
|
|
2
|
-
|
|
3
|
-
<p align="center">
|
|
4
|
-
<img src="./logo.jpg" style="width:500px;" />
|
|
5
|
-
</p>
|
|
6
|
-
|
|
7
|
-
A (primarily) zero-config bundler for HTML files. The idea is to use HTML as Single File Components, because HTML can already include `<style>` and `<script>` elements.
|
|
8
|
-
|
|
9
|
-
## Features
|
|
10
|
-
|
|
11
|
-
- 🦾 TypeScript (reference it as .js or write inline TS)
|
|
12
|
-
- 📦 Automatic Package Installation
|
|
13
|
-
- 💨 HMR and automatic reconnect
|
|
14
|
-
- ⚡ [ESBuild](https://github.com/evanw/esbuild)
|
|
15
|
-
- 🦔 [Critical CSS](https://www.npmjs.com/package/beasties)
|
|
16
|
-
- 🚋 Watcher on PostCSS and Tailwind CSS and TS Config
|
|
17
|
-
- 🛡️ Almost no need to restart
|
|
18
|
-
|
|
19
|
-
## Demo
|
|
20
|
-
|
|
21
|
-

|
|
22
|
-
|
|
23
|
-
## Installation and Usage
|
|
24
|
-
|
|
25
|
-
```properties
|
|
26
|
-
$ npm install -D html-bundle
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
Add an entry to script in package.json (see flags below).
|
|
30
|
-
|
|
31
|
-
```json
|
|
32
|
-
{
|
|
33
|
-
"scripts": {
|
|
34
|
-
"build": "html-bundle"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
Add a `postcss.config.js` file and run the build command.
|
|
40
|
-
<em>If you do not create this config file, a minimal in-memory config file will be created with `cssnano` as plugin.</em>
|
|
41
|
-
|
|
42
|
-
```properties
|
|
43
|
-
$ npm run build
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
## CLI
|
|
47
|
-
|
|
48
|
-
`--hmr`: boots up a static server and enables Hot Module Replacement. **This generates a development build and works best when not triggered from the main index.html**<br>
|
|
49
|
-
`--secure`: creates a secure HTTP2 over HTTPS instance. This requires the files `localhost.pem` and `localhost-key.pem` in the root folder. You can generate them with [mkcert](https://github.com/FiloSottile/mkcert) for instance.<br>
|
|
50
|
-
`--isCritical`: uses critical to extract and inline critical-path CSS to HTML.<br>
|
|
51
|
-
`--handler`: path to your custom handler. Here, you can handle all non-supported files. You can get the filename via `process.argv[2]`.
|
|
52
|
-
|
|
53
|
-
## import
|
|
54
|
-
It is also possible to start the server by importing the package. This could be useful, if you intend to add routes for local development.
|
|
55
|
-
```js
|
|
56
|
-
import router from "html-bundle";
|
|
57
|
-
|
|
58
|
-
router.get("/test", (_req, reply) => {
|
|
59
|
-
return reply.send("hi");
|
|
60
|
-
});
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
## Optional Config
|
|
65
|
-
|
|
66
|
-
_The CLI flags can also be set by the config. Flags set by the CLI will override the config._
|
|
67
|
-
Generate the config in the root and call it "bundle.config.js"
|
|
68
|
-
|
|
69
|
-
**src:** input path. Default to "src"<br>
|
|
70
|
-
**build:** output path. Defaults to "build"<br>
|
|
71
|
-
**port:** For the HMR Server. Defaults to 5000<br>
|
|
72
|
-
**deletePrev:** Whether to delelte the build folder. Defaults to true<br>
|
|
73
|
-
**esbuild:** Your additional config<br>
|
|
74
|
-
**html-minifier-terser:** Your additional config<br>
|
|
75
|
-
**critical:** Your additional config<br>
|
|
76
|
-
|
|
77
|
-
Example:
|
|
78
|
-
|
|
79
|
-
```javascript
|
|
80
|
-
/** @type {import('html-bundle').Config} */
|
|
81
|
-
export default {
|
|
82
|
-
secure: true,
|
|
83
|
-
handler: "utils/staticFiles.js",
|
|
84
|
-
esbuild: {
|
|
85
|
-
external: ["images"],
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
## Concept
|
|
91
|
-
|
|
92
|
-
The bundler always globs all HTML, CSS and TS/JS files from the `src` (config) directory and processes them to the `build` (config) directory. PostCSS is being used for CSS files and inline styles, html-minifier-terser for HTML and esbuild to bundle, minify, etc. for inline and referenced TS/JS. Server-sent events and [hydro-js](https://github.com/Krutsch/hydro-js) are used for HMR. In order to trigger SPA Routers, the popstate event is being triggered after HMR Operations.
|
|
93
|
-
|
|
94
|
-
## Example hydro-js
|
|
95
|
-
|
|
96
|
-
Get the idea from [hydro-starter](https://github.com/Krutsch/hydro-starter).<br>
|
|
97
|
-
Set `"jsxFactory": "h"` in `tsconfig.json` for JSX.
|
|
98
|
-
|
|
99
|
-
### Input
|
|
100
|
-
|
|
101
|
-
```html
|
|
102
|
-
<!DOCTYPE html>
|
|
103
|
-
<html lang="en">
|
|
104
|
-
<head>
|
|
105
|
-
<meta charset="UTF-8" />
|
|
106
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
107
|
-
<title>Example</title>
|
|
108
|
-
<meta name="Description" content="Example for html-bundle" />
|
|
109
|
-
<script type="module">
|
|
110
|
-
import { render, h, reactive } from "hydro-js";
|
|
111
|
-
|
|
112
|
-
function Example({ name }) {
|
|
113
|
-
return <main id="app">Hi {name}</main>;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const name = reactive("Tester");
|
|
117
|
-
render(<Example name={name} />, "#app");
|
|
118
|
-
</script>
|
|
119
|
-
<style>
|
|
120
|
-
body {
|
|
121
|
-
background-color: whitesmoke;
|
|
122
|
-
}
|
|
123
|
-
</style>
|
|
124
|
-
</head>
|
|
125
|
-
<body>
|
|
126
|
-
<main id="app"></main>
|
|
127
|
-
</body>
|
|
128
|
-
</html>
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
## Example Vue.js
|
|
132
|
-
|
|
133
|
-
Set `"jsxFactory": "h"` in `tsconfig.json`.
|
|
134
|
-
|
|
135
|
-
```html
|
|
136
|
-
<!DOCTYPE html>
|
|
137
|
-
<html lang="en">
|
|
138
|
-
<head>
|
|
139
|
-
<meta charset="UTF-8" />
|
|
140
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
141
|
-
<title>Vue Example</title>
|
|
142
|
-
</head>
|
|
143
|
-
<script type="module">
|
|
144
|
-
import { createApp, h } from "vue";
|
|
145
|
-
|
|
146
|
-
const App = {
|
|
147
|
-
data() {
|
|
148
|
-
return {
|
|
149
|
-
name: "Fabian",
|
|
150
|
-
};
|
|
151
|
-
},
|
|
152
|
-
render() {
|
|
153
|
-
return <p>{this.name}</p>;
|
|
154
|
-
},
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
createApp(App).mount("#app");
|
|
158
|
-
</script>
|
|
159
|
-
<body>
|
|
160
|
-
<div id="app"></div>
|
|
161
|
-
</body>
|
|
162
|
-
</html>
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
## Example React
|
|
166
|
-
|
|
167
|
-
Set `"jsxFactory": "React.createElement"` in `tsconfig.json`.
|
|
168
|
-
|
|
169
|
-
```html
|
|
170
|
-
<!DOCTYPE html>
|
|
171
|
-
<html lang="en">
|
|
172
|
-
<head>
|
|
173
|
-
<meta charset="UTF-8" />
|
|
174
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
175
|
-
<title>React Example</title>
|
|
176
|
-
</head>
|
|
177
|
-
<script type="module">
|
|
178
|
-
import React, { useState } from "react";
|
|
179
|
-
import { createRoot } from "react-dom/client";
|
|
180
|
-
|
|
181
|
-
function Example() {
|
|
182
|
-
const [count, setCount] = useState(0);
|
|
183
|
-
|
|
184
|
-
return (
|
|
185
|
-
<div>
|
|
186
|
-
<p>You clicked {count} times</p>
|
|
187
|
-
<button onClick={() => setCount(count + 1)}>Click me</button>
|
|
188
|
-
</div>
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
createRoot(document.getElementById("app")).render(<Example />);
|
|
193
|
-
</script>
|
|
194
|
-
<body>
|
|
195
|
-
<div id="app"></div>
|
|
196
|
-
</body>
|
|
197
|
-
</html>
|
|
198
|
-
```
|
|
1
|
+
# html-bundle
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="./logo.jpg" style="width:500px;" />
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
A (primarily) zero-config bundler for HTML files. The idea is to use HTML as Single File Components, because HTML can already include `<style>` and `<script>` elements.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- 🦾 TypeScript (reference it as .js or write inline TS)
|
|
12
|
+
- 📦 Automatic Package Installation
|
|
13
|
+
- 💨 HMR and automatic reconnect
|
|
14
|
+
- ⚡ [ESBuild](https://github.com/evanw/esbuild)
|
|
15
|
+
- 🦔 [Critical CSS](https://www.npmjs.com/package/beasties)
|
|
16
|
+
- 🚋 Watcher on PostCSS and Tailwind CSS and TS Config
|
|
17
|
+
- 🛡️ Almost no need to restart
|
|
18
|
+
|
|
19
|
+
## Demo
|
|
20
|
+
|
|
21
|
+

|
|
22
|
+
|
|
23
|
+
## Installation and Usage
|
|
24
|
+
|
|
25
|
+
```properties
|
|
26
|
+
$ npm install -D html-bundle
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Add an entry to script in package.json (see flags below).
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "html-bundle"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Add a `postcss.config.js` file and run the build command.
|
|
40
|
+
<em>If you do not create this config file, a minimal in-memory config file will be created with `cssnano` as plugin.</em>
|
|
41
|
+
|
|
42
|
+
```properties
|
|
43
|
+
$ npm run build
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## CLI
|
|
47
|
+
|
|
48
|
+
`--hmr`: boots up a static server and enables Hot Module Replacement. **This generates a development build and works best when not triggered from the main index.html**<br>
|
|
49
|
+
`--secure`: creates a secure HTTP2 over HTTPS instance. This requires the files `localhost.pem` and `localhost-key.pem` in the root folder. You can generate them with [mkcert](https://github.com/FiloSottile/mkcert) for instance.<br>
|
|
50
|
+
`--isCritical`: uses critical to extract and inline critical-path CSS to HTML.<br>
|
|
51
|
+
`--handler`: path to your custom handler. Here, you can handle all non-supported files. You can get the filename via `process.argv[2]`.
|
|
52
|
+
|
|
53
|
+
## import
|
|
54
|
+
It is also possible to start the server by importing the package. This could be useful, if you intend to add routes for local development.
|
|
55
|
+
```js
|
|
56
|
+
import router from "html-bundle";
|
|
57
|
+
|
|
58
|
+
router.get("/test", (_req, reply) => {
|
|
59
|
+
return reply.send("hi");
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
## Optional Config
|
|
65
|
+
|
|
66
|
+
_The CLI flags can also be set by the config. Flags set by the CLI will override the config._
|
|
67
|
+
Generate the config in the root and call it "bundle.config.js"
|
|
68
|
+
|
|
69
|
+
**src:** input path. Default to "src"<br>
|
|
70
|
+
**build:** output path. Defaults to "build"<br>
|
|
71
|
+
**port:** For the HMR Server. Defaults to 5000<br>
|
|
72
|
+
**deletePrev:** Whether to delelte the build folder. Defaults to true<br>
|
|
73
|
+
**esbuild:** Your additional config<br>
|
|
74
|
+
**html-minifier-terser:** Your additional config<br>
|
|
75
|
+
**critical:** Your additional config<br>
|
|
76
|
+
|
|
77
|
+
Example:
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
/** @type {import('html-bundle').Config} */
|
|
81
|
+
export default {
|
|
82
|
+
secure: true,
|
|
83
|
+
handler: "utils/staticFiles.js",
|
|
84
|
+
esbuild: {
|
|
85
|
+
external: ["images"],
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Concept
|
|
91
|
+
|
|
92
|
+
The bundler always globs all HTML, CSS and TS/JS files from the `src` (config) directory and processes them to the `build` (config) directory. PostCSS is being used for CSS files and inline styles, html-minifier-terser for HTML and esbuild to bundle, minify, etc. for inline and referenced TS/JS. Server-sent events and [hydro-js](https://github.com/Krutsch/hydro-js) are used for HMR. In order to trigger SPA Routers, the popstate event is being triggered after HMR Operations.
|
|
93
|
+
|
|
94
|
+
## Example hydro-js
|
|
95
|
+
|
|
96
|
+
Get the idea from [hydro-starter](https://github.com/Krutsch/hydro-starter).<br>
|
|
97
|
+
Set `"jsxFactory": "h"` in `tsconfig.json` for JSX.
|
|
98
|
+
|
|
99
|
+
### Input
|
|
100
|
+
|
|
101
|
+
```html
|
|
102
|
+
<!DOCTYPE html>
|
|
103
|
+
<html lang="en">
|
|
104
|
+
<head>
|
|
105
|
+
<meta charset="UTF-8" />
|
|
106
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
107
|
+
<title>Example</title>
|
|
108
|
+
<meta name="Description" content="Example for html-bundle" />
|
|
109
|
+
<script type="module">
|
|
110
|
+
import { render, h, reactive } from "hydro-js";
|
|
111
|
+
|
|
112
|
+
function Example({ name }) {
|
|
113
|
+
return <main id="app">Hi {name}</main>;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const name = reactive("Tester");
|
|
117
|
+
render(<Example name={name} />, "#app");
|
|
118
|
+
</script>
|
|
119
|
+
<style>
|
|
120
|
+
body {
|
|
121
|
+
background-color: whitesmoke;
|
|
122
|
+
}
|
|
123
|
+
</style>
|
|
124
|
+
</head>
|
|
125
|
+
<body>
|
|
126
|
+
<main id="app"></main>
|
|
127
|
+
</body>
|
|
128
|
+
</html>
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Example Vue.js
|
|
132
|
+
|
|
133
|
+
Set `"jsxFactory": "h"` in `tsconfig.json`.
|
|
134
|
+
|
|
135
|
+
```html
|
|
136
|
+
<!DOCTYPE html>
|
|
137
|
+
<html lang="en">
|
|
138
|
+
<head>
|
|
139
|
+
<meta charset="UTF-8" />
|
|
140
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
141
|
+
<title>Vue Example</title>
|
|
142
|
+
</head>
|
|
143
|
+
<script type="module">
|
|
144
|
+
import { createApp, h } from "vue";
|
|
145
|
+
|
|
146
|
+
const App = {
|
|
147
|
+
data() {
|
|
148
|
+
return {
|
|
149
|
+
name: "Fabian",
|
|
150
|
+
};
|
|
151
|
+
},
|
|
152
|
+
render() {
|
|
153
|
+
return <p>{this.name}</p>;
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
createApp(App).mount("#app");
|
|
158
|
+
</script>
|
|
159
|
+
<body>
|
|
160
|
+
<div id="app"></div>
|
|
161
|
+
</body>
|
|
162
|
+
</html>
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Example React
|
|
166
|
+
|
|
167
|
+
Set `"jsxFactory": "React.createElement"` in `tsconfig.json`.
|
|
168
|
+
|
|
169
|
+
```html
|
|
170
|
+
<!DOCTYPE html>
|
|
171
|
+
<html lang="en">
|
|
172
|
+
<head>
|
|
173
|
+
<meta charset="UTF-8" />
|
|
174
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
175
|
+
<title>React Example</title>
|
|
176
|
+
</head>
|
|
177
|
+
<script type="module">
|
|
178
|
+
import React, { useState } from "react";
|
|
179
|
+
import { createRoot } from "react-dom/client";
|
|
180
|
+
|
|
181
|
+
function Example() {
|
|
182
|
+
const [count, setCount] = useState(0);
|
|
183
|
+
|
|
184
|
+
return (
|
|
185
|
+
<div>
|
|
186
|
+
<p>You clicked {count} times</p>
|
|
187
|
+
<button onClick={() => setCount(count + 1)}>Click me</button>
|
|
188
|
+
</div>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
createRoot(document.getElementById("app")).render(<Example />);
|
|
193
|
+
</script>
|
|
194
|
+
<body>
|
|
195
|
+
<div id="app"></div>
|
|
196
|
+
</body>
|
|
197
|
+
</html>
|
|
198
|
+
```
|