@bndynet/vue-site 0.1.4 → 0.1.6

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 CHANGED
@@ -158,16 +158,35 @@ function readPackageRepositoryUrl() {
158
158
  return tryReadRepositoryFromDir(cwd)
159
159
  }
160
160
 
161
- const entryCode = [
162
- `import { createSiteApp } from '${pkgDir.replace(/\\/g, '/')}/dist/index.es.js'`,
163
- `import '${pkgDir.replace(/\\/g, '/')}/dist/style.css'`,
164
- `import siteConfig from '/${foundConfig}'`,
165
- `import { repositoryUrl } from '${VIRTUAL_PACKAGE}'`,
166
- `;(async () => {`,
167
- ` const app = await createSiteApp({ ...siteConfig, packageRepository: repositoryUrl })`,
168
- ` app.mount('#app')`,
169
- `})()`,
170
- ].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 'element-plus/dist/index.css'`,
179
+ `import 'element-plus/theme-chalk/dark/css-vars.css'`,
180
+ `import { createSiteApp } from '${pkgDir.replace(/\\/g, '/')}/dist/index.es.js'`,
181
+ `import '${pkgDir.replace(/\\/g, '/')}/dist/style.css'`,
182
+ `import siteConfig from '/${foundConfig}'`,
183
+ `import { repositoryUrl } from '${VIRTUAL_PACKAGE}'`,
184
+ `;(async () => {`,
185
+ ` const app = await createSiteApp({ ...siteConfig, packageRepository: repositoryUrl })`,
186
+ ` app.mount('#app')`,
187
+ `})()`,
188
+ ].join('\n')
189
+ }
171
190
 
172
191
  const htmlTemplate = `<!DOCTYPE html>
173
192
  <html lang="en">
@@ -215,7 +234,7 @@ async function loadSiteConfig() {
215
234
  }
216
235
  }
217
236
 
218
- function vueSitePlugin() {
237
+ function vueSitePlugin(entryCode) {
219
238
  return [
220
239
  {
221
240
  name: 'vue-site:virtual-entry',
@@ -254,8 +273,8 @@ function vueSitePlugin() {
254
273
  }
255
274
 
256
275
  async function buildViteConfig(options = {}) {
257
- const { cliBase } = options
258
- const siteConfig = await loadSiteConfig()
276
+ const { cliBase, siteConfig: siteConfigOption } = options
277
+ const siteConfig = siteConfigOption ?? (await loadSiteConfig())
259
278
  const env = siteConfig.env || {}
260
279
  const {
261
280
  port,
@@ -358,9 +377,11 @@ async function buildViteConfig(options = {}) {
358
377
  }
359
378
  }
360
379
 
380
+ const entryCode = buildEntryCode(siteConfig)
381
+
361
382
  const baseConfig = {
362
383
  root: cwd,
363
- plugins: [vue(vueOpts), ...vueSitePlugin(), ...(userPlugins || [])],
384
+ plugins: [vue(vueOpts), ...vueSitePlugin(entryCode), ...(userPlugins || [])],
364
385
  resolve: {
365
386
  alias: {
366
387
  vue: resolve(vuePath, 'dist/vue.runtime.esm-bundler.js'),
@@ -386,7 +407,8 @@ async function buildViteConfig(options = {}) {
386
407
 
387
408
  async function run() {
388
409
  const { command, cliBase } = parseCliArgv()
389
- const viteConfig = await buildViteConfig({ cliBase })
410
+ const siteConfig = await loadSiteConfig()
411
+ const viteConfig = await buildViteConfig({ cliBase, siteConfig })
390
412
 
391
413
  if (command === 'dev') {
392
414
  const server = await createServer(viteConfig)
@@ -398,6 +420,11 @@ async function run() {
398
420
  const hadHtml = fs.existsSync(tempHtml)
399
421
 
400
422
  if (!hadHtml) {
423
+ const bs = siteConfig?.bootstrap
424
+ const bootstrapImport =
425
+ bs != null && String(bs).trim() !== ''
426
+ ? `import '${resolveBootstrapUrl(bs)}'\n`
427
+ : ''
401
428
  const buildHtml = `<!DOCTYPE html>
402
429
  <html lang="en">
403
430
  <head>
@@ -408,6 +435,8 @@ async function run() {
408
435
  <body>
409
436
  <div id="app"></div>
410
437
  <script type="module">
438
+ ${bootstrapImport}import 'element-plus/dist/index.css'
439
+ import 'element-plus/theme-chalk/dark/css-vars.css'
411
440
  import { createSiteApp } from '${pkgDir.replace(/\\/g, '/')}/dist/index.es.js'
412
441
  import '${pkgDir.replace(/\\/g, '/')}/dist/style.css'
413
442
  import siteConfig from './${foundConfig}'
@@ -7,8 +7,9 @@ export declare const themeRefKey: InjectionKey<Ref<string>>;
7
7
  * @param themeIds — full list of allowed ids (built-in `light`/`dark` plus any `extraThemes`)
8
8
  * @param palettes — resolved CSS variable maps per id
9
9
  * @param overlay — optional `:root` overrides applied after the active palette
10
+ * @param darkThemeIds — set of theme ids considered "dark" (toggles `html.dark` for Element Plus)
10
11
  */
11
- export declare function initTheme(themeRef: Ref<string>, defaultMode?: string, themeIds?: readonly string[], palettes?: Record<string, Record<string, string>>, overlay?: Record<string, string>): void;
12
+ export declare function initTheme(themeRef: Ref<string>, defaultMode?: string, themeIds?: readonly string[], palettes?: Record<string, Record<string, string>>, overlay?: Record<string, string>, darkThemeIds?: ReadonlySet<string>): void;
12
13
  export declare function useTheme(): {
13
14
  theme: Ref<string, string>;
14
15
  setTheme: (mode: string) => void;
package/dist/index.d.ts CHANGED
@@ -3,5 +3,6 @@ export { createSiteApp } from './create-app';
3
3
  export { useTheme, themeRefKey } from './composables/useTheme';
4
4
  export { useSiteConfig } from './composables/useSiteConfig';
5
5
  export { builtinThemePalettes } from './theme/presets';
6
+ export { ElMessage, ElMessageBox, ElNotification, } from 'element-plus';
6
7
  export type { SiteConfig, SiteEnvConfig, SiteViteConfig, SiteExternalLink, NavItem, ThemeConfig, ThemeOption, ThemePaletteVars, ResolvedNavItem, } from './types';
7
8
  export declare function defineConfig(config: SiteConfig): SiteConfig;