Home > @lynx-js/rspeedy > Source > exclude
Source.exclude property
The source.exclude
is used to specify JavaScript files that should be excluded from compilation.
Signature:
exclude?: Rspack.RuleSetCondition[] | undefined;
By default, Rsbuild compiles JavaScript files in the current directory and TypeScript/JSX files in all directories. Through the source.exclude
config, you can specify files or directories that should be excluded from compilation. The usage of source.exclude
is consistent with Rule.exclude in Rspack, which supports passing in strings or regular expressions to match module paths.
Example 1
- Exclude specific files or directories
You can exclude specific files or directories from compilation to improve build performance or avoid processing certain files:
import { defineConfig } from '@lynx-js/rspeedy'
export default defineConfig({
source: {
exclude: [
// Exclude all files in the test directory
/[\\/]test[\\/]/,
// Exclude specific file
'./src/legacy-file.js',
// Exclude files matching a pattern
/\.stories\.(js|ts)x?$/,
],
},
})
Example 2
- Exclude third-party dependencies
You can exclude specific third-party dependencies that don't need compilation:
import { defineConfig } from '@lynx-js/rspeedy'
import path from 'node:path'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
export default defineConfig({
source: {
exclude: [
// Exclude specific package
path.dirname(require.resolve('lodash')),
// Exclude using regex pattern
/node_modules[\\/]lodash-es[\\/]/,
],
},
})