Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/atomizer-plugins/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ import type { Options } from './types';
import { outputFile } from 'fs-extra';
import { debounce } from 'lodash-es';

// Binary and non-text file extensions to skip (#609)
const BINARY_EXTENSIONS = [
'.png', '.jpg', '.jpeg', '.gif', '.webp', '.ico', '.bmp', '.tiff', '.tif',
'.svg', '.woff', '.woff2', '.ttf', '.otf', '.eot',
'.mp3', '.mp4', '.wav', '.ogg', '.webm', '.avi', '.mov',
'.pdf', '.zip', '.tar', '.gz', '.rar', '.7z',
'.exe', '.dll', '.so', '.dylib',
'.map', '.lock'
];

// Check if file is binary based on extension
function isBinaryFile(id: string): boolean {
const ext = id.substring(id.lastIndexOf('.')).toLowerCase();
return BINARY_EXTENSIONS.includes(ext);
}

export const unplugin = createUnplugin<Options>((options) => {
const atomizer = new Atomizer({
verbose: options.verbose,
Expand Down Expand Up @@ -43,6 +59,11 @@ export const unplugin = createUnplugin<Options>((options) => {
return null;
}

// Skip binary files to prevent corruption (#609)
if (isBinaryFile(id)) {
return null;
}

// Find atomic classes and add them to our cache
lookup.set(id, atomizer.findClassNames(code));

Expand Down
Loading