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

shim-loader

v1.0.1

Published

makes traditional/legacy scripts compatible with webpack

Downloads

3,561

Readme

shim-loader npm package Build Status codecov

shim-loader makes traditional/legacy "browser globals" scripts compatible with webpack's module system. Based on the idea of RequireJS and browserify-shim.

Shimming in webpack is already possible with complicated configurations. Now it's easy!

Features

  • Shims non-CommonJS modules by specifying an alias and the identifier under which the module attaches itself to the global window object. Optionally you can specify the path to the module.
  • set up code relationships when libraries depends on other libraries being in the global namespace.
  • Makes define and also module be undefined, in order to fix improperly-authored libraries that need shimming but try anyway to use AMD or CommonJS.

When should I use this?

You should use this only when you have to use libraries that are incompatible with your desired module definition style or when you want to upgrade a legacy project to the present.

How does it work?

shim-loader is a webpack loader that transforms the code in a way that it works in the webpack environment. It's nearly the same as doing this manually with imports-loader and exports-loader.

Installation


$ npm install shim-loader --save-dev

Install shim-loader via npm and add the loader to your webpack config.

Configuration

webpack.config.js


var path = require('path');

var webpackShimConfig = {
  // Remember: Only use shim config for incompatible libraries
  // the libraries below are just examples, regardless whether they are compatible or not
  shim: {
    'jquery': {
      exports: 'jQuery' // Once loaded, use the global 'jQuery' as the module value.
    },
    'underscore': {
      exports: '_' // Once loaded, use the global '_' as the module value.
    },
    'backbone': {
      exports: 'Backbone' // Once loaded, use the global 'Backbone' as the module value.
      deps: [
        'underscore', // just make sure that underscore is loaded before (uses it's global value)
        'jquery:$', // Provide jquery as dependency with name $
      ]
    },
    'jquery.ui.core': {
      deps: [
        'jquery:jQuery', // Provide jquery as dependency with name jQuery
      ]
    },
    'jquery.ui.datepicker': {
      deps: [
        'jquery:jQuery', // Provide jquery as dependency with name jQuery
        'jquery.ui.core', // just make sure that jquery.ui.core is loaded before
      ]
    },
    'math': {
      // multiple export values are also possible,
      // they are returned as single object with the associated key for each value
      // e.g. module.exports = { add: function(){}, subtract: function(){} };
      exports: [
        'add', // exports add from global namespace as module value
        'subtract',  // exports subtract from global namespace as module value
      ]
    },
    // absolute paths are also possible
    [path.join(__dirname, 'bower_components/jquery-ui/ui/datepicker.js')]: {
      deps: [
          'jquery:jQuery', // Provide jquery as dependency with name jQuery
          'jquery.ui.core', // just make sure that jquery.ui.core is loaded before
        ]
    }
  },
  'masonry': {
      amd: false // disable AMD module style
      commonjs: true // and use CommonJS module style instead
  }
};

module.exports = {
  entry: './src/app.js',
  output: {
    path: './dist',
    filename: 'bundle.js',
  },
  resolve: {
    alias: {
      'jquery': path.join(__dirname, 'bower_components/jquery/dist/jquery.js'),
      'underscore': path.join(__dirname, 'bower_components/lodash/dist/lodash.underscore.js'),
      'backbone': path.join(__dirname, 'bower_components/backbone/backbone.js'),
      'jquery.ui.core': path.join(__dirname, 'bower_components/jquery-ui/ui/core.js'),
      'jquery.ui.datepicker': path.join(__dirname, 'bower_components/jquery-ui/ui/datepicker.js'),
    },
  },
  module: {
    loaders: [
      {
        // apply the loader to setup module shimming
        test: /\.js/
        loader: 'shim-loader',
        query: webpackShimConfig,
        // pass a list of directories or files to improve performance
        includes:  path.join(__dirname, 'bower_components'),
      }
    ]
  },
};

License

MIT