Skip to content

Commit

Permalink
Convert preflight to plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwathan committed Feb 7, 2019
1 parent 76c40e4 commit 690c7f2
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 67 deletions.
2 changes: 1 addition & 1 deletion __tests__/fixtures/tailwind-input.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@tailwind preflight;
@tailwind base;

@tailwind components;

Expand Down
2 changes: 1 addition & 1 deletion preflight.css
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@tailwind preflight;
@tailwind base;
112 changes: 58 additions & 54 deletions src/corePlugins.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import preflight from './plugins/preflight'
import lists from './plugins/lists'
import appearance from './plugins/appearance'
import backgroundAttachment from './plugins/backgroundAttachment'
Expand Down Expand Up @@ -52,7 +53,7 @@ import zIndex from './plugins/zIndex'
import _ from 'lodash'
import configurePlugins from './util/configurePlugins'

function loadPlugins({ theme, variants, corePlugins }, plugins) {
function loadUtilityPlugins({ theme, variants, corePlugins: userCorePluginConfig }, plugins) {
const defaultCorePluginConfig = _.fromPairs(
Object.keys(plugins).map(plugin => [
plugin,
Expand All @@ -63,60 +64,63 @@ function loadPlugins({ theme, variants, corePlugins }, plugins) {
])
)

return configurePlugins(plugins, corePlugins, defaultCorePluginConfig)
return configurePlugins(plugins, userCorePluginConfig, defaultCorePluginConfig)
}

export default function(config) {
return loadPlugins(config, {
lists,
appearance,
backgroundAttachment,
backgroundColors,
backgroundPosition,
backgroundRepeat,
backgroundSize,
borderCollapse,
borderColors,
borderRadius,
borderStyle,
borderWidths,
cursor,
display,
flexbox,
float,
fonts,
fontWeights,
height,
leading,
margin,
maxHeight,
maxWidth,
minHeight,
minWidth,
negativeMargin,
objectFit,
objectPosition,
opacity,
outline,
overflow,
padding,
pointerEvents,
position,
resize,
shadows,
svgFill,
svgStroke,
tableLayout,
textAlign,
textColors,
textSizes,
textStyle,
tracking,
userSelect,
verticalAlign,
visibility,
whitespace,
width,
zIndex,
})
return [
preflight(),
...loadUtilityPlugins(config, {
lists,
appearance,
backgroundAttachment,
backgroundColors,
backgroundPosition,
backgroundRepeat,
backgroundSize,
borderCollapse,
borderColors,
borderRadius,
borderStyle,
borderWidths,
cursor,
display,
flexbox,
float,
fonts,
fontWeights,
height,
leading,
margin,
maxHeight,
maxWidth,
minHeight,
minWidth,
negativeMargin,
objectFit,
objectPosition,
opacity,
outline,
overflow,
padding,
pointerEvents,
position,
resize,
shadows,
svgFill,
svgStroke,
tableLayout,
textAlign,
textColors,
textSizes,
textStyle,
tracking,
userSelect,
verticalAlign,
visibility,
whitespace,
width,
zIndex,
}),
]
}
10 changes: 0 additions & 10 deletions src/lib/substituteTailwindAtRules.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from 'fs'
import _ from 'lodash'
import postcss from 'postcss'

Expand All @@ -14,15 +13,6 @@ export default function(
) {
return function(css) {
css.walkAtRules('tailwind', atRule => {
if (atRule.params === 'preflight') {
const preflightTree = postcss.parse(
fs.readFileSync(`${__dirname}/../../css/preflight.css`, 'utf8')
)

atRule.before(updateSource(preflightTree, atRule.source))
atRule.remove()
}

if (atRule.params === 'base') {
atRule.before(updateSource(pluginBase, atRule.source))
atRule.remove()
Expand Down
11 changes: 11 additions & 0 deletions src/plugins/preflight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import fs from 'fs'
import postcss from 'postcss'

export default function() {
return function({ addBase }) {
const preflightStyles = postcss.parse(
fs.readFileSync(`${__dirname}/../../css/preflight.css`, 'utf8')
)
addBase(preflightStyles.nodes)
}
}
2 changes: 1 addition & 1 deletion tailwind.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@tailwind preflight;
@tailwind base;

@tailwind components;

Expand Down

0 comments on commit 690c7f2

Please sign in to comment.