Skip to content

Commit d81edb7

Browse files
committed
Add PostCSS 7 support (maybe)
1 parent 71737de commit d81edb7

File tree

3 files changed

+69
-7
lines changed

3 files changed

+69
-7
lines changed

jit/index.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const postcss = require('postcss')
2+
const dlv = require('dlv')
23

34
const evaluateTailwindFunctions = require('../lib/lib/evaluateTailwindFunctions').default
45
const substituteScreenAtRules = require('../lib/lib/substituteScreenAtRules').default
@@ -13,6 +14,50 @@ const collapseAdjacentRules = require('./lib/collapseAdjacentRules')
1314
const { env } = require('./lib/sharedState')
1415

1516
module.exports = (configOrPath = {}) => {
17+
return [
18+
env.DEBUG &&
19+
function (root) {
20+
console.log('\n')
21+
console.time('JIT TOTAL')
22+
return root
23+
},
24+
function (root, result) {
25+
function registerDependency(fileName, type = 'dependency') {
26+
result.messages.push({
27+
type,
28+
plugin: 'tailwindcss-jit',
29+
parent: result.opts.from,
30+
file: fileName,
31+
})
32+
}
33+
34+
rewriteTailwindImports(root)
35+
36+
let context = setupContext(configOrPath)(result, root)
37+
38+
if (!env.TAILWIND_DISABLE_TOUCH) {
39+
if (context.configPath !== null) {
40+
registerDependency(context.configPath)
41+
}
42+
}
43+
44+
return postcss([
45+
removeLayerAtRules(context),
46+
expandTailwindAtRules(context, registerDependency),
47+
expandApplyAtRules(context),
48+
evaluateTailwindFunctions(context.tailwindConfig),
49+
substituteScreenAtRules(context.tailwindConfig),
50+
collapseAdjacentRules(context),
51+
]).process(root, { from: undefined })
52+
},
53+
env.DEBUG &&
54+
function (root) {
55+
console.timeEnd('JIT TOTAL')
56+
console.log('\n')
57+
return root
58+
},
59+
].filter(Boolean)
60+
1661
return {
1762
postcssPlugin: 'tailwindcss-jit',
1863
plugins: [

src/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ module.exports = function (config) {
8080
])
8181
warned = true
8282
}
83-
return require('../jit/index.js')(config)
83+
84+
return {
85+
postcssPlugin: 'tailwindcss',
86+
plugins: require('../jit/index.js')(config),
87+
}
8488
}
8589

8690
const plugins = []

src/index.postcss7.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import resolveConfig from './util/resolveConfig'
1212
import getAllConfigs from './util/getAllConfigs'
1313
import { supportedConfigFiles } from './constants'
1414
import defaultConfig from '../stubs/defaultConfig.stub.js'
15+
import log from './util/log'
1516

1617
function resolveConfigPath(filePath) {
1718
// require('tailwindcss')({ theme: ..., variants: ... })
@@ -65,19 +66,31 @@ const getConfigFunction = (config) => () => {
6566
return resolveConfig([...getAllConfigs(configObject)])
6667
}
6768

69+
let warned = false
70+
6871
const plugin = postcss.plugin('tailwindcss', (config) => {
69-
const plugins = []
7072
const resolvedConfigPath = resolveConfigPath(config)
73+
const getConfig = getConfigFunction(resolvedConfigPath || config)
74+
const mode = _.get(getConfig(), 'mode', 'aot')
75+
76+
if (mode === 'jit') {
77+
if (!warned) {
78+
log.warn([
79+
`You have enabled the JIT engine which is currently in preview.`,
80+
'Preview features are not covered by semver, may introduce breaking changes, and can change at any time.',
81+
])
82+
warned = true
83+
}
7184

85+
return postcss(require('../jit/index.js')(config))
86+
}
87+
88+
const plugins = []
7289
if (!_.isUndefined(resolvedConfigPath)) {
7390
plugins.push(registerConfigAsDependency(resolvedConfigPath))
7491
}
7592

76-
return postcss([
77-
...plugins,
78-
processTailwindFeatures(getConfigFunction(resolvedConfigPath || config)),
79-
formatCSS,
80-
])
93+
return postcss([...plugins, processTailwindFeatures(getConfig), formatCSS])
8194
})
8295

8396
module.exports = plugin

0 commit comments

Comments
 (0)