expose-loader
expose loader module for webpack
Last updated 10 months ago by michael-ciniawsky .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install expose-loader 
SYNC missed versions from official npm registry.

npm deps chat

Expose Loader

The expose loader adds modules to the global object. This is useful for debugging, or supporting libraries that depend on libraries in globals.

Install

npm i expose-loader --save

Usage

Note: Modules must be require()'d within in your bundle, or they will not be exposed.

require("expose-loader?libraryName!./file.js");
// Exposes the exports for file.js to the global context on property "libraryName".
// In web browsers, window.libraryName is then available.

For example, let's say you want to expose jQuery as a global called $:

require("expose-loader?$!jquery");

Thus, window.$ is then available in the browser console.

Alternately, you can set this in your config file:

webpack v1 usage

module: {
  loaders: [
    { test: require.resolve("jquery"), loader: "expose-loader?$" }
  ]
}

webpack v2 usage

module: {
  rules: [{
          test: require.resolve('jquery'),
          use: [{
              loader: 'expose-loader',
              options: '$'
          }]
      }]
}

Let's say you also want to expose it as window.jQuery in addition to window.$. For multiple expose you can use ! in loader string:

webpack v1 usage

module: {
  loaders: [
    { test: require.resolve("jquery"), loader: "expose-loader?$!expose-loader?jQuery" },
  ]
}

webpack v2 usage

module: {
  rules: [{
          test: require.resolve('jquery'),
          use: [{
              loader: 'expose-loader',
              options: 'jQuery'
          },{
              loader: 'expose-loader',
              options: '$'
          }]
      }]
}

The require.resolve is a Node.js call (unrelated to require.resolve in webpack processing). require.resolve gives you the absolute path to the module ("/.../app/node_modules/react/react.js"). So the expose only applies to the react module. And it's only exposed when used in the bundle.

Maintainers


Juho Vepsäläinen

Joshua Wiens

Kees Kluskens

Sean Larkin

Current Tags

  • 0.7.5                                ...           latest (10 months ago)

11 Versions

  • 0.7.5                                ...           10 months ago
  • 0.7.4                                ...           a year ago
  • 0.7.3                                ...           2 years ago
  • 0.7.2                                ...           2 years ago
  • 0.7.1                                ...           3 years ago
  • 0.7.0                                ...           4 years ago
  • 0.6.0                                ...           4 years ago
  • 0.5.3                                ...           5 years ago
  • 0.5.2                                ...           5 years ago
  • 0.5.1                                ...           5 years ago
  • 0.5.0                                ...           6 years ago
Downloads
Today 60
This Week 1,966
This Month 5,676
Last Day 329
Last Week 2,281
Last Month 10,440
Dependencies (0)
None
Dev Dependencies (1)
Dependents (301)

Copyright 2014 - 2017 © taobao.org |