Skip to content

Commit 73fe57a

Browse files
bradlcadamwathan
authored andcommitted
[JIT] Add support for "raw" purge content (#4272)
* add support for "raw" purge content * add support for raw content extensions
1 parent dfbeb1e commit 73fe57a

5 files changed

+1010
-7
lines changed

src/jit/lib/expandTailwindAtRules.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ function getDefaultExtractor(fileExtension) {
2525
}
2626
}
2727

28-
function getExtractor(fileName, tailwindConfig) {
28+
function getExtractor(tailwindConfig, fileExtension) {
2929
const purgeOptions = tailwindConfig && tailwindConfig.purge && tailwindConfig.purge.options
30-
const fileExtension = path.extname(fileName).slice(1)
30+
31+
if (!fileExtension) {
32+
return (purgeOptions && purgeOptions.defaultExtractor) || getDefaultExtractor()
33+
}
3134

3235
if (!purgeOptions) {
3336
return getDefaultExtractor(fileExtension)
@@ -208,11 +211,16 @@ export default function expandTailwindAtRules(context, registerDependency) {
208211
env.DEBUG && console.time('Reading changed files')
209212
for (let file of context.changedFiles) {
210213
let content = fs.readFileSync(file, 'utf8')
211-
let extractor = getExtractor(file, context.tailwindConfig)
214+
let extractor = getExtractor(context.tailwindConfig, path.extname(file).slice(1))
212215
getClassCandidates(content, extractor, contentMatchCache, candidates, seen)
213216
}
214217
env.DEBUG && console.timeEnd('Reading changed files')
215218

219+
for (let { content, extension } of context.rawContent) {
220+
let extractor = getExtractor(context.tailwindConfig, extension)
221+
getClassCandidates(content, extractor, contentMatchCache, candidates, seen)
222+
}
223+
216224
// ---
217225

218226
// Generate the actual CSS

src/jit/lib/setupContext.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,10 @@ export default function setupContext(configOrPath) {
767767

768768
process.env.DEBUG && console.log('Setting up new context...')
769769

770+
let purgeContent = Array.isArray(tailwindConfig.purge)
771+
? tailwindConfig.purge
772+
: tailwindConfig.purge.content
773+
770774
let context = {
771775
changedFiles: new Set(),
772776
ruleCache: new Set(),
@@ -781,10 +785,12 @@ export default function setupContext(configOrPath) {
781785
configPath: userConfigPath,
782786
tailwindConfig: tailwindConfig,
783787
configDependencies: new Set(),
784-
candidateFiles: (Array.isArray(tailwindConfig.purge)
785-
? tailwindConfig.purge
786-
: tailwindConfig.purge.content
787-
).map((path) => normalizePath(path)),
788+
candidateFiles: purgeContent
789+
.filter((item) => typeof item === 'string')
790+
.map((path) => normalizePath(path)),
791+
rawContent: purgeContent
792+
.filter((item) => typeof item.raw === 'string')
793+
.map(({ raw, extension }) => ({ content: raw, extension })),
788794
variantMap: new Map(),
789795
stylesheetCache: null,
790796
fileModifiedMap: new Map(),

0 commit comments

Comments
 (0)