@formatjs/swc-plugin-experimental

中文文档
0.6.1发布于 2024/10/12MITCommonJS零依赖近 30 天下载 3072

SWC plugin for formatjs

此软件包已被标记为弃用

Please use @swc/plugin-formatjs

原始使用文档

@formatjs/swc-plugin-experimental

@formatjs/swc-plugin-experimental is a port of babel-plugin-formatjs written in Rust, for the SWC's experimental plugin system. Transform can currently be performed via SWC's wasm-based plugin, and in the future also as a custom pass in Rust-side transform chains.

What does compatible exactly means?

This plugin attempts to mimic most of defined behavior of original plugin's test fixture. However, due to differences of plugin interfaces, as well as known limitations there are numbers of unsupported features with differences. You may able to check the list of github issues, as well as checking test fixtures.

Notably, any dynamic configuration options (overrideFn, onMsg...) are not supported, and few internal behaviors relying on static evaluation won't work.

NOTE: Package can have breaking changes without major semver bump

Given SWC's plugin interface itself is under experimental stage does not gaurantee semver-based major bump yet, this package also does not gaurantee semver compliant breaking changes yet. Please refer changelogs if you're encountering unexpected breaking behavior across versions.

Also, current implementation is largely unoptimized, and may have performance issues as initial focus was to pass existing test fixtures only.

Usage

Using SWC's wasm-based experimental plugin

First, install package via npm:

npm install --save-dev @formatjs/swc-plugin-experimental

Then add plugin into swc's configuration:

interface PluginOptions {
  pragma: string
  removeDefaultMessage: bool
  idInterpolationPattern?: string
  ast: bool
  extractSorceLocation: bool
  preserveWhitespace: bool
  additionalFunctionNames: Array<string>
  additionalComponentNames: Array<string>
}

jsc: {
  // ...
  experimental: {
    plugins: [
      [
        '@formatjs/swc-plugin-experimental',
        {
          // PluginOptions
        },
      ],
    ]
  }
}

版本与发布记录

@formatjs/swc-plugin-experimental 共发布 10 个版本,首次发布于 2022/12/01;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.6.1latest2024/10/122 年前
0.6.02024/10/082 年前
0.4.02024/06/182 年前
0.3.72023/06/063 年前
0.3.62023/05/013 年前
0.3.52023/04/173 年前

关于 @formatjs/swc-plugin-experimental 的常见问题

@formatjs/swc-plugin-experimental 是什么?

SWC plugin for formatjs注意:该包已被作者标记为弃用——Please use @swc/plugin-formatjs

如何安装 @formatjs/swc-plugin-experimental?

在项目目录运行 npm install @formatjs/swc-plugin-experimental,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@swc/core(>= 1.7.0 < 1.8.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@formatjs/swc-plugin-experimental 支持 TypeScript 吗?

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

@formatjs/swc-plugin-experimental 支持 ESM 还是 CommonJS?

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

@formatjs/swc-plugin-experimental 可以商用吗?

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

@formatjs/swc-plugin-experimental 的下载量有多少?

根据 npm 官方下载统计,@formatjs/swc-plugin-experimental 在 2026/10/16 – 2026/11/14 这 30 天内被下载 3,072 次,日均约 102 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@formatjs/swc-plugin-experimental 还在维护吗?

最新版本 0.6.1 发布于 2024/10/12(2 年前);至今共发布 10 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/12/01。作者已将其标记为弃用,新项目建议寻找替代方案。