# General Translation Changelog: compiler 1.0.0 / gt-next 6.7.0: 面向所有 React 应用的构建时优化
URL: https://generaltranslation.com/zh/blog/compiler_v1_0_0_gt-next_v6_7_0.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 
Authors: Ernest McCarter
Published: 2025-10-10

## 概述

我们非常高兴地宣布推出 @general-translation/compiler v1.0.0。

正如我们在 `gt-next@6.2.0` 的发布中所说，我们相信 i18n 库的未来在于构建时处理。今年早些时候，我们为 `gt-next` 发布了一个 SWC 插件，带来了编译时哈希和更出色的开发时字符串翻译等优化。虽然这让我们的团队对编译器插件有了一次极佳 (尽管颇具挑战) 的初步实践，但它的适用范围仅限于 Next.js 项目。

现在，我们通过发布这个通用的 React 编译器插件，进一步践行对构建时处理的承诺。这意味着，`gt-next` 中的所有构建时优化现在都已向所有 `gt-react` 用户开放！

## 安装

### 配置

| 选项                   | 类型      | 默认值      | 说明                                                                  |
| -------------------- | ------- | -------- | ------------------------------------------------------------------- |
| `compileTimeHash`    | boolean | `true`   | 启用编译时哈希                                                             |
| `disableBuildChecks` | boolean | `false`  | 检测到无效的库用法时，不抛出错误                                                    |
| `logLevel`           | string  | `'warn'` | 控制日志级别。可选值：`'silent'` | `'error'` | `'warn'` | `'info'` | `'debug'` |

**注意**：
对于 `gt-next`，出于向后兼容性的要求，如果将 `compileTimeHash` 设置为 `false`，整个插件都会被禁用。

### gt-react

首先需要安装该软件包：

```bash
npm install @generaltranslation/compiler
```

**Vite**

```js
// vite.config.js
import { defineConfig } from 'vite'
import { vite as gtCompiler } from '@generaltranslation/compiler'

export default defineConfig({
  plugins: [gtCompiler()],
})
```

**Webpack**

```js
// webpack.config.js
const { webpack: gtCompiler } = require('@generaltranslation/compiler')

module.exports = {
  plugins: [gtCompiler()],
}
```

**Rollup**

```js
// rollup.config.js
import { rollup as gtCompiler } from '@generaltranslation/compiler'

export default {
  plugins: [gtCompiler()],
}
```


### gt-next

你无需安装任何额外软件包。

对于 `gt-next`，我们正在弃用 `experimentalSwcPluginOptions`，改用新的 `experimentalCompilerOptions` 字段。关键区别在于，你现在必须指定要使用的编译器类型：`'swc'` 或 `'babel'`。默认使用 `'swc'` 编译器；如果将 `type` 字段设为 `'babel'`，则可启用新的基于 Babel 的编译器。

```js
// next.config.js
import { withGTConfig } from 'gt-next'

export default withGTConfig(nextConfig, {
  experimentalCompilerOptions: {
    type: 'babel',
  },
})
```

## 总结

我们还为编译器规划了许多后续工作，因此接下来几个月会持续频繁更新。

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
