zero-query 0.1.2 → 0.2.2
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 +132 -16
- package/cli.js +833 -0
- 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 +10 -3
- package/src/component.js +12 -0
- package/src/router.js +40 -6
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
</p>
|
|
16
16
|
|
|
17
|
-
> **Lightweight, zero-dependency frontend library that combines jQuery-style DOM manipulation with a modern reactive component system, SPA router, global state management, HTTP client, and utility toolkit — all in a single ~45 KB minified browser bundle.
|
|
17
|
+
> **Lightweight, zero-dependency frontend library that combines jQuery-style DOM manipulation with a modern reactive component system, SPA router, global state management, HTTP client, and utility toolkit — all in a single ~45 KB minified browser bundle. Works out of the box with ES modules — no build step required. An optional CLI bundler is available for single-file distribution.**
|
|
18
18
|
|
|
19
19
|
## Features
|
|
20
20
|
|
|
@@ -30,18 +30,22 @@
|
|
|
30
30
|
|
|
31
31
|
---
|
|
32
32
|
|
|
33
|
-
## Quick Start (Browser Bundle — Recommended)
|
|
33
|
+
## Quick Start (Browser Bundle + ES Modules — Recommended)
|
|
34
34
|
|
|
35
|
-
The preferred way to use zQuery is with the **pre-built browser bundle** (`zQuery.min.js`). No npm install, no bundler, no transpiler.
|
|
35
|
+
The preferred way to use zQuery is with the **pre-built browser bundle** (`zQuery.min.js`) paired with standard **ES module** `<script type="module">` tags for your app code. No npm install, no bundler, no transpiler — just grab the library and start writing components.
|
|
36
36
|
|
|
37
|
-
### 1.
|
|
37
|
+
### 1. Get the library
|
|
38
|
+
|
|
39
|
+
Download `dist/zQuery.min.js` from the [GitHub releases](https://github.com/tonywied17/zero-query/releases/tag/RELEASE), or clone and build:
|
|
38
40
|
|
|
39
41
|
```bash
|
|
42
|
+
git clone https://github.com/tonywied17/zero-query.git
|
|
43
|
+
cd zero-query
|
|
40
44
|
node build.js
|
|
45
|
+
# → dist/zQuery.js (~78 KB, readable)
|
|
46
|
+
# → dist/zQuery.min.js (~45 KB, production)
|
|
41
47
|
```
|
|
42
48
|
|
|
43
|
-
This creates `dist/zQuery.js` and `dist/zQuery.min.js`.
|
|
44
|
-
|
|
45
49
|
### 2. Copy into your project
|
|
46
50
|
|
|
47
51
|
```
|
|
@@ -105,7 +109,9 @@ const router = $.router({
|
|
|
105
109
|
});
|
|
106
110
|
```
|
|
107
111
|
|
|
108
|
-
That's it — a fully working SPA with zero build tools.
|
|
112
|
+
That's it — a fully working SPA with zero build tools. Your files are served as individual ES modules, which means instant browser caching, easy debugging, and native import/export.
|
|
113
|
+
|
|
114
|
+
> **Want a single-file build instead?** See the [CLI Bundler](#cli-bundler-optional) section below for an optional bundling step that compiles your entire app into one file.
|
|
109
115
|
|
|
110
116
|
---
|
|
111
117
|
|
|
@@ -138,6 +144,89 @@ my-app/
|
|
|
138
144
|
|
|
139
145
|
---
|
|
140
146
|
|
|
147
|
+
## CLI Bundler (Optional)
|
|
148
|
+
|
|
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
|
+
|
|
151
|
+
### How It Works
|
|
152
|
+
|
|
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.
|
|
154
|
+
|
|
155
|
+
### Installation
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
npm install zero-query --save-dev
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Bundling
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
# From inside your project directory (auto-detects entry from index.html)
|
|
165
|
+
npx zquery bundle
|
|
166
|
+
|
|
167
|
+
# Or point to an entry from anywhere
|
|
168
|
+
npx zquery bundle path/to/scripts/app.js
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
That's it. The output goes to `dist/` next to your `index.html`, with two sub-folders:
|
|
172
|
+
|
|
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
|
+
```
|
|
186
|
+
|
|
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.
|
|
188
|
+
|
|
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://`.
|
|
190
|
+
|
|
191
|
+
### Bundling the Starter App
|
|
192
|
+
|
|
193
|
+
The zero-query repo includes a starter app you can bundle from the repo root:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
# npm script (defined in package.json)
|
|
197
|
+
npm run bundle:app
|
|
198
|
+
|
|
199
|
+
# or equivalently
|
|
200
|
+
npx zquery bundle examples/starter-app/scripts/app.js
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Optional Flags
|
|
204
|
+
|
|
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 |
|
|
210
|
+
|
|
211
|
+
### What Happens Under the Hood
|
|
212
|
+
|
|
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.
|
|
220
|
+
|
|
221
|
+
### Tips
|
|
222
|
+
|
|
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
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
141
230
|
## Selectors & DOM: `$(selector)` & `$.all(selector)`
|
|
142
231
|
|
|
143
232
|
zQuery provides two selector functions:
|
|
@@ -433,7 +522,7 @@ Components can load their HTML templates and CSS from external files instead of
|
|
|
433
522
|
Relative `templateUrl`, `styleUrl`, and `pages.dir` paths are automatically resolved **relative to the component file** — no extra configuration needed:
|
|
434
523
|
|
|
435
524
|
```js
|
|
436
|
-
// File: scripts/components/widget/
|
|
525
|
+
// File: scripts/components/widget/widget.js
|
|
437
526
|
$.component('my-widget', {
|
|
438
527
|
templateUrl: 'template.html', // → scripts/components/widget/template.html
|
|
439
528
|
styleUrl: 'styles.css', // → scripts/components/widget/styles.css
|
|
@@ -569,7 +658,7 @@ $.style('overrides.css');
|
|
|
569
658
|
The `pages` option is a high-level shorthand for components that display content from multiple HTML files in a directory (e.g. documentation, wizards, tabbed content). It replaces the need to manually build a `templateUrl` object map and maintain a separate page list.
|
|
570
659
|
|
|
571
660
|
```js
|
|
572
|
-
// File: scripts/components/docs/
|
|
661
|
+
// File: scripts/components/docs/docs.js
|
|
573
662
|
$.component('docs-page', {
|
|
574
663
|
pages: {
|
|
575
664
|
dir: 'pages', // → scripts/components/docs/pages/
|
|
@@ -1146,15 +1235,17 @@ mq('.card').addClass('active');
|
|
|
1146
1235
|
## Building from Source
|
|
1147
1236
|
|
|
1148
1237
|
```bash
|
|
1149
|
-
# One-time build
|
|
1238
|
+
# One-time library build
|
|
1150
1239
|
node build.js
|
|
1151
1240
|
# → dist/zQuery.js (development)
|
|
1152
1241
|
# → dist/zQuery.min.js (production)
|
|
1153
1242
|
|
|
1154
|
-
#
|
|
1155
|
-
|
|
1243
|
+
# Or use the CLI
|
|
1244
|
+
npx zquery build
|
|
1156
1245
|
```
|
|
1157
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
|
+
|
|
1158
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.
|
|
1159
1250
|
|
|
1160
1251
|
---
|
|
@@ -1163,7 +1254,7 @@ The build script is zero-dependency — just Node.js. It concatenates all ES mod
|
|
|
1163
1254
|
|
|
1164
1255
|
```bash
|
|
1165
1256
|
# From the project root
|
|
1166
|
-
node build.js # build the
|
|
1257
|
+
node build.js # build the library
|
|
1167
1258
|
cp dist/zQuery.min.js examples/starter-app/scripts/vendor/ # copy to app
|
|
1168
1259
|
|
|
1169
1260
|
# Start the dev server (uses zero-http)
|
|
@@ -1176,26 +1267,45 @@ npx serve examples/starter-app
|
|
|
1176
1267
|
|
|
1177
1268
|
The starter app includes: Home, Counter (reactive state + z-model), Todos (global store + subscriptions), API Docs (full reference), and About pages.
|
|
1178
1269
|
|
|
1270
|
+
#### Bundled Version (Single-File)
|
|
1271
|
+
|
|
1272
|
+
You can also build a fully self-contained bundled version of the starter app:
|
|
1273
|
+
|
|
1274
|
+
```bash
|
|
1275
|
+
npm run bundle:app
|
|
1276
|
+
|
|
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
|
|
1282
|
+
```
|
|
1283
|
+
|
|
1284
|
+
See [CLI Bundler](#cli-bundler-optional) for details.
|
|
1285
|
+
|
|
1179
1286
|
### Local Dev Server
|
|
1180
1287
|
|
|
1181
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`).
|
|
1182
1289
|
|
|
1183
1290
|
```bash
|
|
1184
|
-
#
|
|
1291
|
+
# Serve with SPA fallback routing (recommended during development)
|
|
1185
1292
|
npm run serve
|
|
1186
1293
|
|
|
1187
1294
|
# Custom port
|
|
1188
1295
|
node examples/starter-app/local-server.js 8080
|
|
1189
1296
|
|
|
1297
|
+
# Watch mode — auto-rebuild bundle on file changes
|
|
1298
|
+
npm run dev
|
|
1299
|
+
|
|
1190
1300
|
# Or install zero-http yourself for any project
|
|
1191
1301
|
npm install zero-http --save-dev
|
|
1192
1302
|
```
|
|
1193
1303
|
|
|
1194
|
-
|
|
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.
|
|
1195
1305
|
|
|
1196
1306
|
### Production Deployment
|
|
1197
1307
|
|
|
1198
|
-
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`:
|
|
1199
1309
|
|
|
1200
1310
|
**Apache (.htaccess):**
|
|
1201
1311
|
|
|
@@ -1262,6 +1372,12 @@ location /my-app/ {
|
|
|
1262
1372
|
| `$.version` | Library version |
|
|
1263
1373
|
| `$.noConflict` | Release `$` global |
|
|
1264
1374
|
|
|
1375
|
+
| CLI | Description |
|
|
1376
|
+
| --- | --- |
|
|
1377
|
+
| `zquery build` | Build the zQuery library (`dist/zQuery.min.js`) |
|
|
1378
|
+
| `zquery bundle [entry]` | Bundle app ES modules into a single IIFE file |
|
|
1379
|
+
| `zquery --help` | Show CLI usage and options |
|
|
1380
|
+
|
|
1265
1381
|
For full method signatures and options, see [API.md](API.md).
|
|
1266
1382
|
|
|
1267
1383
|
---
|