Skip to content

Commit e94c94a

Browse files
committed
chore: add layer support
1 parent d37aabc commit e94c94a

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineNuxtConfig } from 'nuxt/config'
2+
3+
export default defineNuxtConfig({
4+
modules: [
5+
'@nuxtjs/tailwindcss',
6+
],
7+
css: [],
8+
future: {
9+
compatibilityVersion: 4,
10+
},
11+
})

playground/nuxt.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { defineNuxtConfig } from 'nuxt/config'
22

33
export default defineNuxtConfig({
4+
extends: [
5+
'./layers/theme',
6+
],
47
modules: [
58
'@nuxtjs/tailwindcss',
69
],

src/import-css.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ const getDefaults = (nuxt = useNuxt()) => [
1010

1111
export default async function importCSS(nuxt = useNuxt()) {
1212
const defaultCSSFiles = getDefaults(nuxt)
13-
const resolvedCSSFiles = await Promise.all(nuxt.options.css.map(p => resolvePath(p))).then(arr => arr.reverse())
13+
const resolvedCSSFiles = await Promise.all(nuxt.options.css.map(p => resolvePath(p)))
14+
15+
const layerSourcesTemplate = addTemplate({
16+
filename: 'tailwind/layer-sources.css',
17+
getContents: () => {
18+
return nuxt.options._layers.slice(1).map(layer => `@source ${JSON.stringify(layer.config.srcDir || layer.cwd)};`).join('\n')
19+
},
20+
write: true,
21+
})
1422

1523
const analyzedFiles = await Promise.all([...new Set([...resolvedCSSFiles, ...defaultCSSFiles])].map(async (file) => {
1624
const fileContents = await readFile(file, { encoding: 'utf-8' }).catch(() => '')
@@ -20,12 +28,21 @@ export default async function importCSS(nuxt = useNuxt()) {
2028
const filesImportingTailwind = analyzedFiles.filter(file => file[1].hasImport)
2129

2230
const [file, { isInNuxt } = {}] = filesImportingTailwind.length === 0
23-
? [addTemplate({ filename: 'tailwind.css', getContents: () => `@import 'tailwindcss';`, write: true }).dst]
31+
? [
32+
addTemplate({
33+
filename: 'tailwind.css',
34+
getContents: () => {
35+
return [`@import 'tailwindcss';`, `@import ${JSON.stringify(layerSourcesTemplate.dst)};`].join('\n')
36+
},
37+
write: true,
38+
}).dst,
39+
]
2440
: filesImportingTailwind.find(file => file[1].isInNuxt) || filesImportingTailwind.pop()!
2541

2642
if (!isInNuxt) {
2743
nuxt.options.css.push(file)
2844
}
2945

3046
nuxt.options.alias['#tailwind'] = file
47+
nuxt.options.alias['#tailwind-layer-sources'] = layerSourcesTemplate.dst
3148
}

src/install-plugin.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ export default async function installPlugin(nuxt = useNuxt()) {
1212

1313
if (!existsTailwindPlugin()) {
1414
await import('@tailwindcss/vite').then(r => addVitePlugin(r.default()))
15-
} else {
16-
console.log('already installed')
1715
}
1816
}
1917
else {

0 commit comments

Comments
 (0)