zero-query 0.2.0 → 0.2.3
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 +64 -123
- package/cli.js +186 -114
- package/dist/zquery.dist.zip +0 -0
- package/dist/zquery.js +2605 -0
- package/dist/zquery.min.js +17 -0
- package/index.js +1 -0
- package/package.json +6 -4
- package/src/router.js +24 -1
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ The preferred way to use zQuery is with the **pre-built browser bundle** (`zQuer
|
|
|
36
36
|
|
|
37
37
|
### 1. Get the library
|
|
38
38
|
|
|
39
|
-
Download `dist/zQuery.min.js` from the [GitHub releases](https://github.com/tonywied17/zero-query), or clone and build:
|
|
39
|
+
Download `dist/zQuery.min.js` from the [GitHub releases](https://github.com/tonywied17/zero-query/releases/tag/RELEASE), or clone and build:
|
|
40
40
|
|
|
41
41
|
```bash
|
|
42
42
|
git clone https://github.com/tonywied17/zero-query.git
|
|
@@ -146,147 +146,84 @@ my-app/
|
|
|
146
146
|
|
|
147
147
|
## CLI Bundler (Optional)
|
|
148
148
|
|
|
149
|
-
|
|
149
|
+
zQuery includes a zero-dependency CLI that compiles your entire app — ES modules, the library, external templates, and assets — into a **single bundled file** you can open directly from disk. Useful for offline distribution, `file://` deployments, or reducing HTTP requests.
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
### How It Works
|
|
152
152
|
|
|
153
|
-
-
|
|
154
|
-
- Deploying to environments without a web server (open `index.html` from disk via `file://`)
|
|
155
|
-
- Reducing HTTP requests on legacy hosting without HTTP/2
|
|
153
|
+
The bundler auto-detects your entry point, embeds the zQuery library, resolves all ES module imports, inlines external templates, rewrites your `index.html`, and copies assets into a `dist/` folder. **No flags needed** — just point it at your app.
|
|
156
154
|
|
|
157
155
|
### Installation
|
|
158
156
|
|
|
159
|
-
The CLI is included in the `zero-query` npm package. Install it to get the `zquery` command along with the library source and pre-built bundles:
|
|
160
|
-
|
|
161
157
|
```bash
|
|
162
|
-
# Add to your project as a dev dependency (recommended)
|
|
163
158
|
npm install zero-query --save-dev
|
|
164
|
-
npx zquery bundle
|
|
165
|
-
|
|
166
|
-
# Or install globally
|
|
167
|
-
npm install -g zero-query
|
|
168
|
-
zquery bundle
|
|
169
|
-
|
|
170
|
-
# Or run once without installing (npx fetches it on demand)
|
|
171
|
-
npx zero-query bundle
|
|
172
159
|
```
|
|
173
160
|
|
|
174
|
-
|
|
175
|
-
- `dist/zQuery.min.js` — pre-built browser bundle (ready to copy into your project)
|
|
176
|
-
- `cli.js` — the CLI tool (`zquery build` / `zquery bundle`)
|
|
177
|
-
- `src/` — library source modules
|
|
178
|
-
|
|
179
|
-
### Commands
|
|
180
|
-
|
|
181
|
-
#### `zquery build` — Build the Library
|
|
182
|
-
|
|
183
|
-
Compiles the zQuery library source into `dist/zQuery.js` and `dist/zQuery.min.js`. This is the same as running `node build.js`.
|
|
161
|
+
### Bundling
|
|
184
162
|
|
|
185
163
|
```bash
|
|
186
|
-
|
|
187
|
-
zquery
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
#### `zquery bundle` — Bundle an App
|
|
191
|
-
|
|
192
|
-
Walks the ES module import graph starting from an entry file, topologically sorts all dependencies, strips `import`/`export` syntax, and concatenates everything into a single IIFE with content-hashed filenames for cache-busting.
|
|
193
|
-
|
|
194
|
-
```bash
|
|
195
|
-
# Auto-detect entry from index.html's <script type="module">
|
|
196
|
-
zquery bundle
|
|
197
|
-
|
|
198
|
-
# Specify entry explicitly
|
|
199
|
-
zquery bundle scripts/app.js
|
|
164
|
+
# From inside your project directory (auto-detects entry from index.html)
|
|
165
|
+
npx zquery bundle
|
|
200
166
|
|
|
201
|
-
#
|
|
202
|
-
zquery bundle scripts/app.js
|
|
203
|
-
--out dist/ \
|
|
204
|
-
--include-lib \
|
|
205
|
-
--html index.html \
|
|
206
|
-
--watch
|
|
167
|
+
# Or point to an entry from anywhere
|
|
168
|
+
npx zquery bundle path/to/scripts/app.js
|
|
207
169
|
```
|
|
208
170
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
| Flag | Short | Description |
|
|
212
|
-
| --- | --- | --- |
|
|
213
|
-
| `--out <path>` | `-o` | Output directory (or file path — directory is extracted). Default: `dist/` |
|
|
214
|
-
| `--include-lib` | `-L` | Embed `zquery.min.js` directly in the bundle (no separate script tag needed) |
|
|
215
|
-
| `--html <file>` | — | Rewrite the HTML file: replaces `<script type="module">` with the bundle, copies assets into `dist/`, adjusts `<base href>` |
|
|
216
|
-
| `--watch` | `-w` | Watch source files and rebuild automatically on changes |
|
|
217
|
-
|
|
218
|
-
### What the Bundler Does
|
|
219
|
-
|
|
220
|
-
1. **Import graph walking** — Starting from the entry file, recursively resolves all `import` statements (including side-effect `import './foo.js'`) and produces a topologically sorted dependency list.
|
|
171
|
+
That's it. The output goes to `dist/` next to your `index.html`, with two sub-folders:
|
|
221
172
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
173
|
+
```
|
|
174
|
+
dist/
|
|
175
|
+
server/ ← deploy to your web server
|
|
176
|
+
index.html ← has <base href="/"> for SPA deep routes
|
|
177
|
+
z-app.a1b2c3d4.js ← readable bundle (library + app + templates)
|
|
178
|
+
z-app.a1b2c3d4.min.js ← minified bundle
|
|
179
|
+
styles/ ← copied CSS
|
|
180
|
+
scripts/vendor/ ← copied vendor assets
|
|
181
|
+
local/ ← open from disk (file://)
|
|
182
|
+
index.html ← relative paths, no <base> tag
|
|
183
|
+
z-app.a1b2c3d4.js ← same bundle
|
|
184
|
+
... ← same assets
|
|
185
|
+
```
|
|
227
186
|
|
|
228
|
-
|
|
187
|
+
**`server/`** — includes `<base href="/">` so deep-route refreshes (e.g. `/docs/router`) resolve assets from the site root. Deploy this folder to your web server.
|
|
229
188
|
|
|
230
|
-
|
|
231
|
-
- Replaces `<script type="module" src="...">` with `<script defer src="bundle.js">`
|
|
232
|
-
- Removes the standalone zQuery `<script>` tag when `--include-lib` is used
|
|
233
|
-
- Preserves `<base href="/">` for SPA deep-route support, with an inline `file://` fallback that switches to `./`
|
|
234
|
-
- Copies all referenced assets (CSS, images, vendor JS) into the `dist/` folder
|
|
235
|
-
- Scans CSS files for `url()` references and copies those assets too
|
|
189
|
+
**`local/`** — omits the `<base>` tag so paths resolve relative to the HTML file. Open `local/index.html` directly from disk — no server needed, zero console errors. The router auto-switches to hash mode on `file://`.
|
|
236
190
|
|
|
237
|
-
|
|
191
|
+
### Bundling the Starter App
|
|
238
192
|
|
|
239
|
-
|
|
193
|
+
The zero-query repo includes a starter app you can bundle from the repo root:
|
|
240
194
|
|
|
241
195
|
```bash
|
|
242
|
-
#
|
|
243
|
-
|
|
244
|
-
npm init -y # if you don't have a package.json yet
|
|
245
|
-
npm install zero-query --save-dev
|
|
196
|
+
# npm script (defined in package.json)
|
|
197
|
+
npm run bundle:app
|
|
246
198
|
|
|
247
|
-
#
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
# 3. Bundle the app
|
|
251
|
-
npx zquery bundle scripts/app.js -o dist/ -L --html index.html
|
|
252
|
-
|
|
253
|
-
# Output (filenames are content-hashed for cache-busting):
|
|
254
|
-
# dist/index.html ← rewritten HTML (src updated automatically)
|
|
255
|
-
# dist/z-app.a1b2c3d4.js ← hashed bundle (library + app + inlined templates)
|
|
256
|
-
# dist/z-app.a1b2c3d4.min.js ← minified version
|
|
257
|
-
# dist/styles/ ← copied CSS
|
|
258
|
-
# dist/scripts/vendor/ ← copied vendor assets
|
|
259
|
-
|
|
260
|
-
# 4. Open directly in a browser — no server needed
|
|
261
|
-
start dist/index.html # Windows
|
|
262
|
-
open dist/index.html # macOS
|
|
199
|
+
# or equivalently
|
|
200
|
+
npx zquery bundle examples/starter-app/scripts/app.js
|
|
263
201
|
```
|
|
264
202
|
|
|
265
|
-
|
|
203
|
+
### Optional Flags
|
|
266
204
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
cd examples/starter-app
|
|
273
|
-
npx zquery bundle scripts/app.js -o dist/ -L --html index.html
|
|
274
|
-
start dist/index.html
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
### Hash Routing on `file://`
|
|
205
|
+
| Flag | Short | Description |
|
|
206
|
+
| --- | --- | --- |
|
|
207
|
+
| `--out <path>` | `-o` | Custom output directory (default: `dist/` next to `index.html`) |
|
|
208
|
+
| `--html <file>` | — | Use a specific HTML file instead of the auto-detected one |
|
|
209
|
+
| `--watch` | `-w` | Watch source files and rebuild on changes |
|
|
278
210
|
|
|
279
|
-
|
|
211
|
+
### What Happens Under the Hood
|
|
280
212
|
|
|
281
|
-
|
|
213
|
+
1. **Entry detection** — Reads `index.html` for `<script type="module" src="...">`, or falls back to `scripts/app.js`, `app.js`, etc.
|
|
214
|
+
2. **Import graph** — Recursively resolves all `import` statements and topologically sorts them (leaves first).
|
|
215
|
+
3. **Module syntax stripping** — Removes `import`/`export` keywords, keeps declarations. Output is plain browser JS.
|
|
216
|
+
4. **Library embedding** — Finds `zquery.min.js` in your project or the package. Auto-builds from source if not found.
|
|
217
|
+
5. **Template inlining** — Detects `templateUrl`, `styleUrl`, and `pages` configs and inlines the referenced files so `file://` works without CORS issues.
|
|
218
|
+
6. **HTML rewriting** — Replaces `<script type="module">` with the bundle, removes the standalone library tag, and produces two output directories: `dist/server/` (with `<base href="/">` for web servers) and `dist/local/` (relative paths for `file://`). Assets are copied into both.
|
|
219
|
+
7. **Minification** — Produces hashed filenames (`z-app.<hash>.js` / `.min.js`) for cache-busting. Previous builds are cleaned automatically.
|
|
282
220
|
|
|
283
|
-
|
|
221
|
+
### Tips
|
|
284
222
|
|
|
285
|
-
- **Use relative imports** — `import './components/home.js'` (not bare specifiers
|
|
286
|
-
- **One component per file** —
|
|
287
|
-
- **`import.meta.url`**
|
|
288
|
-
- **
|
|
289
|
-
- **Vendor scripts** — If using `--include-lib`, the bundler finds `zquery.min.js` in `scripts/vendor/`, `vendor/`, `lib/`, or `dist/`
|
|
223
|
+
- **Use relative imports** — `import './components/home.js'` (not bare specifiers)
|
|
224
|
+
- **One component per file** — the import walker resolves each file once
|
|
225
|
+
- **`import.meta.url`** is automatically replaced at bundle time
|
|
226
|
+
- **Hash routing** — on `file://`, the router switches to hash mode automatically
|
|
290
227
|
|
|
291
228
|
---
|
|
292
229
|
|
|
@@ -1303,14 +1240,12 @@ node build.js
|
|
|
1303
1240
|
# → dist/zQuery.js (development)
|
|
1304
1241
|
# → dist/zQuery.min.js (production)
|
|
1305
1242
|
|
|
1306
|
-
# Watch mode (rebuilds on file changes)
|
|
1307
|
-
node build.js --watch
|
|
1308
|
-
|
|
1309
1243
|
# Or use the CLI
|
|
1310
1244
|
npx zquery build
|
|
1311
|
-
npx zquery build --watch
|
|
1312
1245
|
```
|
|
1313
1246
|
|
|
1247
|
+
> **Note:** `npx zquery build` and `node build.js` must be run from the zero-query project root (where `src/` and `index.js` live). If you've added a `build` script to your own `package.json`, `npm run build` handles the working directory for you.
|
|
1248
|
+
|
|
1314
1249
|
The build script is zero-dependency — just Node.js. It concatenates all ES modules into a single IIFE and strips import/export statements. The minified version strips comments and collapses whitespace. For production builds, pipe through Terser for optimal compression.
|
|
1315
1250
|
|
|
1316
1251
|
---
|
|
@@ -1337,10 +1272,13 @@ The starter app includes: Home, Counter (reactive state + z-model), Todos (globa
|
|
|
1337
1272
|
You can also build a fully self-contained bundled version of the starter app:
|
|
1338
1273
|
|
|
1339
1274
|
```bash
|
|
1340
|
-
|
|
1341
|
-
npx zquery bundle scripts/app.js -o dist/ -L --html index.html
|
|
1275
|
+
npm run bundle:app
|
|
1342
1276
|
|
|
1343
|
-
#
|
|
1277
|
+
# Deploy the server build
|
|
1278
|
+
# → dist/server/index.html (with <base href="/"> for web servers)
|
|
1279
|
+
|
|
1280
|
+
# Or open the local build from disk — no server needed
|
|
1281
|
+
start examples/starter-app/dist/local/index.html
|
|
1344
1282
|
```
|
|
1345
1283
|
|
|
1346
1284
|
See [CLI Bundler](#cli-bundler-optional) for details.
|
|
@@ -1350,21 +1288,24 @@ See [CLI Bundler](#cli-bundler-optional) for details.
|
|
|
1350
1288
|
The project ships with a lightweight dev server powered by [zero-http](https://github.com/tonywied17/zero-http). It handles history-mode SPA routing (all non-file requests serve `index.html`).
|
|
1351
1289
|
|
|
1352
1290
|
```bash
|
|
1353
|
-
#
|
|
1291
|
+
# Serve with SPA fallback routing (recommended during development)
|
|
1354
1292
|
npm run serve
|
|
1355
1293
|
|
|
1356
1294
|
# Custom port
|
|
1357
1295
|
node examples/starter-app/local-server.js 8080
|
|
1358
1296
|
|
|
1297
|
+
# Watch mode — auto-rebuild bundle on file changes
|
|
1298
|
+
npm run dev
|
|
1299
|
+
|
|
1359
1300
|
# Or install zero-http yourself for any project
|
|
1360
1301
|
npm install zero-http --save-dev
|
|
1361
1302
|
```
|
|
1362
1303
|
|
|
1363
|
-
|
|
1304
|
+
`npm run serve` gives the fastest feedback loop — edit your ES module source files and refresh the browser. Use `npm run dev` when you need the bundled output to update automatically as you work.
|
|
1364
1305
|
|
|
1365
1306
|
### Production Deployment
|
|
1366
1307
|
|
|
1367
|
-
For
|
|
1308
|
+
For production, use the bundled `dist/server/` output. It includes `<base href="/">` so deep-route refreshes resolve assets correctly. Configure your web server to rewrite non-file requests to `index.html`:
|
|
1368
1309
|
|
|
1369
1310
|
**Apache (.htaccess):**
|
|
1370
1311
|
|