Skip to content

Commit

Permalink
ensure we can use @import 'tailwindcss/...' without node_modules
Browse files Browse the repository at this point in the history
This is useful if you are using `npx tailwindcs ...` and to prevent
that postcss-import crashes on the tailwind specific imports which we
will replace anyway.
  • Loading branch information
RobinMalfait committed Jun 7, 2022
1 parent ac91c6a commit e68b922
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,17 +568,40 @@ async function build() {

tailwindPlugin.postcss = true

let IMPORT_COMMENT = '__TAILWIND_RESTORE_IMPORT__: '

let [beforePlugins, afterPlugins, postcssOptions] = includePostCss
? await loadPostCssPlugins()
: [
[
(root) => {
root.walkAtRules('import', (rule) => {
if (rule.params.slice(1).startsWith('tailwindcss/')) {
rule.after(postcss.comment({ text: IMPORT_COMMENT + rule.params }))
rule.remove()
}
})
},
(() => {
try {
return require('postcss-import')
} catch {}

return lazyPostcssImport()
})(),
(root) => {
root.walkComments((rule) => {
if (!rule.text.startsWith(IMPORT_COMMENT)) {
rule.after(
postcss.atRule({
name: 'import',
params: rule.text.replace(IMPORT_COMMENT, ''),
})
)
rule.remove()
}
})
},
],
[],
{},
Expand Down

0 comments on commit e68b922

Please sign in to comment.