Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/import-css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@ const getDefaults = (nuxtConfig: NuxtConfig & { srcDir: string }) => [
].map(defaultPath => join(nuxtConfig.srcDir, nuxtConfig.dir?.assets || 'assets', defaultPath))

export default async function importCSS(nuxt = useNuxt()) {
const sources = nuxt.options._layers.map(layer => layer.config.srcDir || layer.cwd)
const sources = nuxt.options._layers.map(layer => JSON.stringify(layer.config.srcDir || layer.cwd))

// Add variables from Nuxt config that need parsing
const sourceConfigs = [
nuxt.options.app?.head?.htmlAttrs?.class,
nuxt.options.app?.head?.bodyAttrs?.class,
]
sourceConfigs.forEach((value) => {
if (value) sources.push(`inline(${JSON.stringify(value)})`)
})

await nuxt.callHook('tailwindcss:sources:extend', sources)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry it took me a while, I was thinking about this hook as passing JSON.stringified strings here would have severe effects. Let me think of some ideas and apply onto this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand! But worth noting that I didn't add this call to JSON.stringify: it was already in the codebase and I moved it.

I had to move it here so that only the bit between () was stringified rather than the whole string.


const sourcesTemplate = addTemplate({
filename: 'tailwindcss/sources.css',
getContents: () => sources.map(source => `@source ${JSON.stringify(source)};`).join('\n'),
getContents: () => sources.map(source => `@source ${source};`).join('\n'),
write: true,
})

Expand Down