SharedLibraryWebpackPlugin
1.0.0
1.0.0
  • SharedLibraryWebpackPlugin
  • Documentation
    • Installation and Configuration
    • How does it work?
    • Sharing and Tree shaking
    • The Plugin
  • Contributor Covenant Code of Conduct
  • Contributing
  • License
Powered by GitBook
On this page
  • Motivation
  • Documentations
  • Demo
  • Contributing
  • License

Was this helpful?

Export as PDF

SharedLibraryWebpackPlugin

NextDocumentation

Last updated 4 years ago

Was this helpful?

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

Demo

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!

There is . All apps are built with Angular. The client page loads 282.8kB of JavaScript (gzip) when it opens all pages.

a host application with two micro-apps
Contributing
License
Installation and configuration
How is it works?
Sharing and Tree shaking
The Plugin API
npm
npm