Skip to content

Commit d690ce7

Browse files
authored
feat(esbuild): add includeNodeModulesPattern option (#68)
* feat: add includeNodeModules option * feat: replace boolean flag with path regex * fix: revert package-lock.json changes * fix: add proper regex checks
1 parent e80fee4 commit d690ce7

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

packages/esbuild/src/index.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { dirname, join } from 'path';
44
import { babelTransform, compile } from '@macaron-css/integration';
55

66
/*
7-
-> load /(t|j)sx?/
7+
-> load /(t|j)sx?/
88
-> extract css and inject imports (extracted_HASH.css.ts)
99
-> resolve all imports
1010
-> load imports, bundle code again
@@ -14,7 +14,14 @@ import { babelTransform, compile } from '@macaron-css/integration';
1414
-> process the file with vanilla-extract
1515
-> resolve with js loader
1616
*/
17-
export function macaronEsbuildPlugin(): EsbuildPlugin {
17+
18+
interface MacaronEsbuildPluginOptions {
19+
includeNodeModulesPattern?: RegExp;
20+
}
21+
22+
export function macaronEsbuildPlugin({
23+
includeNodeModulesPattern,
24+
}: MacaronEsbuildPluginOptions = {}): EsbuildPlugin {
1825
return {
1926
name: 'macaron-css-esbuild',
2027
setup(build) {
@@ -90,7 +97,10 @@ export function macaronEsbuildPlugin(): EsbuildPlugin {
9097
);
9198

9299
build.onLoad({ filter: /\.(j|t)sx?$/ }, async args => {
93-
if (args.path.includes('node_modules')) return;
100+
if (args.path.includes('node_modules')) {
101+
if(!includeNodeModulesPattern) return;
102+
if(!includeNodeModulesPattern.test(args.path)) return;
103+
};
94104

95105
// gets handled by @vanilla-extract/esbuild-plugin
96106
if (args.path.endsWith('.css.ts')) return;

0 commit comments

Comments
 (0)