@asd14/vblocks 1.0.0 → 2.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/LICENSE CHANGED
@@ -1,29 +1,21 @@
1
- BSD 3-Clause License
1
+ MIT License
2
2
 
3
- Copyright (c) 2025, Andrei Dumitrescu
4
- All rights reserved.
3
+ Copyright (c) 2025 Andrei Dumitrescu
5
4
 
6
- Redistribution and use in source and binary forms, with or without
7
- modification, are permitted provided that the following conditions are met:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
8
11
 
9
- 1. Redistributions of source code must retain the above copyright notice, this
10
- list of conditions and the following disclaimer.
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
11
14
 
12
- 2. Redistributions in binary form must reproduce the above copyright notice,
13
- this list of conditions and the following disclaimer in the documentation
14
- and/or other materials provided with the distribution.
15
-
16
- 3. Neither the name of the copyright holder nor the names of its
17
- contributors may be used to endorse or promote products derived from
18
- this software without specific prior written permission.
19
-
20
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,18 +1,40 @@
1
- # vblocks
1
+ [![Release](https://github.com/asd-xiv/vblocks/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/asd-xiv/vblocks/actions/workflows/main.yml)
2
+ [![npm version](https://img.shields.io/npm/v/@asd14/vblocks.svg)](https://www.npmjs.com/package/@asd14/vblocks)
2
3
 
3
- > 📜 POSIX + 📦 Webpack, an unlikely story!
4
-
5
- Zero-config Webpack wrapper for React applications with opinionated defaults and
6
- modern toolchain integration.
4
+ # @asd14/vblocks
7
5
 
8
- ## Features
6
+ > 📜 POSIX + 📦 Webpack, an unlikely story!
9
7
 
10
- - **Zero Configuration** - Works out of the box with sensible defaults
11
- - **Convention over Configuration** - Smart project structure detection
12
- - **Modern Toolchain** - SWC, TailwindCSS, PostCSS, CSS Modules, MDX support
13
- - **Flexible Configuration** - Project configs override defaults when present
14
- - **Development Experience** - Hot reload, React Refresh, bundle analysis
15
- - **Production Ready** - Optimized builds with code splitting and caching
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
11
+
12
+ ## Table of contents
13
+
14
+ <!-- vim-markdown-toc GFM -->
15
+
16
+ - [Installation](#installation)
17
+ - [Peer Dependencies](#peer-dependencies)
18
+ - [Quick Start](#quick-start)
19
+ - [Configuration](#configuration)
20
+ - [Commands](#commands)
21
+ - [`vblocks init`](#vblocks-init)
22
+ - [`vblocks serve`](#vblocks-serve)
23
+ - [`vblocks build`](#vblocks-build)
24
+ - [`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
+ - [License](#license)
36
+
37
+ <!-- vim-markdown-toc -->
16
38
 
17
39
  ## Installation
18
40
 
@@ -20,170 +42,339 @@ modern toolchain integration.
20
42
  npm install --save-dev @asd14/vblocks
21
43
  ```
22
44
 
23
- ## Usage
45
+ > [!IMPORTANT]
46
+ > VBlocks needs Node `^22.22.3`, `^24.15.0` or `>=26.0`.
24
47
 
25
- ### Quick Start
48
+ ### Peer Dependencies
26
49
 
27
50
  ```sh
28
- # Start development server
29
- npx vblocks serve
30
-
31
- # Build for production
32
- npx vblocks build
33
-
34
- # View webpack configuration
35
- npx vblocks eject webpack
51
+ npm install react react-dom
36
52
  ```
37
53
 
38
- ### Project Structure
54
+ > [!IMPORTANT]
55
+ > VBlocks needs React `^18` or `^19`.
56
+
57
+ ## Quick Start
39
58
 
40
- VBlocks expects a standard React project structure:
59
+ Create a project and start the dev server:
41
60
 
61
+ ```sh
62
+ npx @asd14/vblocks init my-vblocks-app
63
+ cd my-vblocks-app
64
+ npm install
65
+ npm start
42
66
  ```
43
- your-project/
67
+
68
+ ```text
69
+ my-vblocks-app/
44
70
  ├── src/
45
- │ ├── index.tsx # Application entry point
46
- │ ├── index.html # HTML template
47
- │ ├── index.css # Global styles (optional)
48
- │ └── public/
49
- │ ├── favicon.svg # Favicon (optional)
50
- │ └── robots.txt # Robots file (optional)
51
- ├── .env # Environment variables (optional)
52
- └── dist/ # Build output
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)
53
77
  ```
54
78
 
55
- ## How It Works
79
+ Run a command in a project that has VBlocks installed:
56
80
 
57
- VBlocks is a **POSIX shell script wrapper** around Webpack that:
81
+ ```sh
82
+ # Start the dev server
83
+ npx vblocks serve
84
+
85
+ # Build for production
86
+ npx vblocks build
58
87
 
59
- 1. **Detects configuration files** - Uses project configs when available, falls
60
- back to defaults
61
- 2. **Sets environment variables** - Passes config paths to Webpack via env vars
62
- 3. **Proxies commands** - `build` and `serve` are passed directly to `webpack`
63
- with custom parameters
64
- 4. **Provides configuration inspection** - `eject` outputs configuration content
65
- for review
88
+ # Save the default Webpack config in your project root
89
+ npx vblocks eject webpack > webpack.config.js
90
+ ```
66
91
 
67
92
  ## Configuration
68
93
 
69
- VBlocks follows a **configuration hierarchy** - project files take precedence
70
- over defaults:
94
+ A config in your project root replaces the default of the same name.
71
95
 
72
- 1. **Project configs** (in your project root) - highest priority
73
- 2. **Default configs** (from vblocks package) - fallback
96
+ - `webpack.config.js`
97
+ - `postcss.config.js`
98
+ - `.swcrc`
74
99
 
75
- ### Supported Configuration Files
100
+ To replace a default, first [`eject`](#vblocks-eject) it into your project root,
101
+ then edit the file:
76
102
 
77
- - `webpack.config.js` - Webpack configuration
78
- - `postcss.config.js` - PostCSS configuration
79
- - `tailwind.config.js` - TailwindCSS configuration
80
- - `.swcrc` - SWC configuration
103
+ ```sh
104
+ npx vblocks eject postcss > postcss.config.js
105
+ ```
81
106
 
82
- ### Configuration Override Example
107
+ > [!NOTE]
108
+ > VBlocks does not merge your config with the default, with two exceptions:
109
+ >
110
+ > - `.swcrc -> env.targets`: VBlocks adds the default when yours is missing
111
+ > - `.swcrc -> jsc.transform.react.refresh`: VBlocks adds the React Refresh
112
+ > transform when `serve` runs in `development` mode
83
113
 
84
- Create any of these files in your project root to customize behavior:
114
+ ## Commands
85
115
 
86
- ```js
87
- // tailwind.config.js - customize TailwindCSS
88
- export default {
89
- content: ["./src/**/*.{ts,tsx}"],
90
- theme: {
91
- extend: {
92
- colors: {
93
- primary: "#your-color"
94
- }
95
- }
96
- }
97
- }
116
+ ### `vblocks init`
117
+
118
+ Creates a project in `<directory>` from a template.
119
+
120
+ ```text
121
+ vblocks init <directory> [--template <plain|xyflow>]
98
122
  ```
99
123
 
100
- ## Commands
124
+ **Example**:
125
+
126
+ ```sh
127
+ npx @asd14/vblocks init my-vblock-flow --template xyflow
128
+ cd my-vblock-flow
129
+ npm install
130
+ ```
101
131
 
102
132
  ### `vblocks serve`
103
133
 
104
- **Proxies to**:
105
- `npx webpack serve --config $VB_WEBPACK_CONFIG --env entryDir=$PROJECT_DIR ...`
134
+ Starts a React Refresh enabled development server.
106
135
 
107
- Starts development server with:
136
+ - Runs at `http://localhost:8080`, auto-opens in browser
137
+ - Runs bundle analyzer at `http://127.0.0.1:8888`
108
138
 
109
- - Hot Module Replacement
110
- - Automatic browser opening
111
- - Bundle analyzer (non-opening)
112
- - Error overlay
113
- - History API fallback for SPAs
139
+ ```text
140
+ vblocks serve [--mode <development|production>] [<webpack option>...]
141
+ ```
142
+
143
+ **Example**:
144
+
145
+ ```sh
146
+ cd my-vblock-flow
147
+ vblocks serve
148
+ # ↓
149
+ # npx webpack serve --config <webpack config> \
150
+ # --env entryDir=<project root> \
151
+ # --mode development
152
+ ```
114
153
 
115
154
  ### `vblocks build`
116
155
 
117
- **Proxies to**:
118
- `npx webpack build --config $VB_WEBPACK_CONFIG --env entryDir=$PROJECT_DIR ...`
156
+ ```text
157
+ vblocks build [--mode <mode>] [--env single] [<webpack option>...]
158
+ ```
159
+
160
+ Builds the project into `dist/`.
119
161
 
120
- Creates production build with:
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 |
121
167
 
122
- - Minified assets
123
- - Content hashing
124
- - Optimized chunks
125
- - Performance hints
168
+ Without `--env single`, the build:
126
169
 
127
- ### `vblocks eject webpack`
170
+ - Writes JS and CSS files with content-hashed names
171
+ - Writes a `react` chunk, and a `vendors` chunk when your other dependencies
172
+ total over 20 KB
128
173
 
129
- **Special command** - Outputs the webpack configuration to stdout for
130
- inspection:
174
+ With `--env single`:
175
+
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
180
+
181
+ **Runs**:
182
+
183
+ ```sh
184
+ npx webpack build --config <webpack config> \
185
+ --env entryDir=<project root> \
186
+ --mode production \
187
+ [...your arguments]
188
+ ```
189
+
190
+ ### `vblocks eject`
191
+
192
+ ```text
193
+ vblocks eject <config>
194
+ ```
195
+
196
+ Prints a default config to stdout.
197
+
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):
131
203
 
132
204
  ```sh
133
205
  npx vblocks eject webpack > webpack.config.js
206
+ npx vblocks eject postcss > postcss.config.js
207
+ npx vblocks eject swc > .swcrc
134
208
  ```
135
209
 
136
210
  ## Features in Detail
137
211
 
212
+ ### TypeScript
213
+
214
+ VBlocks does not check types and never reads your `tsconfig.json`. It only
215
+ compiles TypeScript with SWC.
216
+
217
+ For convenience, VBlocks provides client types in
218
+ [`client.d.ts`](src/types/client.d.ts) for:
219
+
220
+ - `.css` imports
221
+ - Image and font imports
222
+ - `process.env`
223
+
224
+ You can use them in your `tsconfig.json`:
225
+
226
+ ```json
227
+ {
228
+ "compilerOptions": {
229
+ "types": ["@asd14/vblocks/client"]
230
+ }
231
+ }
232
+ ```
233
+
234
+ `tsc` needs the [`@self`](#path-alias) path alias in your `tsconfig.json`:
235
+
236
+ ```diff
237
+ {
238
+ "compilerOptions": {
239
+ "types": ["@asd14/vblocks/client"],
240
+ + "paths": { "@self/*": ["./src/*"] }
241
+ }
242
+ }
243
+ ```
244
+
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
+ ```
266
+
267
+ `postcss-preset-env` compiles nesting, `oklch()` and `color-mix()` for older
268
+ browsers and adds vendor prefixes.
269
+
138
270
  ### CSS Modules Support
139
271
 
140
- - **Global CSS** - `import './styles.css'`
141
- - **Local CSS Modules** - `import styles from './component.module.css'`
272
+ - **Global CSS** - `import "./styles.css"`
273
+ - **Local CSS Modules** - `import styles from "./component.module.css"`
142
274
  - **camelCase exports** - `.my-class` becomes `styles.myClass`
143
- - **Development-friendly naming** - includes class names in dev builds
275
+ - **Class names** - a bare hash in `production` mode, `[local]__[hash]` in
276
+ `development` mode
277
+ - **TypeScript** - the [client types](#typescript) declare `.css` imports
144
278
 
145
279
  ### Asset Handling
146
280
 
147
- - **Images** - Automatic optimization, inlined if < 10KB
148
- - **Fonts** - Copied to `fonts/` directory
149
- - **Favicon & Robots** - Automatically included in build
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
150
286
 
151
287
  ### Environment Variables
152
288
 
153
- VBlocks automatically loads `.env` files in your project root:
289
+ VBlocks loads the `.env` file in your project root:
154
290
 
155
291
  ```env
156
- # .env
157
- REACT_APP_API_URL=https://api.example.com
292
+ API_URL=https://api.example.com
158
293
  ```
159
294
 
160
- Access in your code:
295
+ Read a variable in your code:
161
296
 
162
297
  ```tsx
163
- const apiUrl = process.env.REACT_APP_API_URL
298
+ const apiUrl = process.env["API_URL"]
164
299
  ```
165
300
 
166
- ### Path Aliases
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
167
310
 
168
- Built-in alias for cleaner imports:
311
+ `@self` points at your `src/` directory:
169
312
 
170
313
  ```tsx
171
- // Instead of: import { Component } from '../../../components'
314
+ // Instead of: import { Component } from "../../../components"
172
315
  import { Component } from "@self/components"
173
316
  ```
174
317
 
175
- ## Peer Dependencies
318
+ `tsc` needs the same alias in your `tsconfig.json`. See
319
+ [TypeScript](#typescript).
176
320
 
177
- ```json
178
- {
179
- "peerDependencies": {
180
- "react": "^18 || ^19",
181
- "react-dom": "^18 || ^19"
182
- }
183
- }
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
184
338
  ```
185
339
 
186
- ## License
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
+ ```
187
363
 
188
- BSD 3-Clause
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
+ ```
375
+
376
+ The `xyflow` template of [`vblocks init`](#vblocks-init) has this setup.
377
+
378
+ ## License
189
379
 
380
+ MIT