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-system-register

v1.6.0

Published

A webpack plugin that wraps your bundle in a [System.register](https://github.com/ModuleLoader/es6-module-loader/wiki/System.register-Explained) call. This makes webpack bundles totally consumable by [SystemJS](https://github.com/systemjs/systemjs).

Downloads

875

Readme

webpack-system-register

A webpack plugin that wraps your bundle in a System.register call. This makes webpack bundles totally consumable by SystemJS.

Alternatives

Note that you can achieve much of the same behavior by changing your webpack config to output an AMD module, and then using externals to declare the dependencies that you want to get from SystemJS. This method is probably preferable over the webpack-system-register plugin, in most cases. One of the reasons why you may still want to use this plugin, though, is if you are having trouble configuring webpack's public path, since webpack-system-register gives you the ability to use a dynamic public path at runtime in the browser (see configuration options below).

Motivation

  • System.import webpack apps.
  • Inject SystemJS modules into webpack bundles.
  • Export variables from webpack apps into SystemJS apps.

Usage

First, install the webpack-system-register plugin.

npm install --save-dev webpack-system-register

Then add it to your webpack plugins.

// webpack.config.js
const WebpackSystemRegister = require('webpack-system-register');

module.exports = {
  ...
	plugins: [
		new WebpackSystemRegister({
			systemjsDeps: [
				/^react/, // any import that starts with react
				'react-dom', // only the `react-dom` import
				/^lodash/, // any import that starts with lodash
			],
			registerName: 'test-module', // optional name that SystemJS will know this bundle as.
		}),
	],
}

Configuration Options

All configuration options are passed as properties of the object given to the WebpackSystemRegister constructor. All properties are optional and if no configuration is provided, webpack-system-register will simply wrap you webpack bundle in a System.register call (nothing more).

  • systemjsDeps (optional): an array of dependency names that should not be bundled into the webpack bundle, but instead be provided by SystemJS. These dependency names should either be literal strings or Regular Expressions.
  • registerName (optional): a string that SystemJS will use as the name of the module. Generally speaking, this is the name by which you want other code to be able to SystemJS.import() your webpack bundle.
  • publicPath: (optional) an object with configuration options for setting webpack's output.publicPath variable dynamically
    • useSystemJSLocateDir: (optional) A subproperty of the publicPath object. If it is set to true, this will cause webpack's output.publicPath to be set dynamically at runtime, based on the URL address from which the webpack bundle was loaded by SystemJS. For example, if the webpack bundle is SystemJS.imported from url http://localhost:8080/webpack.bundle.js, the publicPath for webpack will be http://localhost:8080. Since this would completely overwrite the normal output.publicPath option that is passed directly to webpack, webpack-system-register will throw an error if both output.publicPath and publicPath are set. Additionally, at least for now, the registerName must also be provided in order to use publicPath.useSystemJSLocateDir. See example below
// Example webpack.config.js showcasing usage of `useSystemJSLocateDir`
var WebpackSystemRegister = require('webpack-system-register');

module.exports = {
  output: {
    filename: "my-bundle.js",
    publicPath: null, // This MUST not be set when using `useSystemJSLocateDir`
  },
  plugins: [
    new WebpackSystemRegister({
      registerName: 'my-bundle', // required when using `useSystemJSLocateDir`
      publicPath: {
        useSystemJSLocateDir: true, // if this is set to true, publicPath must be omitted and registerName must be provided
      }
    }
  ]
}

Exporting variables from webpack into SystemJS.

To do this, simply export the variables from your webpack entry file. They will automatically be exposed to anybody who System.imports your webpack bundle. Note that (at least right now) if you mutate an exported value that that mutation will not be re-exported like it's supposed to according to the ES6 spec. The reason for this is basically just that it's really hard for me to detect mutation so I decided not to try.

Examples

To run the examples locally, run npm install && npm run build from inside of the example directory that you're interested in. Then run npm start and open up your web browser to localhost:8080.