@greendrake/vite-preset 0.3.0 → 0.5.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
@@ -49,7 +49,7 @@ What the preset sets:
49
49
  vueSpa({ dirname: import.meta.dirname, sourcePackages: ['@greendrake/', '@acme/ui', 'my-design-system'] })
50
50
  ```
51
51
 
52
- Excluding a package also hides it from Vite's dependency scanner, which externalises every excluded id and so never reads what that package imports. The third-party packages behind a source package are therefore pinned into the pre-bundle too, or the first browser request for one is a discovery: Vite re-runs the optimiser mid-session and full-reloads every open page — which under a parallel E2E run lands in the middle of tests in flight. The preset walks the app's runtime dependencies, follows the source packages among them, and pins each package they depend on, plus each peer they declare that the app itself supplies at runtime. Each is named in Vite's `parent > child` form unless the app declares it too, in which case its plain name — the id the scanner itself would produce — is used instead. Two things are left out: a package published only under subpaths, which no `optimizeDeps` entry can name and which Vite reaches through the subpath ids that import it anyway; and anything behind a source package the app keeps among its dev dependencies, which by the app's own reckoning is tooling (a build-tool integration shipped beside a package's components, a native-build helper) that browser code never reaches. That split is what an app is asserting when it puts a package in one list rather than the other, so put build-time source packages in `devDependencies`.
52
+ Excluding a package also hides it from Vite's dependency scanner, which externalises every excluded id and so never reads what that package imports. The third-party packages behind a source package are therefore pinned into the pre-bundle too, or the first browser request for one is a discovery: Vite re-runs the optimiser mid-session and full-reloads every open page — which under a parallel E2E run lands in the middle of tests in flight. The preset walks the app's runtime dependencies, follows the source packages among them, and pins each package they depend on, plus each peer they declare that the app itself supplies at runtime. Each is named in Vite's `parent > child` form unless the app declares it too, in which case its plain name — the id the scanner itself would produce — is used instead. Three things are left out: a package published only under subpaths, which no `optimizeDeps` entry can name and which Vite reaches through the subpath ids that import it anyway; a peer that is itself a source package, which the app's own declaration of it puts under the same rules as any other source package — excluded, and walked in its turn; and anything behind a source package the app keeps among its dev dependencies, which by the app's own reckoning is tooling (a build-tool integration shipped beside a package's components, a native-build helper) that browser code never reaches. That split is what an app is asserting when it puts a package in one list rather than the other, so put build-time source packages in `devDependencies`.
53
53
 
54
54
  - `build`: font files (`woff2`, `woff`, `eot`, `ttf`, `otf`) are emitted unhashed under `assets/fonts/`, so `index.html` can prefetch them by a stable name; everything else is hashed.
55
55
 
@@ -74,7 +74,7 @@ An HMR update whose accepted module sits inside an import cycle cannot be re-exe
74
74
  import { loadAppEnv, requirePort, envBool, deriveImageBaseUrl, apiTargetEnv, buildHash } from '@greendrake/vite-preset'
75
75
  ```
76
76
 
77
- - `loadAppEnv(mode, dirname)` — the app's `.env` / `.env.<mode>` files, every key (not only `VITE_`-prefixed ones): they carry plain build inputs, and the `export` prefix they may be written with is stripped so the same file can be shell-sourced. `process.env` outranks the file. Do not name the files `.env.development` / `.env.production`: bun auto-loads those into `process.env` at startup, and whichever one it picked would then outrank the mode's file. `@greendrake/dash/vite` builds its dashboard convention on this.
77
+ - `loadAppEnv(mode, dirname)` — the app's `.env` / `.env.<mode>` files, every key (not only `VITE_`-prefixed ones): they carry plain build inputs, and the `export` prefix they may be written with is stripped so the same file can be shell-sourced. `process.env` outranks the file. Do not name the files `.env.development` / `.env.production`: bun auto-loads those into `process.env` at startup, and whichever one it picked would then outrank the mode's file.
78
78
  - `requirePort()` — `VITE_PORT`, required; the single port convention.
79
79
  - `envBool(value)` — `"1"`, `"t"`, `"true"` (any case) are true; `"0"`, `"false"`, unset and everything else are false. `Boolean(process.env.X)` would take the literal string `"0"` as true.
80
80
  - `deriveImageBaseUrl(env = process.env)` — the prefix for object-storage image URLs. A defined `S3_PREFIX` wins outright, even when empty; otherwise `AWS_S3_ENDPOINT/AWS_S3_BUCKET`; otherwise `''`.
@@ -107,12 +107,12 @@ The single source of truth for where the API lives, pure and environment-free, s
107
107
 
108
108
  ## Sass: import shared style packages by bare specifier
109
109
 
