Back

compiler v1.0.0 + gt-next@6.7.0

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

Overview

We are 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 such as compile-time hashing and improved string translation during development. While this gave our team an excellent (albeit intense) introduction to compiler plugins, its scope was limited to Next.js projects.

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
disableBuildChecksbooleanfalsePrevents errors from being thrown when invalid library usage is detected
logLevelstring'warn'Controls the logging level. Options: 'silent'

Note: For gt-next, to satisfy 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 main 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 much more work planned for the compiler, so expect frequent updates over the coming months.