@bndynet/vue-site 0.1.3 → 0.1.5

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
@@ -50,6 +50,14 @@ npx vue-site build
50
50
  npx vue-site preview
51
51
  ```
52
52
 
53
+ Subpath deploy: pass Vite’s public base on the CLI (overrides `env.vite.base` in `site.config`):
54
+
55
+ ```bash
56
+ npx vue-site build --base=/app/
57
+ # or
58
+ npx vue-site build --base /app/
59
+ ```
60
+
53
61
  Add `"dev": "vue-site dev"` (or `vs dev`) in `package.json` scripts if you like.
54
62
 
55
63
  ## Config reference
package/bin/vue-site.mjs CHANGED
@@ -24,7 +24,45 @@ const cwd = process.cwd()
24
24
  const cwdParent = resolve(cwd, '..')
25
25
  /** Two levels up: monorepos (`apps/docs` importing `../../packages/...`). Omitted when that would be the FS root (too permissive for dev). */
26
26
  const cwdGrandparent = resolve(cwd, '../..')
27
- const command = process.argv[2] || 'dev'
27
+
28
+ /**
29
+ * @param {string[]} argv
30
+ * @returns {{ command: string, cliBase?: string }}
31
+ */
32
+ function parseCliArgv(argv = process.argv) {
33
+ const sub = argv[2]
34
+ const command =
35
+ sub && !sub.startsWith('-')
36
+ ? sub
37
+ : 'dev'
38
+
39
+ let cliBase
40
+ const flagStart = command === sub && sub ? 3 : 2
41
+ for (let i = flagStart; i < argv.length; i++) {
42
+ const a = argv[i]
43
+ if (a === '--base') {
44
+ const v = argv[i + 1]
45
+ if (!v || v.startsWith('-')) {
46
+ console.error(
47
+ '[vue-site] --base requires a value (e.g. --base=/app/ or --base /app/)',
48
+ )
49
+ process.exit(1)
50
+ }
51
+ cliBase = v
52
+ i++
53
+ } else if (a.startsWith('--base=')) {
54
+ const v = a.slice('--base='.length)
55
+ if (!v) {
56
+ console.error(
57
+ '[vue-site] --base= requires a value (e.g. --base=/app/)',
58
+ )
59
+ process.exit(1)
60
+ }
61
+ cliBase = v
62
+ }
63
+ }
64
+ return { command, cliBase }
65
+ }
28
66
 
29
67
  function isLikelyFilesystemRoot(dir) {
30
68
  if (dir === '/' || dir === '//') return true
@@ -120,16 +158,33 @@ function readPackageRepositoryUrl() {
120
158
  return tryReadRepositoryFromDir(cwd)
121
159
  }
122
160
 
123
- const entryCode = [
124
- `import { createSiteApp } from '${pkgDir.replace(/\\/g, '/')}/dist/index.es.js'`,
125
- `import '${pkgDir.replace(/\\/g, '/')}/dist/style.css'`,
126
- `import siteConfig from '/${foundConfig}'`,
127
- `import { repositoryUrl } from '${VIRTUAL_PACKAGE}'`,
128
- `;(async () => {`,
129
- ` const app = await createSiteApp({ ...siteConfig, packageRepository: repositoryUrl })`,
130
- ` app.mount('#app')`,
131
- `})()`,
132
- ].join('\n')
161
+ /** Root-relative path for Vite (`./foo` -> `/foo`). */
162
+ function resolveBootstrapUrl(path) {
163
+ const t = String(path).trim()
164
+ if (!t) throw new Error('[vue-site] bootstrap path is empty')
165
+ if (t.startsWith('/')) return t
166
+ return '/' + t.replace(/^\.\//, '')
167
+ }
168
+
169
+ // Static import bundles bootstrap for production; dynamic import with vite-ignore is not emitted.
170
+ function buildEntryCode(siteConfig) {
171
+ const bs = siteConfig?.bootstrap
172
+ const bootstrapImport =
173
+ bs != null && String(bs).trim() !== ''
174
+ ? `import '${resolveBootstrapUrl(bs)}'\n`
175
+ : ''
176
+ return [
177
+ bootstrapImport,
178
+ `import { createSiteApp } from '${pkgDir.replace(/\\/g, '/')}/dist/index.es.js'`,
179
+ `import '${pkgDir.replace(/\\/g, '/')}/dist/style.css'`,
180
+ `import siteConfig from '/${foundConfig}'`,
181
+ `import { repositoryUrl } from '${VIRTUAL_PACKAGE}'`,
182
+ `;(async () => {`,
183
+ ` const app = await createSiteApp({ ...siteConfig, packageRepository: repositoryUrl })`,
184
+ ` app.mount('#app')`,
185
+ `})()`,
186
+ ].join('\n')
187
+ }
133
188
 
134
189
  const htmlTemplate = `<!DOCTYPE html>
