diff --git a/README.md b/README.md index 6b9f99a9c..1ae9bf496 100644 --- a/README.md +++ b/README.md @@ -141,6 +141,20 @@ The name of the folder with the source code which should be compiled. The folder The name of the folder where the compiled files should be output to. It will contain separate folder for each target. +#### `exclude` + +Glob pattern to be used while filtering the unnecessary files. Defaults to `'**/{__tests__,__fixtures__,__mocks__}/**'` if you don't specify it. + +> This option only works with `commonjs` and `module` targets. To exclude files while building `typescript`, please see [the tsconfig exclude field](https://www.typescriptlang.org/tsconfig#exclude). + +Example: + +```json +{ + "exclude": "ignore_me/**" +} +``` + #### `targets` Various targets to build for. The available targets are: diff --git a/packages/react-native-builder-bob/src/index.ts b/packages/react-native-builder-bob/src/index.ts index df2be360e..981a7dec8 100644 --- a/packages/react-native-builder-bob/src/index.ts +++ b/packages/react-native-builder-bob/src/index.ts @@ -390,6 +390,9 @@ yargs ); } + const exclude = + options.exclude ?? '**/{__tests__,__fixtures__,__mocks__}/**'; + const report = { info: logger.info, warn: logger.warn, @@ -418,6 +421,7 @@ yargs root, source: path.resolve(root, source as string), output: path.resolve(root, output as string, 'commonjs'), + exclude, options: targetOptions, report, }); @@ -427,6 +431,7 @@ yargs root, source: path.resolve(root, source as string), output: path.resolve(root, output as string, 'module'), + exclude, options: targetOptions, report, }); diff --git a/packages/react-native-builder-bob/src/targets/commonjs.ts b/packages/react-native-builder-bob/src/targets/commonjs.ts index 67a9cd493..2092906cd 100644 --- a/packages/react-native-builder-bob/src/targets/commonjs.ts +++ b/packages/react-native-builder-bob/src/targets/commonjs.ts @@ -11,12 +11,14 @@ type Options = Input & { sourceMaps?: boolean; copyFlow?: boolean; }; + exclude: string; }; export default async function build({ root, source, output, + exclude, options, report, }: Options) { @@ -31,6 +33,7 @@ export default async function build({ root, source, output, + exclude, modules: 'commonjs', report, field: 'main', diff --git a/packages/react-native-builder-bob/src/targets/module.ts b/packages/react-native-builder-bob/src/targets/module.ts index 3f71414c6..e6cee46c7 100644 --- a/packages/react-native-builder-bob/src/targets/module.ts +++ b/packages/react-native-builder-bob/src/targets/module.ts @@ -11,12 +11,14 @@ type Options = Input & { sourceMaps?: boolean; copyFlow?: boolean; }; + exclude: string; }; export default async function build({ root, source, output, + exclude, options, report, }: Options) { @@ -31,6 +33,7 @@ export default async function build({ root, source, output, + exclude, modules: false, report, field: 'module', diff --git a/packages/react-native-builder-bob/src/types.ts b/packages/react-native-builder-bob/src/types.ts index 4d71052ef..3215129c5 100644 --- a/packages/react-native-builder-bob/src/types.ts +++ b/packages/react-native-builder-bob/src/types.ts @@ -19,4 +19,5 @@ export type Options = { source?: string; output?: string; targets?: (Target | [Target, object])[]; + exclude?: string; }; diff --git a/packages/react-native-builder-bob/src/utils/compile.ts b/packages/react-native-builder-bob/src/utils/compile.ts index f3be314ab..4d089f6b3 100644 --- a/packages/react-native-builder-bob/src/utils/compile.ts +++ b/packages/react-native-builder-bob/src/utils/compile.ts @@ -13,6 +13,7 @@ type Options = Input & { copyFlow?: boolean; modules: 'commonjs' | false; field: 'main' | 'module'; + exclude: string; }; export default async function compile({ @@ -21,6 +22,7 @@ export default async function compile({ output, babelrc = false, configFile = false, + exclude, modules, copyFlow, sourceMaps = true, @@ -31,7 +33,7 @@ export default async function compile({ cwd: source, absolute: true, nodir: true, - ignore: '**/{__tests__,__fixtures__,__mocks__}/**', + ignore: exclude, }); report.info(