Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JIT] Add support for "raw" purge content #4272

Merged
merged 2 commits into from May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/jit/lib/expandTailwindAtRules.js
Expand Up @@ -25,9 +25,12 @@ function getDefaultExtractor(fileExtension) {
}
}

function getExtractor(fileName, tailwindConfig) {
function getExtractor(tailwindConfig, fileExtension) {
const purgeOptions = tailwindConfig && tailwindConfig.purge && tailwindConfig.purge.options
const fileExtension = path.extname(fileName).slice(1)

if (!fileExtension) {
return (purgeOptions && purgeOptions.defaultExtractor) || getDefaultExtractor()
}

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

for (let { content, extension } of context.rawContent) {
let extractor = getExtractor(context.tailwindConfig, extension)
getClassCandidates(content, extractor, contentMatchCache, candidates, seen)
}

// ---

// Generate the actual CSS
Expand Down
14 changes: 10 additions & 4 deletions src/jit/lib/setupContext.js
Expand Up @@ -767,6 +767,10 @@ export default function setupContext(configOrPath) {

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

let purgeContent = Array.isArray(tailwindConfig.purge)
? tailwindConfig.purge
: tailwindConfig.purge.content

let context = {
changedFiles: new Set(),
ruleCache: new Set(),
Expand All @@ -781,10 +785,12 @@ export default function setupContext(configOrPath) {
configPath: userConfigPath,
tailwindConfig: tailwindConfig,
configDependencies: new Set(),
candidateFiles: (Array.isArray(tailwindConfig.purge)
? tailwindConfig.purge
: tailwindConfig.purge.content
).map((path) => normalizePath(path)),
candidateFiles: purgeContent
.filter((item) => typeof item === 'string')
.map((path) => normalizePath(path)),
rawContent: purgeContent
.filter((item) => typeof item.raw === 'string')
.map(({ raw, extension }) => ({ content: raw, extension })),
variantMap: new Map(),
stylesheetCache: null,
fileModifiedMap: new Map(),
Expand Down