html-bundle 5.5.2 → 6.0.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/README.md CHANGED
@@ -1,8 +1,20 @@
1
1
  # html-bundle
2
2
 
3
- > A very simple zero-config bundler primarily for HTML files. The idea is to use HTML as Single File Components, because HTML can already include `<style>` and `<script>` elements. Additionally, `TypeScript` and `JSX` can be used as inline or referenced script in HTML.
3
+ <p align="center">
4
+ <img src="./logo.jpg" style="width:500px;" />
5
+ </p>
4
6
 
5
- ![Demo](./example.gif)
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://github.com/evanw/esbuild)
16
+ - 🚋 Watcher on PostCSS and Tailwind CSS and TS Config
17
+ - 🛡️ Almost no need to restart
6
18
 
7
19
  ## Installation and Usage
8
20
 
@@ -20,19 +32,7 @@ Add an entry to script in package.json (see flags below).
20
32
  }
21
33
  ```
22
34
 
23
- or ideally
24
-
25
- ```json
26
- {
27
- "scripts": {
28
- "dev": "html-bundle --hmr --secure",
29
- "build": "html-bundle --critical",
30
- "serve": "html-bundle --serveOnly --secure"
31
- }
32
- }
33
- ```
34
-
35
- Add a `postcss.config.cjs` file and run the build command.
35
+ Add a `postcss.config.js` file and run the build command.
36
36
  <em>If you do not create this config file, a minimal in-memory config file will be created with `cssnano` as plugin.</em>
37
37
 
38
38
  ```properties
@@ -41,22 +41,34 @@ $ npm run build
41
41
 
42
42
  ## CLI
43
43
 
44
- `--serveOnly`: boots up a static server for the build folder (fastify)<br>
44
+ `--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>
45
45
  `--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>
46
- `--hmr`: boots up a static server and enables Hot Module Replacement. This works at its best with non-root HTML files without file references.<br>
47
- `--critical`: uses [critical](https://www.npmjs.com/package/critical) to extract and inline critical-path CSS to HTML.<br>
48
- `--csp`: disables inline option from `critical`.
46
+ `--critical`: uses critical to extract and inline critical-path CSS to HTML.<br>
47
+ `--handler`: path to your custom handler. Here, you can handle all non-supported files. You can get the filename via `process.argv[2]`.
48
+
49
+ ## Optional Config
50
+
51
+ _The CLI flags can also be set by the config. Flags set by the CLI will override the config._
52
+ Generate the config in the root and call it "bundle.config.js"
53
+
54
+ **src:** input path. Default to "src"<br>
55
+ **build:** output path. Defaults to "build"<br>
56
+ **port:** For the HMR Server. Defaults to 5000<br>
57
+ **deletePrev:** Whether to delelte the build folder. Defaults to true<br>
58
+ **esbuild:** Your additional config<br>
59
+ **html-minifier-terser:** Your additional config<br>
60
+ **critical:** Your additional config<br>
49
61
 
50
62
  ## Concept
51
63
 
52
- The bundler always globs all HTML, CSS and TS/JS files from the `src/` directory and processes them to the `build/` directory. PostCSS is being used for CSS files and inline styles, html-minifier for HTML and esbuild to bundle, minify, etc. for inline and referenced TS/JS. There are no <strong>regexes</strong>, just <strong>AST</strong> transformations. Server-sent events and [hydro-js](https://github.com/Krutsch/hydro-js) are used for HMR.
64
+ 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. This will install hydro-js to your dependencies. In order to trigger SPA Routers, the popstate event is being triggered after HMR Operations.
53
65
 
54
66
  ## Example hydro-js
55
67
 
56
- Have a look at [hydro-starter](https://github.com/Krutsch/hydro-starter).<br>
68
+ Get the idea from [hydro-starter](https://github.com/Krutsch/hydro-starter).<br>
57
69
  Set `"jsxFactory": "h"` in `tsconfig.json` for JSX.
58
70
 
59
- #### Input
71
+ ### Input
60
72
 
61
73
  ```html
62
74
  <!DOCTYPE html>
@@ -67,13 +79,14 @@ Set `"jsxFactory": "h"` in `tsconfig.json` for JSX.
67
79
  <title>Example</title>
68
80
  <meta name="Description" content="Example for html-bundle" />
69
81
  <script type="module">
70
- import { render, h } from "hydro-js";
82
+ import { render, h, reactive } from "hydro-js";
71
83
 
72
- function Example() {
73
- return <main id="app">Testing html-bundle</main>;
84
+ function Example({ name }) {
85
+ return <main id="app">Hi {name}</main>;
74
86
  }
75
87
 
76
- render(<Example />, "#app");
88
+ const name = reactive("Tester");
89
+ render(<Example name={name} />, "#app");
77
90
  </script>
78
91
  <style>
79
92
  body {
@@ -91,7 +104,7 @@ Set `"jsxFactory": "h"` in `tsconfig.json` for JSX.
91
104
 
92
105
  ![Output](output.JPG)
93
106
 
94
- ## Example Vue.js
107
+ ## Example Vue.js@next
95
108
 
96
109
  Set `"jsxFactory": "h"` in `tsconfig.json`.
97
110
 
@@ -127,7 +140,7 @@ Set `"jsxFactory": "h"` in `tsconfig.json`.
127
140
 
128
141
  ## Example React
129
142
 
130
- Set `"jsxFactory": "React.createElement"` in `tsconfig.json`.
143
+ Set `"jsxFactory": "h"` in `tsconfig.json`.
131
144
 
132
145
  ```html
133
146
  <!DOCTYPE html>
@@ -140,6 +153,7 @@ Set `"jsxFactory": "React.createElement"` in `tsconfig.json`.
140
153
  <script type="module">
141
154
  import React, { useState } from "react";
142
155
  import { render } from "react-dom";
156
+ const h = React.createElement;
143
157
 
144
158
  function Example() {
145
159
  const [count, setCount] = useState(0);
@@ -152,10 +166,14 @@ Set `"jsxFactory": "React.createElement"` in `tsconfig.json`.
152
166
  );
153
167
  }
154
168
 
155
- render(<Example />, document.getElementById("root"));
169
+ render(<Example />, document.getElementById("app"));
156
170
  </script>
157
171
  <body>
158
- <div id="root"></div>
172
+ <div id="app"></div>
159
173
  </body>
160
174
  </html>
161
175
  ```
176
+
177
+ ### Demo
178
+
179
+ ![Demo](./example.gif)