Skip to content

Commit

Permalink
fix: content paths when content is array
Browse files Browse the repository at this point in the history
layouts and components paths were not being preserved if user defined a custom array of content paths in their tailwind.config.js
  • Loading branch information
cossssmin committed Mar 21, 2023
1 parent 4ded6b0 commit 0641846
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
20 changes: 13 additions & 7 deletions src/generators/tailwindcss.js
Expand Up @@ -34,25 +34,31 @@ module.exports = {
const layoutsRoot = get(config, 'build.layouts.root')
const componentsRoot = get(config, 'build.components.root')

const layoutsPath = typeof layoutsRoot === 'string' && layoutsRoot ?
`${layoutsRoot}/**/*.html`.replace(/\/\//g, '/') :
'./src/layouts/**/*.html'

const componentsPath = typeof componentsRoot === 'string' && componentsRoot ?
`${componentsRoot}/**/*.html`.replace(/\/\//g, '/') :
'./src/components/**/*.html'

const tailwindConfig = merge({
important: true,
content: {
files: [
typeof layoutsRoot === 'string' && layoutsRoot ?
`${layoutsRoot}/**/*.html`.replace(/\/\//g, '/') :
'./src/layouts/**/*.html',
typeof componentsRoot === 'string' && componentsRoot ?
`${componentsRoot}/**/*.html`.replace(/\/\//g, '/') :
'./src/components/**/*.html',
layoutsPath,
componentsPath,
{raw: html, extension: 'html'}
]
}
}, userConfig(config))

// Add back the `{raw: html}` option if user provided own config
// If `content` is an array, add it to `content.files`
if (Array.isArray(tailwindConfig.content)) {
tailwindConfig.content = {
files: [
layoutsPath,
componentsPath,
...tailwindConfig.content,
{raw: html, extension: 'html'}
]
Expand Down
4 changes: 2 additions & 2 deletions test/expected/components/backwards-compatibility.html
@@ -1,6 +1,6 @@
<p>Variable from attribute: Example</p>
<p class="flex">Variable from attribute: Example</p>
<p>Variable from locals attribute: bar</p>
<p class="hidden">Variable from page: maizzle-ci</p>
<p>Variable from attribute: Nested component</p>
<p class="flex">Variable from attribute: Nested component</p>
<p>Variable from locals attribute: bar (nested)</p>
<p>Variable from page (nested): maizzle-ci</p>
2 changes: 1 addition & 1 deletion test/stubs/components/component.html
Expand Up @@ -5,7 +5,7 @@
}
</script>

<p>Variable from attribute: [[ text ]]</p>
<p class="flex">Variable from attribute: [[ text ]]</p>

<p>Variable from locals attribute: [[ foo ]]</p>

Expand Down
38 changes: 38 additions & 0 deletions test/test-tailwindcss.js
Expand Up @@ -146,3 +146,41 @@ test('respects `shorthandCSS` in maizzle config', async t => {
'.padded{padding:1.5rem1rem}'
)
})

test('works with custom `layouts.root`', async t => {
const css = await Tailwind.compile({
config: {
build: {
layouts: {
root: './test/stubs/layouts'
},
tailwind: {
config: {
content: ['./test/stubs/tailwind/*.html']
}
}
}
}
})

t.true(css.includes('.bg-red-500'))
})

test('works with custom `components.root`', async t => {
const css = await Tailwind.compile({
config: {
build: {
components: {
root: './test/stubs/components'
},
tailwind: {
config: {
content: ['./test/stubs/tailwind/*.html']
}
}
}
}
})

t.true(css.includes('.flex'))
})

0 comments on commit 0641846

Please sign in to comment.