@asd14/vblocks 2.1.0 → 4.0.0

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
@@ -3,106 +3,277 @@
3
3
 
4
4
  # @asd14/vblocks
5
5
 
6
- > 📜 POSIX + 📦 Webpack, an unlikely story!
6
+ > Zero-config React builds, as a static site or a single HTML file
7
7
 
8
- - **Minimal configs** - Needs only `src/index.tsx` and `src/index.html`
9
- - **Built in** - SWC, PostCSS (CSS Modules configured), MDX, React Refresh,
10
- Dotenv, bundle analyzer
8
+ **✂️ Zero config**
9
+ Needs only `src/index.tsx` and `src/index.html`
10
+
11
+ <!--
12
+ Using "Maximal support" to answer "Zero config" above: nothing to set up, and
13
+ everything set up.
14
+ -->
15
+
16
+ **🔋 Maximal support**
17
+ SWC, PostCSS (CSS Modules configured), MDX, React Refresh, Dotenv
18
+
19
+ <!--
20
+ PARKED until SSG is finished, then name both outputs: SPA and SSG.
21
+
22
+ **📄 Static website**
23
+ Builds to `dist/`, for any static host
24
+ -->
25
+
26
+ **📦 Several apps, one install**
27
+ Apps share one `package.json` and `node_modules/`, a new app reuses the
28
+ installed packages
29
+
30
+ **🤖 Optimized for AI agents**
31
+ No config to write, so an agent spends its tokens on the content, not on the
32
+ setup
33
+
34
+ > [!IMPORTANT]
35
+ > VBlocks needs Node `^22.22.3`, `^24.15.0` or `>=26.0`.
11
36
 
12
37
  ## Table of contents
13
38
 
14
39
  <!-- vim-markdown-toc GFM -->
15
40
 
