# Build

*Build a local development version of a Lightning App*

```bash
lng build
```

> Run this command from the root folder of your Lightning App.

You can use the `lng build` command to build a version of your App for *local* development.

The built App is placed in the **build** folder which is located in the folder of your App.

> In older versions of the Lightning CLI (older than version 1.6.0), the build command placed the built App in the **dist** folder.

The App version that is generated by the `lng build` command, is intended to simulate the Metrological Application Platform during *local* development.
For example, it loads the appBundle asynchronously and makes an API request to **settings.json** (which is used for App configuration), similar to the boot process of the Metrological Application Platform.

If you want to use your App *outside* the context of the Metrological Application Platform, you might also be interested in the [`lng dist`](dist.md) command.


---------------------------------------

The lng build command, by default, generates an ES6-compatible appBundle using predefined bundler options.
However, you have the flexibility to fine-tune the bundling process to meet your specific needs.
You can pass additional bundler options and override the default settings by using the --rollup-bundler-options and --esbuild-bundler-options flags, depending on the bundler you choose.

### Rollup Bundler Options
When using the Rollup bundler, you can customize your build process by specifying options using the `--rollup-bundler-options` flag. Here's an example:

`lng build --rollup-bundler-options sourcemap=both splitting=true format=esm`

You can pass any options that are supported by Rollup. Make sure to follow the required pattern/format for each type of option.

### esbuild Bundler Options

If you prefer the esbuild bundler, you can similarly tailor your build process with the `--esbuild-bundler-options` flag:

`lng build --esbuild-bundler-options sourcemap=both splitting=true format=esm`

Like with Rollup, you can provide any valid esbuild options. Be sure to adhere to the specified pattern/format for different types of options.


| S.No | Type | Format | Example|
| -------- | -------- | -------- | -------- |
| 1 | String| key=value | sourcemap=both|
| 2 | Boolean | key=value (or) key | splitting=true (or) splitting|
| 3 | Array | key=[value1, value2, value3] | dropLabels=[DEV,TEST] |
| 4 | Object | optionName:key=value | banner:js=//javascriptcomment |

Below command includes all the formats

```bash
lng build --esbuild-bundler-options banner:js=//javascriptcomment banner:css=/*csscomment*/ resolveExtensions=[.js,.ts] dropLabels=[DEV,TEST] sourcemap=both tree-shaking line-limit=10
```
We can also specify the bundler options in the `.env` file and through commandline as `env variable`. Here the priority will be
`.env < commandline env variable < commandline options`

### Rollup Custom Config

If you prefer the rollup bundler to use the custom rollup config(user specified), you need to set the env Variable LNG_CUSTOM_ROLLUP to true. Under the hood the custom config will be merged with the default config options to generate the bundle.

Also make sure the following :

| S.No | Info | Description|
| -------- | -------- |----------
| 1 | Config Location | Project Home |
| 2 | Config File Name | `rollup.es6.config.js`(for es6)|
|   |           | `rollup.es5.config.js`(for es5) |
|   |           |                                 |

Example custom Config file content:

```javascript
module.exports = {
  input: 'src/index.js',
  output: {
    format: 'iife',
    sourcemap: false,
  },
}
