@greendrake/vite-preset 0.2.0 → 0.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
@@ -34,13 +34,12 @@ export default defineConfig(
34
34
  | `scssLoadPaths` | Extra `@use` resolution roots for Sass (e.g. the app's `src/scss`). |
35
35
  | `port` | `'env'` (default): `VITE_PORT` is required whenever a server starts. A number pins that port. `false` disables pinning, for an app served on any free port. |
36
36
  | `htmlPlaceholders` | Literal substitutions applied to `index.html` before Vite processes it (see `htmlPlaceholders` below). |
37
- | `htmlMinify` | Minify `index.html`, inline scripts and styles included, in production builds. |
38
37
  | `staticRoots` | Directories outside the app served at public URL prefixes (see `staticRoots` below). |
39
38
  | `overrides` | A `UserConfig` deep-merged last — the escape hatch for `server.proxy`, extra plugins, build tweaks. |
40
39
 
41
40
  What the preset sets:
42
41
 
43
- - plugins: `@vitejs/plugin-vue` and the HMR circular-import guard, plus the `staticRoots`, `htmlPlaceholders` and `htmlMinify` plugins when their options are given;
42
+ - plugins: `@vitejs/plugin-vue` and the HMR circular-import guard, plus the `staticRoots` and `htmlPlaceholders` plugins when their options are given;
44
43
  - `server.port`/`preview.port` from `VITE_PORT` with `strictPort`, for `vite dev` and `vite preview` only — builds run in deploy contexts that never define a dev port;
45
44
  - `server.fs.allow`: the parent of the app root (a workspace), and every static root's directory;
46
45
  - `resolve.alias`: `@` → `<dirname>/src`; `resolve.dedupe`: `vue`, `pinia`, `vue-router` — each must also be a direct dependency of the app, or Vite fails to resolve it;
@@ -88,10 +87,6 @@ import { loadAppEnv, requirePort, envBool, deriveImageBaseUrl, apiTargetEnv, bui
88
87
 
89
88
  Substitutes build-time values into `index.html` before Vite processes it — a generated inline script, a build hash, PWA metadata. Keys are matched literally (convention: `__NAME__`); an empty map is an error. `vueSpa`'s `htmlPlaceholders` option installs it.
90
89
 
91
- ### `htmlMinify()`
92
-
93
- Production-only: collapses whitespace, strips comments, minifies inline JS and CSS in `index.html`. Dev keeps the source readable. Installed by the `htmlMinify` option.
94
-
95
90
  ### `staticRoots(roots)` and `staticRootFiles(root)`
96
91
 
97
92
  Some assets belong to the product rather than to the frontend — a locale catalogue a backend renders from too, prose a content page shows. A `StaticRoot` is `{ dir, urlPath, transform? }`: an absolute directory, the URL prefix it appears under (e.g. `/i18n`), and an optional per-file rewrite applied on the way out. The plugin serves the root by middleware in dev and copies it into `dist/` at build, so the two modes publish the same bytes; `.yaml`/`.yml` and `.json` get their content types, anything else is `text/plain`. Requests cannot climb out of the root. `staticRootFiles(root)` lists what a root publishes as URL paths, for a service worker's precache list. Installed by the `staticRoots` option.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greendrake/vite-preset",
3
- "version": "0.2.0",
3
+ "version": "0.3.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>",
@@ -38,17 +38,14 @@
38
38
  },
39
39
  "prettier": "@greendrake/dev-config/prettier",
40
40
  "dependencies": {
41
- "@greendrake/util": "0.2.0",
42
- "@vitejs/plugin-vue": "^6.0.7",
43
- "html-minifier-terser": "^7.2.0"
41
+ "@vitejs/plugin-vue": "^6.0.7"
44
42
  },
45
43
  "peerDependencies": {
46
44
  "vite": ">=8"
47
45
  },
48
46
  "devDependencies": {
49
- "@greendrake/dev-config": "0.2.0",
47
+ "@greendrake/dev-config": "0.3.0",
50
48
  "@types/bun": "^1.3.5",
51
- "@types/html-minifier-terser": "^7.0.2",
52
49
  "@types/node": "^24.0.0",
53
50
  "typescript": "6.0.3",
54
51
  "vite": "^8.2.1"
package/src/html.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { minify } from 'html-minifier-terser'
2
1
  import type { Plugin } from 'vite'
3
2
 
4
3
  // Substitutes build-time values into index.html before Vite processes it —
@@ -19,23 +18,3 @@ export const htmlPlaceholders = (map: Record<string, string>): Plugin => {
19
18
  }
20
19
  }
21
20
  }
22
-
23
- // Production-only HTML minification — strips comments and collapses
24
- // whitespace in index.html, and runs inline scripts/styles through
25
- // terser/CSS minification. Dev keeps the source readable.
26
- export const htmlMinify = (): Plugin => ({
27
- name: 'greendrake-html-minify',
28
- apply: 'build',
29
- transformIndexHtml: {
30
- order: 'post',
31
- handler: html =>
32
- minify(html, {
33
- collapseWhitespace: true,
34
- removeComments: true,
35
- minifyJS: true,
36
- minifyCSS: true,
37
- useShortDoctype: true,
38
- removeRedundantAttributes: true
39
- })
40
- }
41
- })
package/src/main.ts CHANGED
@@ -8,11 +8,11 @@ export { envBool, deriveImageBaseUrl, loadAppEnv, requirePort, apiTargetEnv, bui
8
8
  // @greendrake/dash/vite) speak this package's vite types: a second vite
9
9
  // copy resolved downstream is a structurally unrelated set of the same names.
10
10
  export type { ConfigEnv, UserConfig, UserConfigFnObject } from 'vite'
11
- export { htmlPlaceholders, htmlMinify } from './html'
11
+ export { htmlPlaceholders } from './html'
12
12
  export { resolveApiTarget, browserRuntime, type ApiTarget, type ApiTargetEnv, type ApiTargetRuntime } from './apiTarget'
13
13
  export { staticRoots, staticRootFiles, type StaticRoot } from './staticRoots'
14
14
  import { requirePort } from './env'
15
- import { htmlPlaceholders, htmlMinify } from './html'
15
+ import { htmlPlaceholders } from './html'
16
16
  import { hmrCircularImportGuard } from './hmr'
17
17
  import { nestedDependencies, type DeclaredDependencies } from './sourceDeps'
18
18
  import { staticRoots as staticRootsPlugin, type StaticRoot } from './staticRoots'
@@ -34,8 +34,6 @@ export interface VueSpaOptions {
34
34
  // Build-time placeholder substitution in index.html (see the
35
35
  // htmlPlaceholders plugin) — e.g. injecting an inline bootstrap script.
36
36
  htmlPlaceholders?: Record<string, string>
37
- // Minify index.html (incl. inline JS/CSS) in production builds.
38
- htmlMinify?: boolean
39
37
  // Directories outside the app served at a public URL prefix — product
40
38
  // assets both stacks own (locale catalogues, content prose). Served by
41
39
  // middleware in dev and copied into dist/ at build, so the two modes
@@ -90,7 +88,7 @@ export const vueSpa =
90
88
  const portPin = command === 'serve' && options.port !== false ? { port: typeof options.port === 'number' ? options.port : requirePort(), strictPort: true } : undefined
91
89
  const base: UserConfig = {
92
90
  ...(options.define && { define: Object.fromEntries(Object.entries(options.define).map(([key, value]) => [key, JSON.stringify(value)])) }),
93
- plugins: [vue(), hmrCircularImportGuard(), ...(options.staticRoots?.length ? [staticRootsPlugin(options.staticRoots)] : []), ...(options.htmlPlaceholders ? [htmlPlaceholders(options.htmlPlaceholders)] : []), ...(options.htmlMinify ? [htmlMinify()] : [])],
91
+ plugins: [vue(), hmrCircularImportGuard(), ...(options.staticRoots?.length ? [staticRootsPlugin(options.staticRoots)] : []), ...(options.htmlPlaceholders ? [htmlPlaceholders(options.htmlPlaceholders)] : [])],
94
92
  ...(command === 'serve'
95
93
  ? {
96
94
  server: {