npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

webpack-external-plugin

v1.1.3

Published

webpack external deps load plugin

Downloads

201

Readme

webpack-external-plugin

plugin for load bundles and externals

Install

npm i --save-dev webpack-external-plugin
yarn add --dev webpack-external-plugin

This is a webpack plugin that create a script to load all the chunks and externals to html.

Chunks generated by webpack and externals would load according to the calling order.

Usage

The plugin will generate a js file for you that includes all the public path of your webpack bundles and externals. Just add the plugin to your webpack config as follow:

webpack.config.js
module.exports = {
  entry: 'index.jsx',
  output: {
    path: __dirname + '/dist',
    filename: 'index_bundle.js',
    publicPath: '/',
  },
  plugins: [
    new WebpackExternalPlugin()
  ],
  externals: {
    react: 'React',
    'react-dom': 'react-dom'
  }
}

This will generate a file dist/load-main.js to load all the files.

If you have multiple webpack entry points, each one would have a corresponding file called load-[name].js, includes the entry point and externals in the entry.

If there are css files output, they will be added to the generated load files as well.

Actually, all the generated chunks whose filename not end with .map would be added to load files.

The plugin is only suggested to use with production env

Use with html-webpack-plugin

If you want to use with html-webpack-plugin, there is nothing else need to do.

module.exports = {
  ...,
  plugins: [
      new WebpackExternalPlugin(),
      new HtmlWebpackPlugin()
  ],
}

The html file would be like:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Webpack App</title>
  </head>
  <body>
    <script src="load-index_bundle.js"></script>
  </body>
</html>

Options

You can pass a hash of configuration options to webpack-external-plugin. Allowed values are as follows

|Name|Type|Default|Description| |:---:|:---:|:-----:|:----------| | filename | {String} | load-[name].js | The file to write the generated code to. Defaults to load-[name].js like load-main.js. | | externals | {String[]} | [] | Array of file path you want to load external, like external stylesheets | | cdnPath | {String|Function} | https://unpkg.com/[package]@[version] | The path template or function to generate public path of externals | | hash | {Boolean} | true | Add hash to chunk path(not for externals) |

Specify filename

The plugin will output file to load-[name].js default, like load-main.js.

You can specify a name with params like [name].js, [id].js or [hash].js.

Do not make the loader filename same as the bundle out name.

For example, webpack.output.name is '[name].js',
and webpack-external-plugin.options.filename is '[name].js' as well

Specify cdnPath

You can specify cdn path for external package as follow

options.cdnPath accept string|Function

// https://unpkg.com/[package]@[version]
[email protected] => https://unpkg.com/[email protected]

The string type url accept package and version as params, webpack-external-plugin will resolve the node_modules to get installed version of the dependencies.

Sometimes you want to set different path for packages

For example: react

const list = {
  react: 'https://unpkg.com/[email protected]/umd/react.production.min.js',
  'react-dom': 'https://unpkg.com/[email protected]/umd/react-dom.production.min.js'
}
options.cdnPath = (package, version)=> {
  return list[package];
}