# Optimize

This library provides the following features:

* AOT translation file flattening
* Removal of translator comments
* JSON file minification

## Installation

{% tabs %}
{% tab title="pnpm" %}

```bash
pnpm add @jsverse/transloco-optimize --save-dev
```

{% endtab %}

{% tab title="yarn" %}

```bash
yarn add @jsverse/transloco-optimize --dev
```

{% endtab %}

{% tab title="npm" %}

```bash
npm install @jsverse/transloco-optimize --save-dev
```

{% endtab %}
{% endtabs %}

## Usage

1. Make the optimizer run after building

{% tabs %}
{% tab title="Nx" %}
Create the following task in your `project.json` configuration file:

```json
{
  "name": "my-app", 
  ...,
  "targets": {
    "transloco:optimize": {
      "command": "transloco-optimize {workspaceRoot}/dist/my-app/assets/i18n"
    }
  }
}
```

{% endtab %}

{% tab title="Angular CLI" %}
Add the following script to your `package.json`:

```json
"scripts": {
  "transloco:optimize": "transloco-optimize dist/my-app/assets/i18n",
  "build:prod": "ng build --prod && npm run transloco:optimize"
}
```

{% endtab %}
{% endtabs %}

2. In your Transloco configuration, add the following setting:

<pre class="language-typescript"><code class="lang-typescript">provideTransloco({
  config: {
    flatten: {
<strong>      aot: !isDevMode()
</strong>    }
    ...
  },
}),
</code></pre>

Alternatively, if you have some custom pipeline, you can just import it as a function:

```typescript
import translocoOptimize from '@jsverse/transloco-optimize';

// e.g: `${__dirname}/dist/${appName}/assets/i18n`;
const pathToLocales = ...
await translocoOptimize({ dist: pathToLocales });
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jsverse.gitbook.io/transloco/developer-tools/optimize.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
