[JIT] Add support for "raw" purge content (#4272)
* add support for "raw" purge content * add support for raw content extensions
This commit is contained in:
parent
dfbeb1ecea
commit
73fe57aea9
5 changed files with 1010 additions and 7 deletions
|
|
@ -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)
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
@ -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(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue