@tinkoff/shared-library-webpack-plugin
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

SharedLibraryWebpackPlugin

npm npm

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
  2. How is it works?
  3. Sharing and Tree shaking
  4. The Plugin API

Demo

There is a host application with two micro-apps. 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.

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

License

Package Sidebar

Install

npm i @tinkoff/shared-library-webpack-plugin

Weekly Downloads

9

Version

1.1.0

License

Apache-2.0

Unpacked Size

78.4 kB

Total Files

20

Last publish

Collaborators

  • yeahga
  • sradyukov
  • hondasmx
  • makar_l
  • tinkoffbank
  • dmitry-korolev
  • rouland
  • ishivan
  • ytsareva
  • shoom3301
  • waterplea
  • meskill
  • marsibarsi
  • zig-green
  • super_oleg
  • dersizes
  • alexkvak