@discord/rspack-intl-loader

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

Webpack/Rspack loader for i18n message definition files using @discord/intl

原始使用文档
文档目录3 节
  1. Usage
  2. Consumers
  3. Webpack compatibility

@discord/rspack-intl-loader

A Webpack/Rspack loader for intl message definition files using @discord/intl. This loader handles both definitions and translations as a single group, emitting the appropriate file types and contents based on the kind of file provided.

Usage

Add the loader as a rule for all kinds of messages files in your application:

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

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

Make sure that the intl loader is the only transformation that happens on these files, or at least is the first one (before e.g. minification). The loader relies on the structure of the raw source (with ES6 import and export statements, for example) and will not work on transpiled modules. To do this, just be sure to exclude the file patterns from all other JS transformations.

Consumers

Note that you'll also want/need the @discord/swc-intl-message-transformer plugin applied to your JS compilation to ensure that message usages compile to the same keys that match the compiled definitions.

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'] } },
            ],
          ],
        },
      },
    },
  },
];

Webpack compatibility

Webpack processes asset files slightly differently than Rspack and relies on some different conventions. Most notably, Webpack's default transformations won't handle converting ESM back to CommonJS automatically (without configuring another loader, for example). To handle this, use the jsonExportMode option for the loader to have it emit converted CommonJS modules instead of ESM:

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 是什么?

Webpack/Rspack loader for i18n message definition files using @discord/intl

如何安装 @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 和提交记录判断。