@asd14/vblocks 6.2.0 → 6.3.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
@@ -45,6 +45,7 @@ to write, read or fix
45
45
  - [Use environment variables](#use-environment-variables)
46
46
  - [Stop using `../../../` everywhere](#stop-using--everywhere)
47
47
  - [Use CSS Modules](#use-css-modules)
48
+ - [Import a file as text](#import-a-file-as-text)
48
49
  - [Replace a default config](#replace-a-default-config)
49
50
  - [Style with Tailwind](#style-with-tailwind)
50
51
  - [Add VBlocks to an existing project](#add-vblocks-to-an-existing-project)
@@ -259,6 +260,19 @@ import { Component } from "@self/components"
259
260
  > [!NOTE]
260
261
  > The [client types](types/client.d.ts) declare `.css`, image and font imports.
261
262
 
263
+ ### Import a file as text
264
+
265
+ Add `?raw` to the import path. VBlocks hands over the file's contents as text,
266
+ as Vite does:
267
+
268
+ ```tsx
269
+ import greeting from "./greeting.txt?raw"
270
+ // greeting => "Hello from a text file\n"
271
+ ```
272
+
273
+ > [!NOTE]
274
+ > The [client types](types/client.d.ts) type each `?raw` import as a `string`.
275
+
262
276
  ### Replace a default config
263
277
 
264
278
  Each config in your app folder replaces the default of the same name:
@@ -365,6 +379,10 @@ app folder:
365
379
  }
366
380
  ```
367
381
 
382
+ > [!NOTE]
383
+ > An import may name the file tsc emits, eg. `./button.js` for `button.tsx`, as
384
+ > TypeScript's `nodenext` resolution asks. VBlocks finds the source behind it.
385
+
368
386
  3. **Ensure `index.tsx` and `index.html` are in `src/`**
369
387
 
370
388
  > [!NOTE]
@@ -270,6 +270,11 @@ const STATS_BY_LOG_LEVEL = /** @type {const} */ ({
270
270
  verbose: "verbose",
271
271
  })
272
272
 
273
+ /**
274
+ * The query that imports a file as text, as in Vite, eg. `./file.tsx?raw`
275
+ */
276
+ const RAW_QUERY = /[?&]raw(?:&|$)/
277
+
273
278
  /**
274
279
  * @typedef {Object} VBlocksProps
275
280
  *
@@ -349,9 +354,15 @@ export default (
349
354
 
350
355
  module: {
351
356
  rules: [
357
+ // If `?raw`, return the file contents. Every other rule skips `?raw`
358
+ {
359
+ resourceQuery: RAW_QUERY,
360
+ type: "asset/source",
361
+ },
352
362
  {
353
363
  test: /\.(ts|tsx)$/,
354
364
  exclude: /node_modules/,
365
+ resourceQuery: { not: [RAW_QUERY] },
355
366
  use: {
356
367
  loader: "swc-loader",
357
368
  options: swcConfig,
@@ -360,6 +371,7 @@ export default (
360
371
  {
361
372
  test: /\.mdx?$/,
362
373
  exclude: /node_modules/,
374
+ resourceQuery: { not: [RAW_QUERY] },
363
375
  use: [
364
376
  { loader: "swc-loader", options: swcConfig },
365
377
  { loader: "@mdx-js/loader" },
@@ -367,6 +379,7 @@ export default (
367
379
  },
368
380
  {
369
381
  test: /\.module\.css$/,
382
+ resourceQuery: { not: [RAW_QUERY] },
370
383
  use: getCssLoaders({
371
384
  classScope: "local",
372
385
  isProduction,
@@ -376,6 +389,7 @@ export default (
376
389
  {
377
390
  test: /\.css$/,
378
391
  exclude: /\.module\.css$/,
392
+ resourceQuery: { not: [RAW_QUERY] },
379
393
  use: getCssLoaders({
380
394
  classScope: "global",
381
395
  isProduction,
@@ -384,6 +398,7 @@ export default (
384
398
  },
385
399
  {
386
400
  test: /\.(jpg|gif|png|svg)$/,
401
+ resourceQuery: { not: [RAW_QUERY] },
387
402
  ...(isSingle
388
403
  ? { type: "asset/inline" }
389
404
  : {
@@ -397,6 +412,7 @@ export default (
397
412
  },
398
413
  {
399
414
  test: /\.(woff|woff2|ttf|eot)$/,
415
+ resourceQuery: { not: [RAW_QUERY] },
400
416
  ...(isSingle
401
417
  ? { type: "asset/inline" }
402
418
  : {
@@ -512,6 +528,9 @@ export default (
512
528
 
513
529
  resolve: {
514
530
  extensions: [".tsx", ".ts", ".jsx", ".js"],
531
+ // A TypeScript import names the file tsc emits, eg. `./button.js` for
532
+ // `button.tsx`. Find the source behind it, as Vite does
533
+ extensionAlias: { ".js": [".ts", ".tsx", ".js"] },
515
534
  alias: {
516
535
  "@self": `${entryDir}/src`,
517
536
  // React Refresh imports the dev server's client. Use the one VBlocks runs
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@asd14/vblocks",
4
- "version": "6.2.0",
4
+ "version": "6.3.0",
5
5
  "description": "Zero-config React builds, as a static site or a single HTML file",
6
6
  "keywords": [
7
7
  "react",
@@ -64,7 +64,7 @@
64
64
  "@asd14/fancy-logger": "^2.0.0",
65
65
  "@mdx-js/loader": "^3.1.1",
66
66
  "@pmmmwh/react-refresh-webpack-plugin": "^0.6.3",
67
- "@swc/helpers": "^0.5.23",
67
+ "@swc/helpers": "^0.5.24",
68
68
  "browserslist": "^4.29.5",
69
69
  "copy-webpack-plugin": "^14.0.0",
70
70
  "css-loader": "^7.1.5",
@@ -74,30 +74,30 @@
74
74
  "mini-css-extract-plugin": "^2.10.2",
75
75
  "postcss": "^8.5.32",
76
76
  "postcss-loader": "^8.2.1",
77
- "postcss-preset-env": "^11.6.1",
77
+ "postcss-preset-env": "^11.6.2",
78
78
  "react-refresh": "^0.19.0",
79
79
  "swc-loader": "^0.2.7",
80
80
  "webpack": "^5.112.2",
81
- "webpack-bundle-analyzer": "^5.4.0",
82
- "webpack-cli": "^7.2.3",
81
+ "webpack-bundle-analyzer": "^5.4.2",
82
+ "webpack-cli": "^7.3.1",
83
83
  "webpack-dev-server": "^6.1.0"
84
84
  },
85
85
  "devDependencies": {
86
- "@asd14/eslint-config": "^16.2.0",
86
+ "@asd14/eslint-config": "^16.3.0",
87
87
  "@asd14/prettier-config": "^1.5.0",
88
88
  "@asd14/semantic-release-config": "^1.1.0",
89
- "@asd14/ts-config": "^1.6.0",
89
+ "@asd14/ts-config": "^2.0.0",
90
90
  "@commitlint/cli": "^21.2.4",
91
91
  "@commitlint/config-conventional": "^21.2.4",
92
- "@tailwindcss/postcss": "^4.3.3",
92
+ "@tailwindcss/postcss": "^4.3.5",
93
93
  "@types/dotenv-webpack": "^7.0.8",
94
94
  "@types/react": "^19.3.0",
95
95
  "@types/webpack-bundle-analyzer": "^4.7.0",
96
- "@xyflow/react": "^12.12.0",
96
+ "@xyflow/react": "^12.12.1",
97
97
  "eslint": "^9.39.5",
98
98
  "prettier": "^3.9.10",
99
99
  "semantic-release": "^25.0.9",
100
- "tailwindcss": "^4.3.3",
100
+ "tailwindcss": "^4.3.5",
101
101
  "typescript": "^6.0.3"
102
102
  },
103
103
  "peerDependencies": {
@@ -14,7 +14,7 @@
14
14
  "react-dom": "^19"
15
15
  },
16
16
  "devDependencies": {
17
- "@asd14/ts-config": "^1.6.0",
17
+ "@asd14/ts-config": "^2.0.0",
18
18
  "@asd14/vblocks": "*",
19
19
  "@types/react": "^19",
20
20
  "@types/react-dom": "^19",
package/types/client.d.ts CHANGED
@@ -93,6 +93,22 @@ declare module "*.mdx" {
93
93
  export default MDXContent
94
94
  }
95
95
 
96
+ /**
97
+ * The text of the file, as Vite's `?raw` gives it. No loader changes it.
98
+ *
99
+ * @example
100
+ * import { Variants } from "./variants.js"
101
+ * import variantsSource from "./variants.tsx?raw"
102
+ *
103
+ * <Variants />
104
+ * <pre>{variantsSource}</pre>
105
+ */
106
+ declare module "*?raw" {
107
+ const source: string
108
+
109
+ export default source
110
+ }
111
+
96
112
  /**
97
113
  * The `.env` variables Webpack writes into the bundle. The browser has no
98
114
  * other part of Node's `process`.