Skip to content

Commit 720df99

Browse files
authored
Merge pull request #1336 from tailwindcss/support-import-syntax
Support import syntax even if not using postcss-import
2 parents bd1d0e1 + 08c6911 commit 720df99

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@import "tailwindcss/base";
2+
3+
@import 'tailwindcss/components';
4+
5+
@import "tailwindcss/utilities";
6+
7+
@responsive {
8+
.example {
9+
@apply .font-bold;
10+
color: theme('colors.red.500');
11+
}
12+
}

__tests__/sanity.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ it('generates the right CSS when "important" is enabled', () => {
3636
})
3737
})
3838

39+
it('generates the right CSS when using @import instead of @tailwind', () => {
40+
const inputPath = path.resolve(`${__dirname}/fixtures/tailwind-input-import.css`)
41+
const input = fs.readFileSync(inputPath, 'utf8')
42+
43+
return postcss([tailwind()])
44+
.process(input, { from: inputPath })
45+
.then(result => {
46+
const expected = fs.readFileSync(
47+
path.resolve(`${__dirname}/fixtures/tailwind-output.css`),
48+
'utf8'
49+
)
50+
51+
expect(result.css).toBe(expected)
52+
})
53+
})
54+
3955
it('does not add any CSS if no Tailwind features are used', () => {
4056
return postcss([tailwind()])
4157
.process('.foo { color: blue; }', { from: undefined })

src/lib/substituteTailwindAtRules.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,34 @@ export default function(
1212
{ base: pluginBase, components: pluginComponents, utilities: pluginUtilities }
1313
) {
1414
return function(css) {
15+
css.walkAtRules('import', atRule => {
16+
if (atRule.params === '"tailwindcss/base"' || atRule.params === "'tailwindcss/base'") {
17+
atRule.name = 'tailwind'
18+
atRule.params = 'base'
19+
}
20+
21+
if (
22+
atRule.params === '"tailwindcss/components"' ||
23+
atRule.params === "'tailwindcss/components'"
24+
) {
25+
atRule.name = 'tailwind'
26+
atRule.params = 'components'
27+
}
28+
29+
if (
30+
atRule.params === '"tailwindcss/utilities"' ||
31+
atRule.params === "'tailwindcss/utilities'"
32+
) {
33+
atRule.name = 'tailwind'
34+
atRule.params = 'utilities'
35+
}
36+
37+
if (atRule.params === '"tailwindcss/screens"' || atRule.params === "'tailwindcss/screens'") {
38+
atRule.name = 'tailwind'
39+
atRule.params = 'screens'
40+
}
41+
})
42+
1543
css.walkAtRules('tailwind', atRule => {
1644
if (atRule.params === 'preflight') {
1745
// prettier-ignore

0 commit comments

Comments
 (0)