@bndynet/vue-site 0.1.4 → 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/bin/vue-site.mjs +41 -16
- package/dist/index.es.js +4 -14
- package/dist/types.d.ts +6 -0
- package/package.json +1 -1
package/bin/vue-site.mjs
CHANGED
|
@@ -158,16 +158,33 @@ function readPackageRepositoryUrl() {
|
|
|
158
158
|
return tryReadRepositoryFromDir(cwd)
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
+
}
|
|
171
188
|
|
|
172
189
|
const htmlTemplate = `<!DOCTYPE html>
|
|
173
190
|
<html lang="en">
|
|
@@ -215,7 +232,7 @@ async function loadSiteConfig() {
|
|
|
215
232
|
}
|
|
216
233
|
}
|
|
217
234
|
|
|
218
|
-
function vueSitePlugin() {
|
|
235
|
+
function vueSitePlugin(entryCode) {
|
|
219
236
|
return [
|
|
220
237
|
{
|
|
221
238
|
name: 'vue-site:virtual-entry',
|
|
@@ -254,8 +271,8 @@ function vueSitePlugin() {
|
|
|
254
271
|
}
|
|
255
272
|
|
|
256
273
|
async function buildViteConfig(options = {}) {
|
|
257
|
-
const { cliBase } = options
|
|
258
|
-
const siteConfig = await loadSiteConfig()
|
|
274
|
+
const { cliBase, siteConfig: siteConfigOption } = options
|
|
275
|
+
const siteConfig = siteConfigOption ?? (await loadSiteConfig())
|
|
259
276
|
const env = siteConfig.env || {}
|
|
260
277
|
const {
|
|
261
278
|
port,
|
|
@@ -358,9 +375,11 @@ async function buildViteConfig(options = {}) {
|
|
|
358
375
|
}
|
|
359
376
|
}
|
|
360
377
|
|
|
378
|
+
const entryCode = buildEntryCode(siteConfig)
|
|
379
|
+
|
|
361
380
|
const baseConfig = {
|
|
362
381
|
root: cwd,
|
|
363
|
-
plugins: [vue(vueOpts), ...vueSitePlugin(), ...(userPlugins || [])],
|
|
382
|
+
plugins: [vue(vueOpts), ...vueSitePlugin(entryCode), ...(userPlugins || [])],
|
|
364
383
|
resolve: {
|
|
365
384
|
alias: {
|
|
366
385
|
vue: resolve(vuePath, 'dist/vue.runtime.esm-bundler.js'),
|
|
@@ -386,7 +405,8 @@ async function buildViteConfig(options = {}) {
|
|
|
386
405
|
|
|
387
406
|
async function run() {
|
|
388
407
|
const { command, cliBase } = parseCliArgv()
|
|
389
|
-
const
|
|
408
|
+
const siteConfig = await loadSiteConfig()
|
|
409
|
+
const viteConfig = await buildViteConfig({ cliBase, siteConfig })
|
|
390
410
|
|
|
391
411
|
if (command === 'dev') {
|
|
392
412
|
const server = await createServer(viteConfig)
|
|
@@ -398,6 +418,11 @@ async function run() {
|
|
|
398
418
|
const hadHtml = fs.existsSync(tempHtml)
|
|
399
419
|
|
|
400
420
|
if (!hadHtml) {
|
|
421
|
+
const bs = siteConfig?.bootstrap
|
|
422
|
+
const bootstrapImport =
|
|
423
|
+
bs != null && String(bs).trim() !== ''
|
|
424
|
+
? `import '${resolveBootstrapUrl(bs)}'\n`
|
|
425
|
+
: ''
|
|
401
426
|
const buildHtml = `<!DOCTYPE html>
|
|
402
427
|
<html lang="en">
|
|
403
428
|
<head>
|
|
@@ -408,7 +433,7 @@ async function run() {
|
|
|
408
433
|
<body>
|
|
409
434
|
<div id="app"></div>
|
|
410
435
|
<script type="module">
|
|
411
|
-
import { createSiteApp } from '${pkgDir.replace(/\\/g, '/')}/dist/index.es.js'
|
|
436
|
+
${bootstrapImport}import { createSiteApp } from '${pkgDir.replace(/\\/g, '/')}/dist/index.es.js'
|
|
412
437
|
import '${pkgDir.replace(/\\/g, '/')}/dist/style.css'
|
|
413
438
|
import siteConfig from './${foundConfig}'
|
|
414
439
|
import { repositoryUrl } from '${VIRTUAL_PACKAGE}'
|
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
|
|
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
|
|
38144
|
+
function kA(e) {
|
|
38155
38145
|
return e;
|
|
38156
38146
|
}
|
|
38157
38147
|
export {
|
|
38158
38148
|
eI as builtinThemePalettes,
|
|
38159
|
-
|
|
38160
|
-
|
|
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
|
/**
|