# Plugins

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [RsyncPlugin](#rsyncplugin)
  - [Arguments](#arguments)
  - [Example `webpack.config.js`](#example-webpackconfigjs)
- [TranslationsPlugin (Deprecated)](#translationsplugin-deprecated)
  - [Arguments](#arguments-1)
  - [Example `webpack.config.js`](#example-webpackconfigjs-1)
- [WatchDelayPlugin](#watchdelayplugin)
  - [Arguments](#arguments-2)
  - [Example `webpack.config.js`](#example-webpackconfigjs-2)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## RsyncPlugin

This plugin rsyncs files from your local machine to your Dev VM. The plugin will run automatically after every webpack build.

### Arguments

- `source: string` - Source Directory
- `destination: string` - Destination Directory
- `message: string` - A short description of what is being transferred

### Example `webpack.config.js`

```js
const RsyncPlugin = require('@box/frontend/webpack/RsyncPlugin.js');

...
  plugins: [
    ...,
    new RsyncPlugin(
      'dist/.',
      '${USER}@${USER}.dev.box.net:/box/www/assets/enduser-assets', // eslint-disable-line no-template-curly-in-string
      'enduser assets',
    ),
    ...
  ]
...
```

## TranslationsPlugin (Deprecated)

> **⚠️ DEPRECATED:** This plugin is deprecated. Use the standalone scripts instead:
>
> - `props2es` for building translation files
> - `buildBundles` for generating language bundles
>
> See the [i18n documentation](../i18n/README.md) for more details and migration guidance.

This plugin compiles `react-intl` translations into a single `.properties` file. It will also convert `.properties` files to `.js` or `.ts` files for your app to consume. Optionally, you can have it build a language bundle for your application.

### Arguments

- `options: Object`
  - `generateBundles: boolean` - Build language bundles for your application in ./i18n/bundles
  - `additionalMessageData: Array<string>` - Additional message data path to bundle in (You can use `[language]` or `[locale]` placeholders)

### Example `webpack.config.js`

```js
const TranslationsPlugin = require('@box/frontend/webpack/TranslationsPlugin.js');

...
  plugins: [
    ...,
    new TranslationsPlugin({
      generateBundles: true,
      additionalMessageData: [
        'box-react-ui/i18n/[language]',
        'box-ui-elements/i18n/[language]',
      ]
    }),
    ...
  ]
...
```

## WatchDelayPlugin

Due to the way watchpack (webpack's file system watcher) works, if a file is
generated within 1 second (FS_ACCURACY) of the original "watchRun" start time,
it counts as a file changed which triggers webpack to recompile again. To avoid this,
we are fudging the start time and then resetting it after we are done.

### Arguments

- `delay?: number` - The adjustable time (ms) delay for file changes (Default: 2000 - recommended)

### Example `webpack.config.js`

```js
const WatchDelayPlugin = require('@box/frontend/webpack/WatchDelayPlugin.js');

...
  plugins: [
    ...,
    new WatchDelayPlugin(),
    ...
  ]
...
```
