For AI agents: the complete documentation index is available at /next/zh/llms.txt, the full documentation bundle is available at /next/zh/llms-full.txt, and this page is available as Markdown at /next/zh/api/packages/rspeedy/interfaces/Tools.md.
Lynx
  • 简体中文
  • 接口: Tools

    Tools 选项用于修改各类构建工具的行为。

    属性

    bundlerChain?

    optional bundlerChain?: ToolsBundlerChainConfig

    Tools.bundlerChain 通过 Rspack 修改 rspack-chain 的选项。

    默认值

    undefined

    示例

    import { defineConfig } from '@lynx-js/rspeedy'
    
    export default defineConfig({
      tools: {
        bundlerChain(chain) {
          chain.resolve.fullySpecified(true)
        },
      },
    })

    详见 rspack-chain。


    cssExtract?

    optional cssExtract?: CssExtract

    CssExtract 用于控制 CssExtractRspackPlugin 的选项。

    默认值

    undefined

    cssLoader?

    optional cssLoader?: CssLoader

    CssLoader 用于控制 css-loader 的选项。

    默认值

    使用基于 output.cssModules 和 output.sourceMap 推导出的默认值,其中 CSS 文件的 importLoaders 设置为 1,Sass/Less 文件设置为 2。

    备注

    默认选项如下:

    const defaultOptions = {
      modules: {
        auto: true,
        namedExport: false,
        exportLocalsConvention: 'camelCase',
        localIdentName: output.cssModules.localIdentName,
      },
      sourceMap: output.sourceMap,
      // importLoaders is `1` when compiling css files, and is `2` when compiling sass/less files
      importLoaders: 1 || 2,
    };

    rsdoctor?

    optional rsdoctor?: RsdoctorRspackPluginOptions

    Tools.rsdoctor 用于控制 Rsdoctor 的选项。

    默认值

    undefined

    备注

    设置 RSDOCTOR=true 可启用 Rsdoctor。启用后,Rspeedy 会在配置规范化阶段合并额外的插件默认配置。

    示例

    • 使用内置的 Rsdoctor。
    import { defineConfig } from '@lynx-js/rspeedy'
    
    export default defineConfig({
      tools: {
        rsdoctor: {
          disableClientServer: true,
        },
      },
    })

    详见 Rsdoctor - Configuration。


    rspack?

    optional rspack?: ToolsRspackConfig

    Tools.rspack 用于控制 Rspack 的选项。

    默认值

    undefined

    示例

    • 使用对象配置
    import { defineConfig } from '@lynx-js/rspeedy'
    
    export default defineConfig({
      tools: {
        rspack: {
          resolve: {
            fullySpecified: true,
          },
        },
      },
    })

    详见 Rspack - Configuration。

    • 使用函数形式并借助 env 工具函数
    import { defineConfig } from '@lynx-js/rspeedy'
    
    export default defineConfig({
      tools: {
        rspack(config, { env }) {
          if (env === 'development') {
            config.devtool = 'cheap-source-map'
          }
          return config
        },
      },
    })

    详见 Rsbuild - tools.rspack。

    • 使用函数形式并借助 mergeConfig 工具函数
    import { defineConfig } from '@lynx-js/rspeedy'
    
    export default defineConfig({
      tools: {
        rspack(config, { mergeConfig }) {
          return mergeConfig(config, {
            resolve: {
              fullySpecified: true,
            },
          })
        },
      },
    })

    详见 Rsbuild - tools.rspack。

    • 使用函数形式并借助 appendPlugins 工具函数
    import { defineConfig } from '@lynx-js/rspeedy'
    
    export default defineConfig({
      tools: {
        rspack(config, { appendPlugins, rspack }) {
          appendPlugins(new rspack.BannerPlugin({ banner: 'Hello, World!' }))
          return config
        },
      },
    })

    详见 Rsbuild - tools.rspack。


    swc?

    optional swc?: ToolsSwcConfig

    Tools.swc 用于控制 builtin:swc-loader 的选项。

    默认值

    undefined
    除非另有说明,本项目采用知识共享署名 4.0 国际许可协议进行许可,代码示例采用 Apache License 2.0 许可协议进行许可。