@bndynet/vue-site 0.1.7 → 0.1.9

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.
Files changed (2) hide show
  1. package/bin/vue-site.mjs +48 -16
  2. package/package.json +1 -1
package/bin/vue-site.mjs CHANGED
@@ -301,6 +301,11 @@ async function buildViteConfig(options = {}) {
301
301
  }
302
302
  }
303
303
 
304
+ // Absolute source root directories for packages using entryPath, used by the
305
+ // scss-raw plugin below to prevent Vite's module cache from returning an
306
+ // already-transformed JS module to Sass on a second resolution of the same file.
307
+ const watchedSourceRoots = []
308
+
304
309
  if (watchPackages.length) {
305
310
  const excludeNames = []
306
311
  const watchPatterns = []
@@ -324,6 +329,9 @@ async function buildViteConfig(options = {}) {
324
329
  const dirForGlob = entryDir.replace(/\\/g, '/')
325
330
  watchPatterns.push(`!${dirForGlob}/**`)
326
331
  fsAllowPaths.push(entryDir)
332
+ // Track the package root (parent of entryDir) so SCSS imports that use
333
+ // paths like '../styles/foo.scss' are also covered.
334
+ watchedSourceRoots.push(dirname(entryDir))
327
335
  }
328
336
  }
329
337
 
@@ -379,9 +387,41 @@ async function buildViteConfig(options = {}) {
379
387
 
380
388
  const entryCode = buildEntryCode(siteConfig)
381
389
 
390
+ // When watchPackages uses entryPath, SCSS files imported inside the watched
391
+ // package source (e.g. Lit web components with `import styles from './foo.scss'`
392
+ // used alongside `unsafeCSS()`) need to be exported as a CSS string, not
393
+ // injected as a side-effect. Vite only does this for `?inline` imports.
394
+ // This pre-plugin intercepts .scss/.sass imports whose importer lives inside a
395
+ // watched source root and transparently adds `?inline`, so Vite compiles the
396
+ // SCSS through Sass and returns `export default "...css..."`.
397
+ const watchedScssPlugin =
398
+ watchedSourceRoots.length > 0
399
+ ? [
400
+ {
401
+ name: 'vue-site:watched-scss-inline',
402
+ enforce: 'pre',
403
+ async resolveId(source, importer) {
404
+ if (!importer) return
405
+ const cleanImporter = importer.split('?')[0]
406
+ const cleanSource = source.split('?')[0]
407
+ if (
408
+ (cleanSource.endsWith('.scss') || cleanSource.endsWith('.sass')) &&
409
+ !source.includes('?') &&
410
+ watchedSourceRoots.some((root) => cleanImporter.startsWith(root))
411
+ ) {
412
+ const resolved = await this.resolve(source, importer, { skipSelf: true })
413
+ if (resolved && !resolved.external) {
414
+ return { id: resolved.id + '?inline' }
415
+ }
416
+ }
417
+ },
418
+ },
419
+ ]
420
+ : []
421
+
382
422
  const baseConfig = {
383
423
  root: cwd,
384
- plugins: [vue(vueOpts), ...vueSitePlugin(entryCode), ...(userPlugins || [])],
424
+ plugins: [vue(vueOpts), ...watchedScssPlugin, ...vueSitePlugin(entryCode), ...(userPlugins || [])],
385
425
  resolve: {
386
426
  alias: {
387
427
  vue: resolve(vuePath, 'dist/vue.runtime.esm-bundler.js'),
@@ -389,21 +429,13 @@ async function buildViteConfig(options = {}) {
389
429
  },
390
430
  },
391
431
  optimizeDeps: {
392
- // dayjs ships a UMD browser build (dayjs.min.js) which has no ESM default
393
- // export. Listing it here forces Vite to pre-bundle it into a proper ESM
394
- // module before the browser requests it preventing the
395
- // "does not provide an export named 'default'" SyntaxError from Element Plus.
396
- include: [
397
- 'dayjs',
398
- 'dayjs/plugin/localeData',
399
- 'dayjs/plugin/advancedFormat',
400
- 'dayjs/plugin/customParseFormat',
401
- 'dayjs/plugin/weekOfYear',
402
- 'dayjs/plugin/weekYear',
403
- 'dayjs/plugin/dayOfYear',
404
- 'dayjs/plugin/isSameOrAfter',
405
- 'dayjs/plugin/isSameOrBefore',
406
- ],
432
+ // Pre-bundle element-plus so Vite crawls its dependency graph and
433
+ // discovers dayjs (a CJS/UMD package with no ESM default export).
434
+ // Without this, dayjs.min.js is served raw to the browser and
435
+ // Element Plus throws "does not provide an export named 'default'".
436
+ // The virtual entry only imports element-plus CSS, so Vite's static
437
+ // analysis never sees the JS side — this include bridges that gap.
438
+ include: ['element-plus'],
407
439
  },
408
440
  server: {
409
441
  open: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bndynet/vue-site",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "type": "module",
5
5
  "description": "A configurable Vue 3 site framework with sidebar navigation, markdown rendering, and theme switching.",
6
6
  "repository": {