Socket
Socket
Sign inDemoInstall

imports-loader

Package Overview
Dependencies
Maintainers
3
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

imports-loader

imports loader module for webpack


Version published
Weekly downloads
432K
decreased by-4.31%
Maintainers
3
Weekly downloads
 
Created

What is imports-loader?

The imports-loader npm package allows you to use custom imports in your modules. It is particularly useful for injecting variables or dependencies into modules that do not explicitly export them, or for polyfilling global variables.

What are imports-loader's main functionalities?

Injecting Variables

This feature allows you to inject variables into your modules. In this example, the jQuery library is injected into every JavaScript file, making the $ variable available globally.

module.exports = {
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        use: [
          {
            loader: 'imports-loader',
            options: {
              additionalCode: 'var $ = require("jquery");'
            }
          }
        ]
      }
    ]
  }
};

Polyfilling Global Variables

This feature allows you to polyfill global variables that may not be available in certain environments. In this example, the process variable is polyfilled using the 'process/browser' module.

module.exports = {
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        use: [
          {
            loader: 'imports-loader',
            options: {
              additionalCode: 'var process = require("process/browser");'
            }
          }
        ]
      }
    ]
  }
};

Injecting Dependencies

This feature allows you to inject dependencies into your modules. In this example, the lodash library is injected into every JavaScript file, making the _ variable available globally.

module.exports = {
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        use: [
          {
            loader: 'imports-loader',
            options: {
              imports: {
                moduleName: 'lodash',
                name: '_'
              }
            }
          }
        ]
      }
    ]
  }
};

Other packages similar to imports-loader

Keywords

FAQs

Package last updated on 12 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc