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

feat(esbuild): filter option that allows to process only specific files #50

Merged
merged 1 commit into from
Feb 6, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/quick-bulldogs-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@wyw-in-js/esbuild': patch
'@wyw-in-js/website': patch
---

The new `filter` options for the esbuild plugin that allows to process only specific files, e.g. `.styles.ts`.
1 change: 1 addition & 0 deletions apps/website/pages/bundlers/esbuild.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const prod = process.env.NODE_ENV === 'production';

esbuild
.build({
filter: /\.(js|jsx|ts|tsx)$/,
entryPoints: ['src/index.ts'],
outdir: 'dist',
bundle: true,
Expand Down
7 changes: 6 additions & 1 deletion packages/esbuild/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {

type EsbuildPluginOptions = {
esbuildOptions?: TransformOptions;
filter?: RegExp | string;
preprocessor?: Preprocessor;
sourceMap?: boolean;
} & Partial<PluginOptions>;
Expand All @@ -29,6 +30,7 @@ export default function wywInJS({
sourceMap,
preprocessor,
esbuildOptions,
filter = /\.(js|jsx|ts|tsx)$/,
...rest
}: EsbuildPluginOptions = {}): Plugin {
let options = esbuildOptions;
Expand Down Expand Up @@ -73,7 +75,10 @@ export default function wywInJS({
};
});

build.onLoad({ filter: /\.(js|jsx|ts|tsx)$/ }, async (args) => {
const filterRegexp =
typeof filter === 'string' ? new RegExp(filter) : filter;

build.onLoad({ filter: filterRegexp }, async (args) => {
const rawCode = readFileSync(args.path, 'utf8');
const { ext, name: filename } = parse(args.path);
const loader = ext.replace(/^\./, '') as Loader;
Expand Down
Loading