veslx 0.1.29 → 0.1.30

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veslx",
3
- "version": "0.1.29",
3
+ "version": "0.1.30",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -281,33 +281,15 @@ export default function contentPlugin(contentDir: string, config?: VeslxConfig,
281
281
  next()
282
282
  }
283
283
 
284
+ // Virtual module ID for the modified CSS
285
+ const VIRTUAL_CSS_MODULE = '\0veslx:index.css'
286
+
284
287
  return {
285
288
  name: 'content',
286
289
  enforce: 'pre',
287
290
 
288
- // Inject @source directive for Tailwind to scan content directory for classes
289
- transform(code, id) {
290
- // Only process CSS files containing the tailwindcss import
291
- if (!id.endsWith('.css')) return null
292
- if (!code.includes('@import "tailwindcss"')) return null
293
-
294
- // Calculate relative path from CSS file to content directory
295
- const cssDir = path.dirname(id)
296
- let relativeContentDir = path.relative(cssDir, dir)
297
- relativeContentDir = relativeContentDir.replace(/\\/g, '/') // Windows compatibility
298
-
299
- // Inject @source directive after the tailwindcss import
300
- const sourceDirective = `@source "${relativeContentDir}";`
301
- const modified = code.replace(
302
- /(@import\s+["']tailwindcss["'];?)/,
303
- `$1\n${sourceDirective}`
304
- )
305
-
306
- return { code: modified, map: null }
307
- },
308
-
309
291
  // Inject @content alias and fs.allow into Vite config
310
- config() {
292
+ config(config, { command }) {
311
293
  return {
312
294
  resolve: {
313
295
  alias: {
@@ -325,8 +307,18 @@ export default function contentPlugin(contentDir: string, config?: VeslxConfig,
325
307
  }
326
308
  },
327
309
 
328
- // Virtual modules for content MDX imports and site config
329
- resolveId(id) {
310
+ // Intercept CSS and virtual module imports
311
+ resolveId(id, importer) {
312
+ // Intercept index.css imported from main.tsx and redirect to our virtual module
313
+ // This allows us to inject @source directive for Tailwind to scan user content
314
+ if (id === './index.css' && importer?.endsWith('/src/main.tsx')) {
315
+ return VIRTUAL_CSS_MODULE
316
+ }
317
+ // Also catch the resolved path
318
+ if (id.endsWith('/src/index.css') && !id.startsWith('\0')) {
319
+ return VIRTUAL_CSS_MODULE
320
+ }
321
+ // Virtual modules for content
330
322
  if (id === VIRTUAL_MODULE_ID) {
331
323
  return RESOLVED_VIRTUAL_MODULE_ID
332
324
  }
@@ -336,6 +328,28 @@ export default function contentPlugin(contentDir: string, config?: VeslxConfig,
336
328
  },
337
329
 
338
330
  load(id) {
331
+ // Serve the modified CSS content with @source directive
332
+ // This enables Tailwind v4 to scan the user's content directory for classes
333
+ if (id === VIRTUAL_CSS_MODULE) {
334
+ // Read the original CSS
335
+ const veslxRoot = path.dirname(path.dirname(__dirname))
336
+ const cssPath = path.join(veslxRoot, 'src/index.css')
337
+ const cssContent = fs.readFileSync(cssPath, 'utf-8')
338
+
339
+ // Use absolute path for @source directive
340
+ const absoluteContentDir = dir.replace(/\\/g, '/')
341
+
342
+ // Inject @source directive after the tailwindcss import
343
+ const sourceDirective = `@source "${absoluteContentDir}";`
344
+ const modified = cssContent.replace(
345
+ /(@import\s+["']tailwindcss["'];?)/,
346
+ `$1\n${sourceDirective}`
347
+ )
348
+
349
+ return modified
350
+ }
351
+
352
+ // Virtual module for content
339
353
  if (id === RESOLVED_VIRTUAL_MODULE_ID) {
340
354
  // Extract frontmatter from MDX files at build time (avoids MDX hook issues)
341
355
  const frontmatterData = extractFrontmatters(dir);