name: rspack description: 提供Rspack打包工具的全面指导,包括配置、插件、加载器、优化和Webpack兼容性。当用户询问Rspack、需要配置Rspack、优化构建性能或从Webpack迁移时使用。 license: 完整条款见LICENSE.txt
何时使用此技能
每当用户想要:
- 在新项目或现有项目中设置Rspack
- 为不同环境配置Rspack
- 使用内置插件或创建自定义插件
- 从Webpack迁移到Rspack
- 优化构建性能
- 理解Rspack配置选项
- 使用Rspack CLI或JavaScript API
- 编写自定义加载器
- 理解插件API和钩子
- 配置入口点和输出
- 设置代码分割和优化
- 配置开发服务器
- 处理资产和资源
- 使用TypeScript与Rspack
- 排查Rspack问题
如何使用此技能
此技能按照Rspack官方文档结构组织(https://rspack.rs/zh/guide/start/introduction, https://rspack.rs/zh/config/, https://rspack.rs/zh/plugins/, https://rspack.rs/zh/api/)。在使用Rspack时:
-
从用户请求中识别主题:
- 入门/快速上手 →
examples/guide/start/ - 配置 →
examples/config/ - 插件 →
examples/plugins/ - API →
examples/api/
- 入门/快速上手 →
-
从
examples/目录加载适当的示例文件:指南 -
examples/guide/:examples/guide/compatibility/plugin.mdexamples/guide/features/asset-base-path.mdexamples/guide/features/asset-module.mdexamples/guide/features/builtin-lightningcss-loader.mdexamples/guide/features/builtin-swc-loader.mdexamples/guide/features/dev-server.mdexamples/guide/features/esm.mdexamples/guide/features/layer.mdexamples/guide/features/lazy-compilation.mdexamples/guide/features/loader.mdexamples/guide/features/module-federation.mdexamples/guide/features/module-resolution.mdexamples/guide/features/plugin.mdexamples/guide/features/web-workers.mdexamples/guide/migration/cra.mdexamples/guide/migration/rspack_0.x.mdexamples/guide/migration/storybook.mdexamples/guide/migration/webpack.mdexamples/guide/optimization/analysis.mdexamples/guide/optimization/code-splitting.mdexamples/guide/optimization/lazy-barrel.mdexamples/guide/optimization/production.mdexamples/guide/optimization/profile.mdexamples/guide/optimization/tree-shaking.mdexamples/guide/optimization/use-rsdoctor.mdexamples/guide/start/ecosystem.mdexamples/guide/start/introduction.mdexamples/guide/start/quick-start.mdexamples/guide/tech/css.mdexamples/guide/tech/json.mdexamples/guide/tech/nestjs.mdexamples/guide/tech/next.mdexamples/guide/tech/preact.mdexamples/guide/tech/react.mdexamples/guide/tech/solid.mdexamples/guide/tech/svelte.mdexamples/guide/tech/typescript.mdexamples/guide/tech/vue.md
配置 -
examples/config/:examples/config/cache.mdexamples/config/context.mdexamples/config/deprecated-options.mdexamples/config/dev-server.mdexamples/config/devtool.mdexamples/config/entry.mdexamples/config/experiments.mdexamples/config/extends.mdexamples/config/externals.mdexamples/config/filename-placeholders.mdexamples/config/index.mdexamples/config/infrastructure-logging.mdexamples/config/lazy-compilation.mdexamples/config/mode.mdexamples/config/module-rules.mdexamples/config/module.mdexamples/config/node.mdexamples/config/optimization-optimizationsplitchunks.mdexamples/config/optimization.mdexamples/config/other-options.mdexamples/config/output.mdexamples/config/performance.mdexamples/config/plugins.mdexamples/config/resolve-loader.mdexamples/config/resolve.mdexamples/config/stats.mdexamples/config/target.mdexamples/config/watch.md
插件 -
examples/plugins/:examples/plugins/index.mdexamples/plugins/rspack/circular-dependency-rspack-plugin.mdexamples/plugins/rspack/copy-rspack-plugin.mdexamples/plugins/rspack/css-chunking-plugin.mdexamples/plugins/rspack/css-extract-rspack-plugin.mdexamples/plugins/rspack/esm-library-plugin.mdexamples/plugins/rspack/html-rspack-plugin.mdexamples/plugins/rspack/lightning-css-minimizer-rspack-plugin.mdexamples/plugins/rspack/subresource-integrity-plugin.mdexamples/plugins/rspack/swc-js-minimizer-rspack-plugin.mdexamples/plugins/rspack/virtual-modules-plugin.mdexamples/plugins/webpack/banner-plugin.mdexamples/plugins/webpack/case-sensitive-plugin.mdexamples/plugins/webpack/context-replacement-plugin.mdexamples/plugins/webpack/define-plugin.mdexamples/plugins/webpack/dll-plugin.mdexamples/plugins/webpack/dll-reference-plugin.mdexamples/plugins/webpack/electron-target-plugin.mdexamples/plugins/webpack/enable-chunk-loading-plugin.mdexamples/plugins/webpack/enable-library-plugin.mdexamples/plugins/webpack/enable-wasm-loading-plugin.mdexamples/plugins/webpack/entry-plugin.mdexamples/plugins/webpack/environment-plugin.mdexamples/plugins/webpack/eval-source-map-dev-tool-plugin.mdexamples/plugins/webpack/externals-plugin.mdexamples/plugins/webpack/hot-module-replacement-plugin.mdexamples/plugins/webpack/ignore-plugin.mdexamples/plugins/webpack/index.mdexamples/plugins/webpack/internal-plugins.mdexamples/plugins/webpack/javascript-modules-plugin.mdexamples/plugins/webpack/limit-chunk-count-plugin.mdexamples/plugins/webpack/module-federation-plugin-v1.mdexamples/plugins/webpack/module-federation-plugin.mdexamples/plugins/webpack/no-emit-on-errors-plugin.mdexamples/plugins/webpack/node-target-plugin.mdexamples/plugins/webpack/node-template-plugin.mdexamples/plugins/webpack/normal-module-replacement-plugin.mdexamples/plugins/webpack/progress-plugin.mdexamples/plugins/webpack/provide-plugin.mdexamples/plugins/webpack/runtime-chunk-plugin.mdexamples/plugins/webpack/source-map-dev-tool-plugin.mdexamples/plugins/webpack/split-chunks-plugin.md
API参考 -
examples/api/:examples/api/cli.mdexamples/api/index.mdexamples/api/javascript-api/browser.mdexamples/api/javascript-api/cache.mdexamples/api/javascript-api/compilation.mdexamples/api/javascript-api/compiler.mdexamples/api/javascript-api/index.mdexamples/api/javascript-api/logger.mdexamples/api/javascript-api/resolver.mdexamples/api/javascript-api/stats-json.mdexamples/api/javascript-api/stats.mdexamples/api/javascript-api/swc.mdexamples/api/loader-api/context.mdexamples/api/loader-api/index.mdexamples/api/loader-api/inline-match-resource.mdexamples/api/loader-api/inline.mdexamples/api/loader-api/writing-loaders.mdexamples/api/plugin-api/compilation-hooks.mdexamples/api/plugin-api/compiler-hooks.mdexamples/api/plugin-api/context-module-factory-hooks.mdexamples/api/plugin-api/index.mdexamples/api/plugin-api/javascript-modules-plugin-hooks.mdexamples/api/plugin-api/normal-module-factory-hooks.mdexamples/api/plugin-api/runtime-plugin-hooks.mdexamples/api/plugin-api/stats-hooks.mdexamples/api/runtime-api/hmr.mdexamples/api/runtime-api/module-methods.mdexamples/api/runtime-api/module-variables.md
-
遵循该示例文件中的具体说明,了解语法、结构和最佳实践
重要注意事项:
- Rspack与大多数Webpack插件和加载器兼容
- 配置格式类似于Webpack
- Rspack提供比Webpack更好的性能
- 示例包括JavaScript和TypeScript版本
- 每个示例文件包括参数、返回、常见错误、最佳实践和场景
-
需要时参考官方文档:
最佳实践
- 使用TypeScript进行配置:更好的类型安全和自动完成
- 利用内置插件:当可用时使用Rspack插件
- 优化生产环境:使用生产模式进行构建
- 代码分割:使用optimization.splitChunks以获得更好的性能
- 缓存配置:启用持久缓存以加速重建
- 使用HMR:启用热模块替换以获得更好的开发体验
资源
- 官方文档: https://rspack.rs/zh/
- 入门: https://rspack.rs/zh/guide/start/introduction
- 配置: https://rspack.rs/zh/config/
- 插件: https://rspack.rs/zh/plugins/
- API参考: https://rspack.rs/zh/api/
- GitHub仓库: https://github.com/web-infra-dev/rspack
关键词
Rspack, rspack, bundler, webpack, rust, build tool, bundling, code splitting, HMR, hot module replacement, loader, plugin, configuration, entry, output, optimization, development server, 打包工具, 构建工具, 代码分割, 热模块替换, 加载器, 插件, 配置, 入口, 输出, 优化, 开发服务器