Giter Club home page Giter Club logo

expose-loader's Introduction

npm node deps tests chat

expose-loader

expose loader module for webpack

Requirements

This module requires a minimum of Node v6.9.0 and Webpack v4.0.0.

Getting Started

To begin, you'll need to install expose-loader:

$ npm install expose-loader --save-dev

Then add the loader to your webpack config. For example:

// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /.js/,
        use: [
          {
            loader: `expose-loader`,
            options: {...options}
          }
        ]
      }
    ]
  }
}

And then require the target file in your bundle's code:

// src/entry.js
require("expose-loader?libraryName!./thing.js");

And run webpack via your preferred method.

Examples

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.config.js
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.config.js
module: {
  rules: [{
    test: require.resolve('jquery'),
    use: [{
      loader: 'expose-loader',
      options: {
        expose: ['jQuery', '$']
      }
    }]
  }]
}

The require.resolve call is a Node.js function (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.

Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.

License

expose-loader's People

Contributors

cuongvo avatar e-pavlica avatar gaearon avatar gdborton avatar joshwiens avatar justin808 avatar kevinzwhuang avatar lencioni avatar michael-ciniawsky avatar shama avatar shellscape avatar simon04 avatar smmoosavi avatar sokra avatar timse avatar wgiddens avatar wilfred avatar wuxiandiejia avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.