Back

compiler v1.0.0 + gt-next@6.7.0

Ernest McCarter avatarErnest McCarter
@general-translation/compilerv1.0.0compilertranslationi18n

Overview

We’re very excited to announce the release of @general-translation/compiler v1.0.0.

As we stated in our gt-next@6.2.0 release, we believe the future of i18n libraries lies in build-time processing. Earlier this year, we released an SWC plugin for gt-next that enabled optimisations like compile-time hashing and better dev-time string translations. While this provided an excellent (if intense) introduction to compiler plugins for our team, its scope was limited to Next.js projects only.

We’re following through on our commitment to build-time processing by releasing this general-purpose React compiler plugin. This means all the build-time optimisations from gt-next are now available to every gt-react user!

Setup

Configuration

OptionTypeDefaultDescription
compileTimeHashbooleantrueEnables compile-time hashing
disableBuildChecksbooleanfalseDisables throwing errors when invalid library usage is detected
logLevelstring'warn'Controls the level of logging. Options: 'silent' | 'error' | 'warn' | 'info' | 'debug'

Note: For gt-next, to meet a backwards compatibility requirement, if you set compileTimeHash to false, the entire plugin will be disabled.

gt-react

First, install the package:

npm install @generaltranslation/compiler

Vite

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

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

Webpack

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

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

Rollup

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

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

gt-next

You do not need to install any additional packages.

For gt-next, we're deprecating experimentalSwcPluginOptions in favour of the new experimentalCompilerOptions field. The key difference is that you must now specify which compiler type to use: 'swc' or 'babel'. The 'swc' compiler is used by default, but you can enable the new Babel-based compiler by setting the type field to 'babel'.

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

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

Conclusion

We have plenty more work planned for the compiler, so expect frequent updates over the coming months.