Optimize
This library provides the following features:
AOT translation file flattening
Removal of translator comments
JSON file minification
Installation
pnpm add @jsverse/transloco-optimize --save-devyarn add @jsverse/transloco-optimize --devnpm install @jsverse/transloco-optimize --save-devUsage
Make the optimizer run after building
Create the following task in your project.json configuration file:
{
"name": "my-app",
...,
"targets": {
"transloco:optimize": {
"command": "transloco-optimize {workspaceRoot}/dist/my-app/assets/i18n"
}
}
}Add the following script to your package.json:
"scripts": {
"transloco:optimize": "transloco-optimize dist/my-app/assets/i18n",
"build:prod": "ng build --prod && npm run transloco:optimize"
}In your Transloco configuration, add the following setting:
provideTransloco({
config: {
flatten: {
aot: !isDevMode()
}
...
},
}),Alternatively, if you have some custom pipeline, you can just import it as a function:
import translocoOptimize from '@jsverse/transloco-optimize';
// e.g: `${__dirname}/dist/${appName}/assets/i18n`;
const pathToLocales = ...
await translocoOptimize({ dist: pathToLocales });Was this helpful?