110
- `@use '@greendrake/font-inter'` — never `@use 'pkg:@greendrake/font-inter'`, and do not register Sass's `NodePackageImporter`.
110
+ `@use '@acme/font'` — never `@use 'pkg:@acme/font'`, and do not register Sass's `NodePackageImporter`.
111
111
 
112
112
  Vite resolves bare specifiers with its own Sass importer and rebases relative `url()` references inside the imported package against that package's own source location, so `@font-face { src: url('./fonts/X.woff2') }` in a font package resolves, gets emitted into `dist/assets/`, and the emitted CSS points at the built asset.
113
113
 
114
114
  `NodePackageImporter` resolves the same `@use` to a path Vite's CSS pipeline does not rebase against. The `url()` then survives verbatim into the output, no font asset is emitted, and the build warns `didn't resolve at build time, it will remain unchanged to be resolved at runtime` — every font 404s at runtime. This is a property of the importer, not of any Vite version.
115
115
 
116
- The corollary, enforced by `@greendrake/scss-kit`'s `_font-face.scss`: the `url()` literal must be written in the owning package's own `.scss`, because that is the file the rebasing is relative to.
116
+ The corollary: the `url()` literal must be written in the owning package's own `.scss`, because that is the file the rebasing is relative to — a shared `@font-face` mixin that builds the URL itself breaks it.
117
117
 
118
118
  If a future Vite drops bare-specifier support, migrate to `loadPaths` or move the `@font-face` blocks into the consuming apps — not to `pkg:`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greendrake/vite-preset",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Vite config factory and build-env helpers for Vue 3 single-page apps: plugin set, strict dev port, alias, dedupe and source-package pre-bundling rules",
5
5
  "license": "MIT",
6
6
  "author": "Eugene Greendrake <eugene@greendrake.nz>",
@@ -44,7 +44,7 @@
44
44
  "vite": ">=8"
45
45
  },
46
46
  "devDependencies": {
47
- "@greendrake/dev-config": "0.3.0",
47
+ "@greendrake/dev-config": "0.5.0",
48
48
  "@types/bun": "^1.3.5",
49
49
  "@types/node": "^24.0.0",
50
50
  "typescript": "6.0.3",
package/src/main.ts CHANGED
@@ -4,9 +4,9 @@ import vue from '@vitejs/plugin-vue'
4
4
  import { mergeConfig, type ConfigEnv, type UserConfig, type UserConfigFnObject } from 'vite'
5
5
 
6
6
  export { envBool, deriveImageBaseUrl, loadAppEnv, requirePort, apiTargetEnv, buildHash } from './env'
7
- // Re-exported so config factories building on vueSpa (e.g.
8
- // @greendrake/dash/vite) speak this package's vite types: a second vite
9
- // copy resolved downstream is a structurally unrelated set of the same names.
7
+ // Re-exported so config factories building on vueSpa speak this package's
8
+ // vite types: a second vite copy resolved downstream is a structurally
9
+ // unrelated set of the same names.
10
10
  export type { ConfigEnv, UserConfig, UserConfigFnObject } from 'vite'
11
11
  export { htmlPlaceholders } from './html'
12
12
  export { resolveApiTarget, browserRuntime, type ApiTarget, type ApiTargetEnv, type ApiTargetRuntime } from './apiTarget'
@@ -28,8 +28,8 @@ export interface VueSpaOptions {
28
28
  scssLoadPaths?: string[]
29
29
  // 'env' (default): the strict VITE_PORT convention, required when the dev
30
30
  // server starts. A number: that port verbatim, for callers that resolved
31
- // the app's env themselves (see @greendrake/dash/vite). false: no
32
- // port pinning — for simple apps served on any free port.
31
+ // the app's env themselves. false: no port pinning — for simple apps
32
+ // served on any free port.
33
33
  port?: 'env' | number | false
34
34
  // Build-time placeholder substitution in index.html (see the
35
35
  // htmlPlaceholders plugin) — e.g. injecting an inline bootstrap script.
package/src/sourceDeps.ts CHANGED
@@ -86,9 +86,10 @@ export const nestedDependencies = (dirname: string, declared: DeclaredDependenci
86
86
  }
87
87
  // A peer is the app's to supply, so it counts only where the app does,
88
88
  // at runtime — the same reckoning, applied to what a package leaves to
89
- // its consumer.
89
+ // its consumer. A source package among them is served raw like any
90
+ // other, and walked as the app's own declaration of it is.
90
91
  for (const peer of Object.keys(pkg.peerDependencies ?? {})) {
91
- if (declared.runtime.includes(peer)) pin(here, dirname, peer)
92
+ if (declared.runtime.includes(peer) && !isSourcePackage(peer)) pin(here, dirname, peer)
92
93
  }
93
94
  }
94
95
  for (const name of declared.runtime) {