Sponsor webpack and get apparel from the official shop! All proceeds go to our open collective!

script-loader

Install

npm install --save-dev script-loader

Usage

Executes JS script once in global context.

:warning: Doesn't work in NodeJS

import exec from 'script.exec.js';

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.exec\.js$/,
        use: [ 'script-loader' ]
      }
    ]
  }
}

Inline

import exec from 'script-loader!./script.js';

Options

Name Type Default Description

Name

Type

Default

Description

sourceMap

{Boolean}

{Boolean} false Enable/Disable Sourcemaps

sourceMap

Type: Boolean Default: false

To include source maps set the sourceMap option.

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.script\.js$/,
        use: [
          {
            loader: 'script-loader',
            options: {
              sourceMap: true,
            },
          },
        ]
      }
    ]
  }
}

Maintainers


Juho Vepsäläinen

Joshua Wiens

Kees Kluskens

Sean Larkin