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