Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

isolated-externals-plugin

Package Overview
Dependencies
Maintainers
5
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

isolated-externals-plugin

[![Build Status](https://travis-ci.com/WTW-IM/isolated-externals-plugin.svg?branch=master)](https://travis-ci.com/github/WTW-IM/isolated-externals-plugin) [![npm version](https://badge.fury.io/js/isolated-externals-plugin.svg)](https://badge.fury.io/js/is

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
470
increased by70.91%
Maintainers
5
Weekly downloads
 
Created
Source

isolated-externals-plugin

Build Status npm version

Installation

To install, simply run:

npm install --save-dev isolated-externals-plugin

Usage

The IsolatedExternalsPlugin allows you to load external dependencies into the scope of your webpack bundle without having to have them in your global scope. If you're curious about why you might want this, there are some use cases listed below.

The plugin is built as an ES Module, so you'll need to load it in by using the default property:

const IsolatedExternalsPlugin = require('isolated-externals-plugin').default;

It currently only works with UMD javascript dependencies, and with an externals declaration that has a similar shape to this:

  ...
  externals: {
    ["react-dom"]: "ReactDOM",
    react: "React",
  },
  ...

For the externals above, your IsolatedExternalsPlugin configuration might look like the following:

new IsolatedExternalsPlugin({
  entryName: {
    react: {
      url: 'https://unpkg.com/react@16/umd/react.development.js'
    },
    ['react-dom']: {
      url: 'https://unpkg.com/react-dom@16/umd/react-dom.development.js'
    }
  }
});

entryName, in this instance, is the name of one of your webpack Entry Points.

The external files will be loaded and applied to your context in the order that they're listed, so if you have dependencies that depend on other dependencies (like ReactDOM depends on React), then you'll want to make sure you list the ones they depend on first.

How It Works

IsolatedExternalsPlugin wraps your webpack bundle in a self-calling function, evaluating the external dependencies and your bundle with an in-memory context object. This allows those external dependencies to only exist on that in-memory context, and will not require them to exist on the broader global context.

Why load externals locally instead of globally?

Here are two valid use cases. There may be others, but these are the reason we built this plugin!:

  1. You want to load different javascript apps on the same page with different versions of the same dependency (like React).
  2. You want to load more than one javascript app onto the same page with the same dependency, but ignorant of each other and the global context (like in micro frontends). This case leverages browser caching to allow each app to be small in byte size, but to load the same libraries more than once on the page without transferring them more than once over the wire

Contributing

This package uses semantic-release. Changes will be compiled into a changelog and the package versioned, tagged and published automatically. Please ensure your commit messages adhere to the following structure:

<type>: <subject>
<BLANK LINE>
<body>

Only the header is mandatory. The supported types are based off of the ESLint Convention.

Keywords

FAQs

Package last updated on 22 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc