Skip to content

Commit

Permalink
arbitrary values are no longer removed
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianGonz97 committed Aug 17, 2023
1 parent 63eeb34 commit c9eb647
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-vans-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'vite-plugin-tailwind-purgecss': patch
---

fix: Tailwind arbitrary values are no longer erroneously removed
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"devDependencies": {
"@changesets/cli": "^2.26.2",
"@types/node": "^18.11.18",
"css-what": "^6.1.0",
"prettier": "^2.8.1",
"tsup": "^6.5.0",
"typescript": "^4.9.4",
Expand Down
8 changes: 0 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 2 additions & 18 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { walk } from 'estree-walker';
import { join } from 'path';
import type { ResolvedConfig, Plugin } from 'vite';
import type { ComplexSafelist, StringRegExpArray, UserDefinedOptions } from 'purgecss';
import { parse } from 'css-what';

type Extractor = (content: string) => string[];

Expand All @@ -14,7 +13,7 @@ type Options = Partial<UserDefinedOptions> & {
type PurgeOptions = Omit<Options, 'css'>;

const EXT_CSS = /\.(css)$/;
const MAX_STRING_LITERAL_LENGTH = 2000;
const MAX_STRING_LITERAL_LENGTH = 50_000;

export function purgeCss(purgeOptions?: PurgeOptions): Plugin {
let viteConfig: ResolvedConfig;
Expand Down Expand Up @@ -90,18 +89,8 @@ export function purgeCss(purgeOptions?: PurgeOptions): Plugin {
}

for (const selector of selectors) {
try {
parse(selector);
new RegExp(selector);
standard.push(selector);
} catch (e) {
// console.log(`${selector} failed to transform into a regex`);
}
standard.push(selector);
}
// console.dir(
// { selectors: standard },
// { maxArrayLength: Infinity, maxStringLength: Infinity, depth: Infinity }
// );

for (const [fileName, asset] of Object.entries(assets)) {
const purgeCSSResult = await new PurgeCSS().purge({
Expand All @@ -121,11 +110,6 @@ export function purgeCss(purgeOptions?: PurgeOptions): Plugin {
// prevent the original from being written
delete bundle[asset.fileName];

// console.dir(
// { purge: purgeCSSResult[0] },
// { maxArrayLength: Infinity, maxStringLength: Infinity, depth: Infinity }
// );

// emit the newly purged css file
this.emitFile({
...asset,
Expand Down

0 comments on commit c9eb647

Please sign in to comment.