16
- - [Installation](#installation)
17
- - [Peer Dependencies](#peer-dependencies)
18
41
  - [Quick Start](#quick-start)
19
- - [Configuration](#configuration)
42
+ - [Several apps in one project](#several-apps-in-one-project)
43
+ - [Vocabulary](#vocabulary)
44
+ - [How to](#how-to)
45
+ - [Use environment variables](#use-environment-variables)
46
+ - [Stop using `../../../` everywhere](#stop-using--everywhere)
47
+ - [Use CSS Modules](#use-css-modules)
48
+ - [Replace a default config](#replace-a-default-config)
49
+ - [Style with Tailwind](#style-with-tailwind)
50
+ - [Add VBlocks to an existing project](#add-vblocks-to-an-existing-project)
20
51
  - [Commands](#commands)
21
52
  - [`vblocks init`](#vblocks-init)
22
53
  - [`vblocks serve`](#vblocks-serve)
23
54
  - [`vblocks build`](#vblocks-build)
24
55
  - [`vblocks eject`](#vblocks-eject)
25
- - [Features in Detail](#features-in-detail)
26
- - [TypeScript](#typescript)
27
- - [PostCSS](#postcss)
28
- - [CSS Modules Support](#css-modules-support)
29
- - [Asset Handling](#asset-handling)
30
- - [Environment Variables](#environment-variables)
31
- - [Path Alias](#path-alias)
32
- - [How It Works](#how-it-works)
33
- - [FAQ](#faq)
34
- - [Does VBlocks support Tailwind?](#does-vblocks-support-tailwind)
35
56
  - [License](#license)
36
57
 
37
58
  <!-- vim-markdown-toc -->
38
59
 
39
- ## Installation
60
+ <!--
61
+ Order this README by three principles. Each settles one decision:
40
62
 
41
- ```sh
42
- npm install --save-dev @asd14/vblocks
43
- ```
63
+ - **Pain relief**, the order of sections. The section that relieves the most
64
+ pain for the least reading comes first
65
+ - **Progressive disclosure**, the depth of a section. A section uses only what
66
+ the sections above it showed
67
+ - **Colocation**, the place of a fact. A caveat sits on the step or option it
68
+ limits, in a NOTE when it is tangential or points at another section
44
69
 
45
- > [!IMPORTANT]
46
- > VBlocks needs Node `^22.22.3`, `^24.15.0` or `>=26.0`.
70
+ Each section is one Diátaxis type (https://diataxis.fr): Quick Start is a
71
+ tutorial, How to is how-to guides, Vocabulary and Commands are reference.
72
+ -->
47
73
 
48
- ### Peer Dependencies
74
+ ## Quick Start
49
75
 
50
- ```sh
51
- npm install react react-dom
52
- ```
76
+ <!--
77
+ Diátaxis: tutorial. The fewest steps to a working build. It shows enough of
78
+ VBlocks for the reader to decide whether VBlocks fits their project.
79
+ -->
80
+
81
+ <!--
82
+ Using "scaffold", the field's word for what `init` does, eg. Yeoman and
83
+ create-vite use it.
84
+ -->
85
+
86
+ 1. **Scaffold a minimal React project**
87
+
88
+ ```sh
89
+ npx @asd14/vblocks init my-vblocks-app
90
+ cd my-vblocks-app
91
+ npm install
92
+ ```
53
93
 
54
- > [!IMPORTANT]
55
- > VBlocks needs React `^18` or `^19`.
94
+ ```text
95
+ my-vblocks-app/
96
+ ├─ src/
97
+ │ ├─ index.tsx
98
+ │ ├─ index.html
99
+ │ └─ index.css
100
+ ├─ .gitignore
101
+ ├─ tsconfig.json
102
+ └─ package.json # react, react-dom and the vblocks scripts
103
+ ```
104
+
105
+ 2. **Start a development server**
56
106
 
57
- ## Quick Start
107
+ ```sh
108
+ npx vblocks serve
109
+ ```
58
110
 
59
- Create a project and start the dev server:
111
+ 3. **Build**
60
112
 
61
- ```sh
62
- npx @asd14/vblocks init my-vblocks-app
63
- cd my-vblocks-app
64
- npm install
65
- npm start
66
- ```
113
+ ```sh
114
+ npx vblocks build # production bundle in dist/
115
+ npx vblocks build --single-file # one dist/index.html, every asset inlined
116
+ ```
67
117
 
68
- ```text
69
- my-vblocks-app/
70
- ├── src/
71
- │ ├── index.tsx # Application entry point
72
- │ ├── index.html # HTML template
73
- │ └── index.css # Global CSS
74
- ├── .gitignore # Minimal set
75
- ├── tsconfig.json # TypeScript config for React
76
- └── package.json # Scripts and dependencies (react, react-dom)
77
- ```
118
+ ### Several apps in one project
78
119
 
79
- Run a command in a project that has VBlocks installed:
120
+ Several apps, eg. demos or MVP sketches, can share one `package.json` and one
121
+ `node_modules/`:
80
122
 
81
- ```sh
82
- # Start the dev server
83
- npx vblocks serve
123
+ 1. **Add the plumbing**
84
124
 
85
- # Build for production
86
- npx vblocks build
125
+ ```sh
126
+ npx @asd14/vblocks init sketches --only plumbing
127
+ ```
87
128
 
88
- # Save the default Webpack config in your project root
89
- npx vblocks eject webpack > webpack.config.js
129
+ ```text
130
+ sketches/
131
+ ├─ .gitignore
132
+ └─ package.json
133
+ ```
134
+
135
+ 2. **Add an app**
136
+
137
+ ```sh
138
+ npx @asd14/vblocks init sketches/flow-diagram --template xyflow --only app
139
+ cd sketches
140
+ npm install
141
+ ```
142
+
143
+ ```diff
144
+ sketches/
145
+ + ├─ flow-diagram/
146
+ + │ ├─ src/
147
+ + │ │ ├─ index.tsx
148
+ + │ │ ├─ index.html
149
+ + │ │ └─ index.css
150
+ + │ ├─ postcss.config.js
151
+ + │ └─ tsconfig.json
152
+ ├─ .gitignore
153
+ ! └─ package.json # + @xyflow/react, tailwindcss, @tailwindcss/postcss
154
+ ```
155
+
156
+ 3. **Start a development server for one app**
157
+
158
+ ```sh
159
+ npx vblocks serve --prefix flow-diagram
160
+ ```
161
+
162
+ ## Vocabulary
163
+
164
+ <!--
165
+ Vocabulary follows Quick Start. The reader sees the terms used, then reads
166
+ their definitions. How to is the first section that assumes the reader knows
167
+ them.
168
+ -->
169
+
170
+ | Term | Means |
171
+ | :----------------- | :------------------------------------------------------------ |
172
+ | **Project folder** | The folder with `package.json` |
173
+ | **App folder** | The folder with `src/index.tsx` and `src/index.html` |
174
+ | **Plumbing** | The project files `init` writes: `package.json`, `.gitignore` |
175
+
176
+ ## How to
177
+
178
+ <!--
179
+ Diátaxis: how-to. Each ### names a pain as the task that relieves it. Order
180
+ the guides by how early the Quick Start reader has the pain. A guide for
181
+ another reader, eg. one with an existing app, goes last.
182
+ -->
183
+
184
+ ### Use environment variables
185
+
186
+ 1. **Add a `.env` file to your app folder**
187
+
188
+ ```env
189
+ API_URL=https://api.example.com
190
+ ```
191
+
192
+ 2. **Read the variable in your code**
193
+
194
+ ```tsx
195
+ const apiUrl = process.env["API_URL"]
196
+ ```
197
+
198
+ Webpack replaces each `process.env["NAME"]` with the value of `NAME`, and
199
+ `undefined` when `.env` does not set it. The build leaves out every variable
200
+ your code does not read.
201
+
202
+ > [!WARNING]
203
+ > Never expose a secret, eg. an API key, through `process.env`. Anyone who loads
204
+ > the page can read it.
205
+
206
+ > [!NOTE]
207
+ > The [client types](src/types/client.d.ts) declare `process.env` and nothing
208
+ > else from Node, because Webpack replaces nothing else. With the client types,
209
+ > `tsc` fails on `process.cwd()` and `Buffer`.
210
+
211
+ ### Stop using `../../../` everywhere
212
+
213
+ VBlocks resolves `@self` to the `src/` of your app folder:
214
+
215
+ ```tsx
216
+ // Instead of: import { Component } from "../../../components"
217
+ import { Component } from "@self/components"
90
218
  ```
91
219
 
92
- ## Configuration
220
+ > [!NOTE]
221
+ > VBlocks never reads your `tsconfig.json`, so `tsc` needs the alias too. The
222
+ > one scaffolded by [`vblocks init`](#vblocks-init) already has it. Otherwise,
223
+ > add:
224
+ >
225
+ > ```json
226
+ > {
227
+ > "compilerOptions": {
228
+ > "paths": { "@self/*": ["./src/*"] }
229
+ > }
230
+ > }
231
+ > ```
232
+
233
+ ### Use CSS Modules
234
+
235
+ 1. **Name the file `*.module.css`**
236
+
237
+ ```css
238
+ /* src/button.module.css */
239
+ .primary-button {
240
+ color: tomato;
241
+ }
242
+ ```
243
+
244
+ 2. **Import it as an object**
245
+
246
+ ```tsx
247
+ /* src/button.tsx */
248
+ import styles from "./button.module.css"
93
249
 
94
- A config in your project root replaces the default of the same name.
250
+ export const Button = () => <button className={styles.primaryButton} />
251
+ ```
252
+
253
+ - **camelCase exports** - `.primary-button` becomes `styles.primaryButton`
254
+ - **Class names** - a bare hash in `production` mode, `[local]__[hash]` in
255
+ `development` mode
256
+ - **Global CSS** - a file without `.module` stays global,
257
+ `import "./styles.css"`
258
+
259
+ > [!NOTE]
260
+ > The [client types](src/types/client.d.ts) declare `.css` imports.
261
+
262
+ ### Replace a default config
263
+
264
+ Each of these configs in your app folder replaces the default of the same name:
95
265
 
96
266
  - `webpack.config.js`
97
267
  - `postcss.config.js`
98
268
  - `.swcrc`
99
269
 
100
- To replace a default, first [`eject`](#vblocks-eject) it into your project root,
101
- then edit the file:
270
+ 1. **[Eject](#vblocks-eject) the default into your app folder**
102
271
 
103
- ```sh
104
- npx vblocks eject postcss > postcss.config.js
105
- ```
272
+ ```sh
273
+ npx vblocks eject postcss > flow-diagram/postcss.config.js
274
+ ```
275
+
276
+ 2. **Update the ejected file**
106
277
 
107
278
  > [!NOTE]
108
279
  > VBlocks does not merge your config with the default, with two exceptions:
@@ -111,18 +282,119 @@ npx vblocks eject postcss > postcss.config.js
111
282
  > - `.swcrc -> jsc.transform.react.refresh`: VBlocks adds the React Refresh
112
283
  > transform when `serve` runs in `development` mode
113
284
 
285
+ ### Style with Tailwind
286
+
287
+ VBlocks does not include Tailwind. Add it through a `postcss.config.js` in your
288
+ app folder:
289
+
290
+ > [!NOTE]
291
+ > The `xyflow` template of [`vblocks init`](#vblocks-init) has this setup.
292
+
293
+ 1. **Install Tailwind and the Tailwind plugin for PostCSS**
294
+
295
+ ```sh
296
+ npm install --save-dev tailwindcss @tailwindcss/postcss
297
+ ```
298
+
299
+ 2. **Eject the default PostCSS config into your app folder**
300
+
301
+ ```sh
302
+ npx vblocks eject postcss > postcss.config.js
303
+ ```
304
+
305
+ 3. **Replace `postcss-preset-env` with the Tailwind plugin**
306
+
307
+ ```diff
308
+ export default ({ mode }) => ({
309
+ plugins: {
310
+ - "postcss-preset-env": {
311
+ - stage: 2,
312
+ - },
313
+ + "@tailwindcss/postcss": {
314
+ + optimize: mode === "production",
315
+ + },
316
+ "cssnano": mode === "production" && {
317
+ preset: "default",
318
+ },
319
+ },
320
+ })
321
+ ```
322
+
323
+ > [!IMPORTANT]
324
+ > Tailwind 4
325
+ > [compiles nesting and adds vendor prefixes](https://tailwindcss.com/docs/compatibility)
326
+ > itself. With both plugins, `postcss-preset-env` rewrites Tailwind's `@layer`
327
+ > rules into `:not(#\#)` selectors. The CSS file grows.
328
+
329
+ 4. **Add the Tailwind import to `src/index.css`**
330
+
331
+ ```css
332
+ @import "tailwindcss" source(".");
333
+ ```
334
+
335
+ `source(".")` limits Tailwind's class scan to the folder of the CSS file,
336
+ `src/`.
337
+
338
+ > [!NOTE]
339
+ > Without `source(".")`, Tailwind scans the current folder. With
340
+ > [`--prefix`](#vblocks-build), you run VBlocks from the project folder, which
341
+ > holds every app. Each app's CSS then also gets the classes of the other apps.
342
+
343
+ ### Add VBlocks to an existing project
344
+
345
+ 1. **Install VBlocks**
346
+
347
+ ```sh
348
+ npm install --save-dev @asd14/vblocks # needs react and react-dom ^18 or ^19
349
+ ```
350
+
351
+ 2. **Ensure `index.tsx` and `index.html` are in `src/`**
352
+
353
+ > [!NOTE]
354
+ > VBlocks builds `dist/index.html` from `src/index.html` and adds the script and
355
+ > stylesheet tags to it. Drop the tag that loads your entry, eg. Vite's
356
+ > `<script type="module" src="/src/main.tsx"></script>`.
357
+
358
+ 3. **Start a development server**
359
+
360
+ ```sh
361
+ npx vblocks serve
362
+ ```
363
+
114
364
  ## Commands
115
365
 
366
+ <!--
367
+ Diátaxis: reference. Mirror SYNOPSIS and OPTIONS of `vblocks --help`, in the
368
+ same words. Each option and operand is a term, a line break, then its
369
+ description, like OPTIONS in a man page.
370
+ -->
371
+
116
372
  ### `vblocks init`
117
373
 
118
- Creates a project in `<directory>` from a template.
374
+ Write a template's plumbing, app, or both into `<directory>`.
119
375
 
120
376
  ```text
121
- vblocks init <directory> [--template <plain|xyflow>]
377
+ vblocks init <directory> [--template <name>] [--only <app|plumbing>]
122
378
  ```
123
379
 
380
+ - `<directory>`\
381
+ The folder to write into. It must be missing or empty
382
+ - `--template <name>`\
383
+ `plain`, or `xyflow` with React Flow and Tailwind (default: `plain`)
384
+ - `--only <app|plumbing>`\
385
+ Write one part of the template (default: both)
386
+ - `plumbing`: `package.json`, `.gitignore`
387
+ - `app`: `src/`, `tsconfig.json` and the template's configs. `init` adds the
388
+ template's dependencies to the nearest `package.json` above `<directory>`.
389
+ Without one, `init` fails
390
+
124
391
  **Example**:
125
392
 
393
+ <!--
394
+ Using the `my-vblock-` prefix, so a reader who tries several scaffolders spots
395
+ the folder at a glance, as with `vite-project` and `nuxt-app`.
396
+ -->
397
+
126
398
  ```sh
127
399
  npx @asd14/vblocks init my-vblock-flow --template xyflow
128
400
  cd my-vblock-flow
@@ -131,75 +403,92 @@ npm install
131
403
 
132
404
  ### `vblocks serve`
133
405
 
134
- Starts a React Refresh enabled development server.
406
+ Start the development server.
135
407
 
136
- - Runs at `http://localhost:8080`, auto-opens in browser
137
- - Runs bundle analyzer at `http://127.0.0.1:8888`
408
+ - Runs at `http://localhost:8080`, or the next free port
409
+ - Opens the page in the browser
138
410
 
139
411
  ```text
140
- vblocks serve [--mode <development|production>] [<webpack option>...]
412
+ vblocks serve [--mode <mode>] [--prefix <directory>] [--analyze] [<webpack option>...]
141
413
  ```
142
414
 
415
+ - `--mode <mode>`\
416
+ The Webpack mode, `development` or `production` (default: `development`).
417
+ React Refresh runs only in `development`
418
+ - `--prefix <directory>`\
419
+ The [app folder](#vocabulary), which must exist (default: the current folder)
420
+ - `--analyze`\
421
+ Run the bundle analyzer, on a free port
422
+ - `<webpack option>`\
423
+ Any other [`webpack serve`](https://webpack.js.org/api/cli/) option. VBlocks
424
+ passes it to Webpack unchanged
425
+
143
426
  **Example**:
144
427
 
145
428
  ```sh
146
429
  cd my-vblock-flow
147
- vblocks serve
148
- # ↓
430
+ npx vblocks serve
431
+ # ↓↓↓
149
432
  # npx webpack serve --config <webpack config> \
150
- # --env entryDir=<project root> \
151
- # --mode development
433
+ # --env entryDir=<app folder> \
434
+ # --mode development \
435
+ # ...
152
436
  ```
153
437
 
154
438
  ### `vblocks build`
155
439
 
156
- ```text
157
- vblocks build [--mode <mode>] [--env single] [<webpack option>...]
158
- ```
159
-
160
- Builds the project into `dist/`.
161
-
162
- | Parameter | Required | Default | Description |
163
- | ------------------ | -------- | ------------ | -------------------------------------------------------------------------------------------------------------------------------------- |
164
- | `--mode <mode>` | no | `production` | The Webpack mode, `development` or `production`. The build minifies JS, CSS and HTML only in `production` |
165
- | `--env single` | no | off | Build one standalone `dist/index.html` |
166
- | `<webpack option>` | no | none | Any other [`webpack build`](https://webpack.js.org/api/cli/) option, eg. `--stats errors-only`. VBlocks passes it to Webpack unchanged |
167
-
168
- Without `--env single`, the build:
440
+ Build the app into `dist/` in the app folder. Without `--single-file`, the
441
+ build:
169
442
 
170
443
  - Writes JS and CSS files with content-hashed names
171
444
  - Writes a `react` chunk, and a `vendors` chunk when your other dependencies
172
- total over 20 KB
445
+ total over 20 KB (10 KB in `development`)
173
446
 
174
- With `--env single`:
447
+ ```text
448
+ vblocks build [--mode <mode>] [--prefix <directory>] [--single-file] [<webpack option>...]
449
+ ```
175
450
 
176
- - `dist/index.html` holds every script, stylesheet, image, font and the favicon
177
- - A browser opens the file from disk, with no server and no network
178
- - Keep the route in the URL hash. On `file://`, `history.pushState` to another
179
- path throws
451
+ - `--mode <mode>`\
452
+ The Webpack mode, `development` or `production` (default: `production`). In
453
+ `production`, the build minifies JS and HTML, and cssnano, in the default
454
+ PostCSS config, minifies CSS
455
+ - `--prefix <directory>`\
456
+ The [app folder](#vocabulary), which must exist (default: the current folder)
457
+ - `--single-file`\
458
+ The build writes one standalone `dist/index.html`, every asset inlined
459
+ - A browser opens the file from disk, with no server and no network
460
+ - The build leaves `robots.txt` out
461
+ - Keep the route in the URL hash. On `file://`, `history.pushState` to another
462
+ path throws
463
+ - `<webpack option>`\
464
+ Any other [`webpack build`](https://webpack.js.org/api/cli/) option, eg.
465
+ `--stats errors-only`. VBlocks passes it to Webpack unchanged
180
466
 
181
- **Runs**:
467
+ **Example**:
182
468
 
183
469
  ```sh
184
- npx webpack build --config <webpack config> \
185
- --env entryDir=<project root> \
186
- --mode production \
187
- [...your arguments]
470
+ cd my-vblock-flow
471
+ npx vblocks build
472
+ # ↓↓↓
473
+ # npx webpack build --config <webpack config> \
474
+ # --env entryDir=<app folder> \
475
+ # --mode production \
476
+ # ...
188
477
  ```
189
478
 
190
479
  ### `vblocks eject`
191
480
 
481
+ Print a default config to stdout.
482
+
192
483
  ```text
193
- vblocks eject <config>
484
+ vblocks eject <webpack|postcss|swc>
194
485
  ```
195
486
 
196
- Prints a default config to stdout.
487
+ - `<webpack|postcss|swc>`\
488
+ The config to print
197
489
 
198
- | Parameter | Required | Default | Description |
199
- | ---------- | -------- | ------- | -------------------------------------------------- |
200
- | `<config>` | yes | none | The config to print: `webpack`, `postcss` or `swc` |
201
-
202
- Save the output in your project root to [replace the default](#configuration):
490
+ Save the output in your app folder to
491
+ [replace the default](#replace-a-default-config):
203
492
 
204
493
  ```sh
205
494
  npx vblocks eject webpack > webpack.config.js
@@ -207,173 +496,76 @@ npx vblocks eject postcss > postcss.config.js
207
496
  npx vblocks eject swc > .swcrc
208
497
  ```
209
498
 
210
- ## Features in Detail
499
+ <!--
500
+ PARKED: sort each fact below into an existing section or a new one, or drop
501
+ it. The client types and the PostCSS default have no home yet.
211
502
 
212
- ### TypeScript
503
+ ## Details
213
504
 
214
- VBlocks does not check types and never reads your `tsconfig.json`. It only
215
- compiles TypeScript with SWC.
505
+ ### TypeScript
216
506
 
217
- For convenience, VBlocks provides client types in
218
- [`client.d.ts`](src/types/client.d.ts) for:
507
+ VBlocks does not check types and never reads your `tsconfig.json`. It only
508
+ compiles TypeScript with SWC.
219
509
 
220
- - `.css` imports
221
- - Image and font imports
222
- - `process.env`
510
+ For convenience, VBlocks provides client types in
511
+ [`client.d.ts`](src/types/client.d.ts) for:
223
512
 
224
- You can use them in your `tsconfig.json`:
513
+ - `.css` imports
514
+ - Image and font imports
515
+ - `process.env`
225
516
 
226
- ```json
227
- {
228
- "compilerOptions": {
229
- "types": ["@asd14/vblocks/client"]
230
- }
231
- }
232
- ```
517
+ You can use them in your `tsconfig.json`:
233
518
 
234
- `tsc` needs the [`@self`](#path-alias) path alias in your `tsconfig.json`:
519
+ ```json
520
+ {
521
+ "compilerOptions": {
522
+ "types": ["@asd14/vblocks/client"]
523
+ }
524
+ }
525
+ ```
235
526
 
236
- ```diff
237
- {
238
- "compilerOptions": {
239
- "types": ["@asd14/vblocks/client"],
240
- + "paths": { "@self/*": ["./src/*"] }
241
- }
242
- }
243
- ```
527
+ > [!NOTE]
528
+ > The `tsconfig.json` that [`vblocks init`](#vblocks-init) writes has the client
529
+ > types and the [`@self`](#stop-using--everywhere) alias.
244
530
 
245
- The `tsconfig.json` that [`vblocks init`](#vblocks-init) writes has both.
246
-
247
- ### PostCSS
248
-
249
- The default `postcss.config.js`:
250
-
251
- ```js
252
- /**
253
- * @param {{ mode: "production" | "development" | "none" }} api
254
- */
255
- export default ({ mode }) => ({
256
- plugins: {
257
- "postcss-preset-env": {
258
- stage: 2,
259
- },
260
- "cssnano": mode === "production" && {
261
- preset: "default",
262
- },
263
- },
264
- })
265
- ```
531
+ ### PostCSS
266
532
 
267
- `postcss-preset-env` compiles nesting, `oklch()` and `color-mix()` for older
268
- browsers and adds vendor prefixes.
533
+ The default `postcss.config.js`:
269
534
 
270
- ### CSS Modules Support
535
+ ```js
536
+ /**
537
+ * @param {{ mode: "production" | "development" | "none" }} api
538
+ */
539
+ export default ({ mode }) => ({
540
+ plugins: {
541
+ "postcss-preset-env": {
542
+ stage: 2,
543
+ },
544
+ "cssnano": mode === "production" && {
545
+ preset: "default",
546
+ },
547
+ },
548
+ })
549
+ ```
271
550
 
272
- - **Global CSS** - `import "./styles.css"`
273
- - **Local CSS Modules** - `import styles from "./component.module.css"`
274
- - **camelCase exports** - `.my-class` becomes `styles.myClass`
275
- - **Class names** - a bare hash in `production` mode, `[local]__[hash]` in
276
- `development` mode
277
- - **TypeScript** - the [client types](#typescript) declare `.css` imports
278
-
279
- ### Asset Handling
551
+ > [!NOTE]
552
+ > `postcss-preset-env` compiles nesting, `oklch()` and `color-mix()` for older
553
+ > browsers and adds vendor prefixes.
280
554
 
281
- - **Images** - the build inlines `jpg`, `gif`, `png` and `svg` files up to 10 KB
282
- - **Fonts** - the build writes `woff`, `woff2`, `ttf` and `eot` files to
283
- `dist/fonts/`
284
- - **Favicon and `robots.txt`** - yours or the default. `--env single` leaves
285
- `robots.txt` out
555
+ ### Asset Handling
286
556
 
287
- ### Environment Variables
557
+ - **Images** - the build inlines `jpg`, `gif`, `png` and `svg` files up to 10 KB
558
+ - **Fonts** - the build writes `woff`, `woff2`, `ttf` and `eot` files to
559
+ `dist/fonts/`
560
+ - **Favicon and `robots.txt`** - yours or the default. With `--single-file`, the
561
+ build inlines the favicon and leaves `robots.txt` out
288
562
 
289
- VBlocks loads the `.env` file in your project root:
290
-
291
- ```env
292
- API_URL=https://api.example.com
293
- ```
294
-
295
- Read a variable in your code:
296
-
297
- ```tsx
298
- const apiUrl = process.env["API_URL"]
299
- ```
300
-
301
- Webpack replaces each `process.env` read with the variable's value. A variable
302
- that `.env` does not set reads as `undefined`. The build leaves out every
303
- variable your code does not read.
304
-
305
- The [client types](#typescript) declare `process.env` and nothing else from
306
- Node, because Webpack replaces nothing else. With the client types, `tsc` fails
307
- on `process.cwd()` and `Buffer`.
308
-
309
- ### Path Alias
310
-
311
- `@self` points at your `src/` directory:
312
-
313
- ```tsx
314
- // Instead of: import { Component } from "../../../components"
315
- import { Component } from "@self/components"
316
- ```
317
-
318
- `tsc` needs the same alias in your `tsconfig.json`. See
319
- [TypeScript](#typescript).
320
-
321
- ## How It Works
322
-
323
- VBlocks is a POSIX shell script that runs Webpack. The script exports
324
- `VB_POSTCSS_CONFIG` and `VB_SWC_CONFIG`, the paths of the configs it picked. The
325
- Webpack config reads them.
326
-
327
- ## FAQ
328
-
329
- ### Does VBlocks support Tailwind?
330
-
331
- Yes, VBlocks supports Tailwind but does not include it, so you need a
332
- `postcss.config.js` in your project root.
333
-
334
- 1. Install Tailwind and the Tailwind plugin for PostCSS:
335
-
336
- ```sh
337
- npm install --save-dev tailwindcss @tailwindcss/postcss
338
- ```
339
-
340
- 2. Eject the default PostCSS config into your project root:
341
-
342
- ```sh
343
- npx vblocks eject postcss > postcss.config.js
344
- ```
345
-
346
- 3. Replace `postcss-preset-env` with the Tailwind plugin:
347
-
348
- ```diff
349
- export default ({ mode }) => ({
350
- plugins: {
351
- - "postcss-preset-env": {
352
- - stage: 2,
353
- - },
354
- + "@tailwindcss/postcss": {
355
- + optimize: mode === "production",
356
- + },
357
- "cssnano": mode === "production" && {
358
- preset: "default",
359
- },
360
- },
361
- })
362
- ```
363
-
364
- > [!IMPORTANT]
365
- > You do not need `postcss-preset-env`. Tailwind 4
366
- > [compiles nesting and adds vendor prefixes](https://tailwindcss.com/docs/compatibility)
367
- > itself. With both plugins, `postcss-preset-env` rewrites Tailwind's `@layer`
368
- > rules into `:not(#\#)` selectors. The CSS file grows.
369
-
370
- 4. Add this import to `src/index.css`:
371
-
372
- ```css
373
- @import "tailwindcss";
374
- ```
563
+ ## How It Works
375
564
 
376
- The `xyflow` template of [`vblocks init`](#vblocks-init) has this setup.
565
+ VBlocks is a POSIX shell script that runs Webpack. The script exports
566
+ `VB_POSTCSS_CONFIG` and `VB_SWC_CONFIG`, the paths of the configs it picked. The
567
+ Webpack config reads them.
568
+ -->
377
569
 
378
570
  ## License
379
571