@discord/rspack-intl-loader

中文文档
0.33.3发布于 2026/10/31MITCommonJS构建来源已验证近 30 天下载 20.1万

使用 @ discord/ intl 为 i18n 信件定义文件提供的 Webpack/ Rspack 加载器

中文使用文档
文档目录3 节
  1. 使用量
  2. 消费者
  3. Web 软件包兼容性

@ discord/ rspack- intl- loader (英语)

使用 intl 信件定义文件的 Webpack/ Rspack 加载器 @discord/intl。这个加载器将定义和翻译作为一组处理,根据所提供的文件类型释放适当的文件类型和内容.

使用量

添加装入器作为规则 全部 您应用程序中的信息文件类型 :

const discord_intl_MESSAGES_REGEXP = /\.messages\.(js|json|jsona)$/;

rules = [
  {
    test: discord_intl_MESSAGES_REGEXP,
    loader: '@discord/rspack-intl-loader',
  },
];

确保内装车是 仅限 在这些文件中发生的变换,或者至少是第一个变换(例如minification之前). 装载器依赖于原始源的结构(例如有ES6的出入口声明),不会在转接模块上工作. 要做到这一点,只是确保 exclude 所有其他JS变换的文件模式.

消费者

请注意,你也会想要/需要 @discord/swc-intl-message-transformer 插件应用到您的 JS 汇编中, 以确保消息用法汇编到与所汇编定义相匹配的密钥 .

rules = [
  {
    loader: 'builtin:swc-loader',
    exclude: [discord_intl_MESSAGES_REGEXP],
    options: {
      jsc: {
        experimental: {
          // Just using a string here causes rspack/swc to error out immediately
          // with "failed to get node_modules path", seemingly because it doesn't
          // correctly give context for how the module should be resolved. Using
          // a resolved path load directly instead.
          //
          // This plugin is responsible for obfuscating and minimizing intl
          // message _usages_ across every source file, to match the compiled
          // _definitions_ that are handled by rspack-intl-loader in a
          // separate rule.
          plugins: [
            [
              require.resolve('@discord/swc-intl-message-transformer'),
              // Add configuration for other message import sources as needed.
              { extraImports: { '@app/intl': ['t', 'untranslated', 'international'] } },
            ],
          ],
        },
      },
    },
  },
];

Web 软件包兼容性

Webpack处理资产文件与Rspack略有不同,依赖一些不同的惯例. 最值得注意的是,Webpack的默认变换不会自动处理将无害环境管理转换回CommonJS(例如不配置另一个加载器). 要处理这个,请使用 jsonExportMode 选项:

rules = [
  {
    test: discord_intl_MESSAGES_REGEXP,
    use: [
      {
        loader: '@discord/rspack-intl-loader',
        // This should work to be compatible with Webpack builds
        options: { jsonExportMode: 'webpack' },
      },
    ],
  },
];

版本与发布记录

@discord/rspack-intl-loader 共发布 138 个版本,首次发布于 2024/08/07;过去 12 个月发布了 18 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.33.3latest2026/10/3112 天前
0.33.22026/10/2320 天前
0.33.12026/10/061 个月前
0.32.02026/09/032 个月前
0.31.02026/08/202 个月前
0.30.02026/08/142 个月前

其他发布通道:canary → 0.28.0-canary.eb67948。

关于 @discord/rspack-intl-loader 的常见问题

@discord/rspack-intl-loader 是什么?

使用 @ discord/ intl 为 i18n 信件定义文件提供的 Webpack/ Rspack 加载器

如何安装 @discord/rspack-intl-loader?

在项目目录运行 npm install @discord/rspack-intl-loader,或使用 pnpm add / yarn add / bun add。

@discord/rspack-intl-loader 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/discord__rspack-intl-loader 是否存在。

@discord/rspack-intl-loader 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@discord/rspack-intl-loader 可以商用吗?

@discord/rspack-intl-loader 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@discord/rspack-intl-loader 的下载量有多少?

根据 npm 官方下载统计,@discord/rspack-intl-loader 在 2026/10/13 – 2026/11/11 这 30 天内被下载 200,623 次,日均约 6,687 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@discord/rspack-intl-loader 还在维护吗?

最新版本 0.33.3 发布于 2026/10/31(12 天前);至今共发布 138 个版本,其中过去 12 个月发布了 18 个;首次发布于 2024/08/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。