Skip to content

Commit 690c7f2

Browse files
committed
Convert preflight to plugin
1 parent 76c40e4 commit 690c7f2

6 files changed

Lines changed: 72 additions & 67 deletions

File tree

__tests__/fixtures/tailwind-input.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@tailwind preflight;
1+
@tailwind base;
22

33
@tailwind components;
44

preflight.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
@tailwind preflight;
1+
@tailwind base;

src/corePlugins.js

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import preflight from './plugins/preflight'
12
import lists from './plugins/lists'
23
import appearance from './plugins/appearance'
34
import backgroundAttachment from './plugins/backgroundAttachment'
@@ -52,7 +53,7 @@ import zIndex from './plugins/zIndex'
5253
import _ from 'lodash'
5354
import configurePlugins from './util/configurePlugins'
5455

55-
function loadPlugins({ theme, variants, corePlugins }, plugins) {
56+
function loadUtilityPlugins({ theme, variants, corePlugins: userCorePluginConfig }, plugins) {
5657
const defaultCorePluginConfig = _.fromPairs(
5758
Object.keys(plugins).map(plugin => [
5859
plugin,
@@ -63,60 +64,63 @@ function loadPlugins({ theme, variants, corePlugins }, plugins) {
6364
])
6465
)
6566

66-
return configurePlugins(plugins, corePlugins, defaultCorePluginConfig)
67+
return configurePlugins(plugins, userCorePluginConfig, defaultCorePluginConfig)
6768
}
6869

6970
export default function(config) {
70-
return loadPlugins(config, {
71-
lists,
72-
appearance,
73-
backgroundAttachment,
74-
backgroundColors,
75-
backgroundPosition,
76-
backgroundRepeat,
77-
backgroundSize,
78-
borderCollapse,
79-
borderColors,
80-
borderRadius,
81-
borderStyle,
82-
borderWidths,
83-
cursor,
84-
display,
85-
flexbox,
86-
float,
87-
fonts,
88-
fontWeights,
89-
height,
90-
leading,
91-
margin,
92-
maxHeight,
93-
maxWidth,
94-
minHeight,
95-
minWidth,
96-
negativeMargin,
97-
objectFit,
98-
objectPosition,
99-
opacity,
100-
outline,
101-
overflow,
102-
padding,
103-
pointerEvents,
104-
position,
105-
resize,
106-
shadows,
107-
svgFill,
108-
svgStroke,
109-
tableLayout,
110-
textAlign,
111-
textColors,
112-
textSizes,
113-
textStyle,
114-
tracking,
115-
userSelect,
116-
verticalAlign,
117-
visibility,
118-
whitespace,
119-
width,
120-
zIndex,
121-
})
71+
return [
72+
preflight(),
73+
...loadUtilityPlugins(config, {
74+
lists,
75+
appearance,
76+
backgroundAttachment,
77+
backgroundColors,
78+
backgroundPosition,
79+
backgroundRepeat,
80+
backgroundSize,
81+
borderCollapse,
82+
borderColors,
83+
borderRadius,
84+
borderStyle,
85+
borderWidths,
86+
cursor,
87+
display,
88+
flexbox,
89+
float,
90+
fonts,
91+
fontWeights,
92+
height,
93+
leading,
94+
margin,
95+
maxHeight,
96+
maxWidth,
97+
minHeight,
98+
minWidth,
99+
negativeMargin,
100+
objectFit,
101+
objectPosition,
102+
opacity,
103+
outline,
104+
overflow,
105+
padding,
106+
pointerEvents,
107+
position,
108+
resize,
109+
shadows,
110+
svgFill,
111+
svgStroke,
112+
tableLayout,
113+
textAlign,
114+
textColors,
115+
textSizes,
116+
textStyle,
117+
tracking,
118+
userSelect,
119+
verticalAlign,
120+
visibility,
121+
whitespace,
122+
width,
123+
zIndex,
124+
}),
125+
]
122126
}

src/lib/substituteTailwindAtRules.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import fs from 'fs'
21
import _ from 'lodash'
32
import postcss from 'postcss'
43

@@ -14,15 +13,6 @@ export default function(
1413
) {
1514
return function(css) {
1615
css.walkAtRules('tailwind', atRule => {
17-
if (atRule.params === 'preflight') {
18-
const preflightTree = postcss.parse(
19-
fs.readFileSync(`${__dirname}/../../css/preflight.css`, 'utf8')
20-
)
21-
22-
atRule.before(updateSource(preflightTree, atRule.source))
23-
atRule.remove()
24-
}
25-
2616
if (atRule.params === 'base') {
2717
atRule.before(updateSource(pluginBase, atRule.source))
2818
atRule.remove()

src/plugins/preflight.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import fs from 'fs'
2+
import postcss from 'postcss'
3+
4+
export default function() {
5+
return function({ addBase }) {
6+
const preflightStyles = postcss.parse(
7+
fs.readFileSync(`${__dirname}/../../css/preflight.css`, 'utf8')
8+
)
9+
addBase(preflightStyles.nodes)
10+
}
11+
}

tailwind.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@tailwind preflight;
1+
@tailwind base;
22

33
@tailwind components;
44

0 commit comments

Comments
 (0)