135
190
  <html lang="en">
@@ -177,7 +232,7 @@ async function loadSiteConfig() {
177
232
  }
178
233
  }
179
234
 
180
- function vueSitePlugin() {
235
+ function vueSitePlugin(entryCode) {
181
236
  return [
182
237
  {
183
238
  name: 'vue-site:virtual-entry',
@@ -215,15 +270,20 @@ function vueSitePlugin() {
215
270
  ]
216
271
  }
217
272
 
218
- async function buildViteConfig() {
219
- const siteConfig = await loadSiteConfig()
273
+ async function buildViteConfig(options = {}) {
274
+ const { cliBase, siteConfig: siteConfigOption } = options
275
+ const siteConfig = siteConfigOption ?? (await loadSiteConfig())
276
+ const env = siteConfig.env || {}
220
277
  const {
221
278
  port,
222
279
  outDir,
223
280
  customElements = [],
224
- watchPackages = [],
225
281
  vite: userVite = {},
226
- } = siteConfig.env || {}
282
+ } = env
283
+ const watchPackages =
284
+ env.watchPackages !== undefined
285
+ ? env.watchPackages
286
+ : siteConfig.watchPackages ?? []
227
287
  const { vue: userVueOpts = {}, plugins: userPlugins, ...userViteRest } =
228
288
  userVite
229
289
 
@@ -315,9 +375,11 @@ async function buildViteConfig() {
315
375
  }
316
376
  }
317
377
 
378
+ const entryCode = buildEntryCode(siteConfig)
379
+
318
380
  const baseConfig = {
319
381
  root: cwd,
320
- plugins: [vue(vueOpts), ...vueSitePlugin(), ...(userPlugins || [])],
382
+ plugins: [vue(vueOpts), ...vueSitePlugin(entryCode), ...(userPlugins || [])],
321
383
  resolve: {
322
384
  alias: {
323
385
  vue: resolve(vuePath, 'dist/vue.runtime.esm-bundler.js'),
@@ -335,13 +397,16 @@ async function buildViteConfig() {
335
397
  outDir: resolve(cwd, outDir || `${basename(cwd)}-dist`),
336
398
  emptyOutDir: true,
337
399
  },
400
+ ...(cliBase != null && { base: cliBase }),
338
401
  }
339
402
 
340
403
  return mergeConfig(userViteRest, baseConfig)
341
404
  }
342
405
 
343
406
  async function run() {
344
- const viteConfig = await buildViteConfig()
407
+ const { command, cliBase } = parseCliArgv()
408
+ const siteConfig = await loadSiteConfig()
409
+ const viteConfig = await buildViteConfig({ cliBase, siteConfig })
345
410
 
346
411
  if (command === 'dev') {
347
412
  const server = await createServer(viteConfig)
@@ -353,6 +418,11 @@ async function run() {
353
418
  const hadHtml = fs.existsSync(tempHtml)
354
419
 
355
420
  if (!hadHtml) {
421
+ const bs = siteConfig?.bootstrap
422
+ const bootstrapImport =
423
+ bs != null && String(bs).trim() !== ''
424
+ ? `import '${resolveBootstrapUrl(bs)}'\n`
425
+ : ''
356
426
  const buildHtml = `<!DOCTYPE html>
357
427
  <html lang="en">
358
428
  <head>
@@ -363,7 +433,7 @@ async function run() {
363
433
  <body>
364
434
  <div id="app"></div>
365
435
  <script type="module">
366
- import { createSiteApp } from '${pkgDir.replace(/\\/g, '/')}/dist/index.es.js'
436
+ ${bootstrapImport}import { createSiteApp } from '${pkgDir.replace(/\\/g, '/')}/dist/index.es.js'
367
437
  import '${pkgDir.replace(/\\/g, '/')}/dist/style.css'
368
438
  import siteConfig from './${foundConfig}'
369
439
  import { repositoryUrl } from '${VIRTUAL_PACKAGE}'
@@ -390,7 +460,10 @@ import { repositoryUrl } from '${VIRTUAL_PACKAGE}'
390
460
  )
391
461
  server.printUrls()
392
462
  } else {
393
- console.log('Usage: vue-site|vs <dev|build|preview>')
463
+ console.log(
464
+ 'Usage: vue-site|vs <dev|build|preview> [--base=<path>]\n' +
465
+ ' --base Public path for assets (overrides env.vite.base); e.g. --base=/app/',
466
+ )
394
467
  process.exit(1)
395
468
  }
396
469
  }
package/dist/index.es.js CHANGED
@@ -38128,18 +38128,8 @@ const CS = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
38128
38128
  };
38129
38129
  }
38130
38130
  });
38131
- function lA(e) {
38132
- const a = e.trim();
38133
- if (!a) throw new Error("[vue-site] bootstrap path is empty");
38134
- return a.startsWith("/") ? a : "/" + a.replace(/^\.\//, "");
38135
- }
38136
- async function sA(e) {
38137
- if (e.bootstrap == null || String(e.bootstrap).trim() === "") return;
38138
- await import(lA(String(e.bootstrap)));
38139
- }
38140
- async function fA(e) {
38131
+ async function pA(e) {
38141
38132
  var d, h, s, y;
38142
- await sA(e);
38143
38133
  const a = GI(e.nav), c = fS(a), o = ["light", "dark", ...((h = (d = e.theme) == null ? void 0 : d.extraThemes) == null ? void 0 : h.filter((f) => f.id !== "light" && f.id !== "dark").map((f) => f.id)) ?? []], i = bS(e.theme), u = me("light");
38144
38134
  mS(
38145
38135
  u,
@@ -38151,13 +38141,13 @@ async function fA(e) {
38151
38141
  const r = tL(hA);
38152
38142
  return r.provide(XI, u), r.provide(dI, { config: e, resolvedNav: a }), r.use(c), e.configureApp && await Promise.resolve(e.configureApp(r)), r;
38153
38143
  }
38154
- function MA(e) {
38144
+ function kA(e) {
38155
38145
  return e;
38156
38146
  }
38157
38147
  export {
38158
38148
  eI as builtinThemePalettes,
38159
- fA as createSiteApp,
38160
- MA as defineConfig,
38149
+ pA as createSiteApp,
38150
+ kA as defineConfig,
38161
38151
  XI as themeRefKey,
38162
38152
  Rt as useSiteConfig,
38163
38153
  xS as useTheme
package/dist/types.d.ts CHANGED
@@ -97,11 +97,17 @@ export interface SiteConfig {
97
97
  packageRepository?: string | null;
98
98
  /** Development / build environment configuration */
99
99
  env?: SiteEnvConfig;
100
+ /**
101
+ * Same as `env.watchPackages` (CLI only). Used when `env.watchPackages` is omitted.
102
+ */
103
+ watchPackages?: SiteEnvConfig['watchPackages'];
100
104
  /**
101
105
  * Optional. Path to a module under the site root (Vite `root`), loaded once **before** the Vue app
102
106
  * is created. Omit or leave unset to skip. Use for global side effects (polyfills, telemetry,
103
107
  * `window` setup). Relative to root, e.g. `./bootstrap.ts` or `src/bootstrap.ts` (resolved as
104
108
  * `/bootstrap.ts`, `/src/bootstrap.ts`).
109
+ * The `vue-site` CLI injects a static import for this path so it is included in production builds;
110
+ * if you call `createSiteApp` from a custom entry, import that module yourself before mounting.
105
111
  */
106
112
  bootstrap?: string;
107
113
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bndynet/vue-site",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "description": "A configurable Vue 3 site framework with sidebar navigation, markdown rendering, and theme switching.",
6
6
  "repository": {