Skip to content

Commit

Permalink
fix content glob to support windows
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianGonz97 committed Apr 2, 2024
1 parent a27fd10 commit b6b5bac
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PurgeCSS } from 'purgecss';
import { defaultExtractor } from './extractors/default-extractor.js';
import { walk } from 'estree-walker';
import path from 'node:path';
import type { ResolvedConfig, Plugin } from 'vite';
import type { ComplexSafelist, StringRegExpArray, UserDefinedOptions } from 'purgecss';

Expand Down Expand Up @@ -90,10 +91,12 @@ export function purgeCss(purgeOptions?: PurgeOptions): Plugin {
standard.push(selector);
}

// normalize the glob path to use `/`
const htmlGlob = viteConfig.root.split(path.sep).join('/') + '/**/*.html';
for (const [fileName, asset] of Object.entries(assets)) {
const purgeCSSResult = await new PurgeCSS().purge({
...purgeOptions,
content: ['**/*.html', ...(purgeOptions?.content ?? [])],
content: [htmlGlob, ...(purgeOptions?.content ?? [])],
css: [{ raw: (asset.source as string).trim(), name: fileName }],
safelist: {
...purgeOptions?.safelist,
Expand Down

0 comments on commit b6b5bac

Please sign in to comment.