# SharedLibraryWebpackPlugin

[![npm](https://img.shields.io/npm/v/@tinkoff/shared-library-webpack-plugin)](https://www.npmjs.com/package/@tinkoff/shared-library-webpack-plugin) [![npm](https://img.shields.io/npm/dm/@tinkoff/shared-library-webpack-plugin)](https://www.npmjs.com/package/@tinkoff/shared-library-webpack-plugin)

`SharedLibraryWebpackPlugin` is a webpack plugin for sharing libraries between applications.

## Motivation

When the host application loads many micro apps bundled with a webpack, many JavaScript is loaded on a client page. In a perfect world, each app can share its libraries with other apps and meet the requirements:

1. Each app stays self-hosted.
2. Fallbacks for non-loaded packages.
3. Codesharing in runtime.
4. Different library versions work individually.

SharedLibraryWebpackPlugin came to us from a perfect world!

## Documentations

1. [Installation and configuration](/sharedlibrarywebpackplugin/docs/installation_and_configuration.md)
2. [How is it works?](/sharedlibrarywebpackplugin/docs/how_does_it_work.md)
3. [Sharing and Tree shaking](https://github.com/TinkoffCreditSystems/shared-library-webpack-plugin/tree/15f229429eaf4e9adedbd15b405686a142d0087e/docs/tree_shaking.md)
4. [The Plugin API](/sharedlibrarywebpackplugin/docs/the_plugin.md)

## Demo

There is [a host application with two micro-apps](https://github.com/IKatsuba/shared-library-plugin-demo). All apps are built with Angular. The client page loads 282.8kB of JavaScript (gzip) when it opens all pages.

We add SharedLibraryWebpackPlugin in each app build for sharing all Angular packages and zone.js.

```typescript
const {
  SharedLibraryWebpackPlugin,
} = require('@tinkoff/shared-library-webpack-plugin');

module.exports = {
  plugins: [
    new SharedLibraryWebpackPlugin({
      libs: [
        { name: '@angular/core', usedExports: [] },
        { name: '@angular/common', usedExports: [] },
        { name: '@angular/common/http', usedExports: [] },
        { name: '@angular/platform-browser', usedExports: ['DomSanitizer'] },
        { name: '@angular/platform-browser/animations', usedExports: [] },
        { name: '@angular/animations', usedExports: [] },
        { name: '@angular/animations/browser', usedExports: [] },
        'zone.js/dist/zone',
      ],
    }),
  ],
};
```

After that, the client page loads 174.6kB of JavaScript! It is 38% less!

## [Contributing](/sharedlibrarywebpackplugin/contributing.md)

## [License](/sharedlibrarywebpackplugin/license.md)


---

# 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://shared-library-webpack-plugin.gitbook.io/sharedlibrarywebpackplugin/master.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.
