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;

Remarks

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[\\/]/,
    ],
  },
})
除非另有说明,本项目采用知识共享署名 4.0 国际许可协议进行许可,代码示例采用 Apache License 2.0 许可协议进行许可。