Skip to content

Commit

Permalink
docs: describe how to configure CommonJS modules
Browse files Browse the repository at this point in the history
In version 10, we have a new option for the `angular.json` file,
`allowedCommonJsDependencies`, so users can opt in to support
CommonJS modules.
  • Loading branch information
David Shevitz 🔵 committed Jun 9, 2020
1 parent 55979fe commit d6e7954
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions aio/content/guide/build.md
Expand Up @@ -262,6 +262,31 @@ Each budget entry is a JSON object with the following properties:

</table>

{@a commonjs-dependencies }
## Allowing CommonJS dependencies

<div class="alert is-important">
It is recommended that you avoid depending on CommonJS modules in your Angular applications.
Depending on CommonJS modules can prevent bundlers and minifiers from optimizing your application, which results in larger bundle sizes.
Instead, it is recommended that you use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import">ECMAScript modules</a> in your entire application.
For more information, see <a href="https://web.dev/commonjs-larger-bundles/">How CommonJS is making your bundles larger</a>.
</div>

The Angular CLI outputs warnings if it detects that your browser application depends on CommonJS modules.
To disable these warnings, you can add the CommonJS module name to `allowedCommonJsDependencies` option in the `build` options located in `angular.json` file.

<code-example lang="json">
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"allowedCommonJsDependencies": [
"lodash"
]
...
}
...
},
</code-example>

{@a browser-compat}

Expand Down

0 comments on commit d6e7954

Please sign in to comment.