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 🙏

© 2025 – Pkg Stats / Ryan Hefner

multi-expose-loader

v1.0.2

Published

loader for exposing multiple exported members for webpack

Downloads

984

Readme

Loader for exposing multiple exported members for webpack

Motivation

While I was working on an upgrade project that had a lot of "plain-old JavaScript" files that using a lot of global JS variables, I noticed that not all JS files could be upgraded to ES6.

So I had to use the Expose loader for webpack to continue providing these global variables. Unfortunately, I was not able to port all code to ES6 modules using only ES6 default exports, which the export loader could handle. Some modules export members, which has to be placed in the global scope too. So I searched for a webpack loader placing members in the global scope.

Found Expose Members loader for webpack, but this, somewhat older, contribution by @davidpelayo did not meet my requirements. So I decided to write a loader that can expose both the default export and member export to the global scope.

Usage

Usecase: Expose the default export to multiple globals

Requirement: Expose jquery to globals $ and jQuery

module: {
    rules: [{ 
        "test": "jquery", 
        "use": [{ "loader": "multi-expose-loader", "options": "$,jQuery" }]
    }]
} 

Solution: Separate multiple exports with a comma.

Usecase: Expose multiple members

Requirement: Expose exports member1 and member2 from module example.js to globals member1 and member2

module: {
    rules: [{ 
        "test": "./example.js", 
        "use": [{ "loader": "multi-expose-loader", "options": "#member1,#member2" }]
    }]
} 

Solution: Indicate members with a leading #

Usecase: Expose multiple members to alias names

Requirement: Expose exports member1 and member2 from module example.js to globals alias1 and alias2

module: {
    rules: [{ 
        "test": "./example.js", 
        "use": [{ "loader": "multi-expose-loader", "options": "alias1:#member1,alias2:#member2" }]
    }]
} 

Solution: Seperate alias and member with a colon

Usecase: Expose to namespaces in the global environment

Requirement: Expose to namespace

module: {
    rules: [{ 
        "test": "./example.js", 
        "use": [{ "loader": "multi-expose-loader", "options": "namespace1.alias1:#member1,namespace2.alias2:#member2" }]
    }]
} 

Solution: Give the point separated path to the alias

Alternative configurations

Of course, the configuration can also be made via import or require. Examples:

import  'multi-expose-loader?$,jQuery!jquery'; 

require('multi-expose-loader?#namespace1.member1,alias2:#member2!./example.js');

Code generation

Unlike the expose-loader, only one webpack module is generated. For example, it looks like this:

/* 63 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
/* WEBPACK VAR INJECTION */(function(global) {

var __multi_expose_loader_exports = __webpack_require__(64);
global["alias1"] = __multi_expose_loader_exports.member1;
if (!global["namespace2"]) global["namespace2"] = {};
global["namespace2"]["alias2"] = __multi_expose_loader_exports.member2;
globalmodule.exports = global["global1"] = global["global2"] = __multi_expose_loader_exports;
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(3)))

/***/ }) 

Peer dependencies

The peer dependencies are webpack 2 and 3. I think it also works in 4, but without testing I added this webpack version not to the peers.

License

MIT (http://www.opensource.org/licenses/mit-license.php)