Registry / devops / script-loader

script-loader

JSON →
library0.7.2jsnpmunverified

A webpack loader that executes JavaScript files once in the global context, useful for loading legacy scripts or libraries that pollute the global scope. Current stable version is 0.7.2, last released September 2017. This loader is part of the webpack-contrib organization and has minimal dependencies. It differs from imports-loader or expose-loader by executing scripts directly, without module wrapping. Does not work in Node.js; designed exclusively for browser bundles. The project is effectively in maintenance mode with no recent updates.

npm install script-loader
INSTALL
IMPORT
SIG · SCRIPT-LOADER
S
script-loader
devopsjavascriptv0.7.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default import (webpack loader)
import exec from 'script-loader!./script.js';
import exec from './script.js'; // no loader
Use as a webpack loader via inline import or in webpack.config.js rules.
require with loader
const exec = require('script-loader!./script.js');
const exec = require('./script.js'); // missing script-loader
CommonJS require works as well.
webpack.config.js rule
use: ['script-loader']
use: ['script-loader?'] // no query params supported
Configure via module.rules for files matching pattern like *.exec.js.

Configures script-loader to execute .exec.js files in the global context. Shows installation, webpack config, and a sample script that sets a global variable.

# Install npm install --save-dev script-loader # webpack.config.js module.exports = { module: { rules: [ { test: /\.exec\.js$/, use: ['script-loader'] } ] } }; # Example script.js // script.exec.js or import with script-loader! prefix // This file runs in global context var globalVar = 'I am global';
Debug
Known issues
gotchascript-loader does not work in Node.js; it is intended for browser bundles only.
fix
Do not use script-loader in Node.js. If needed, consider node-specific alternatives or dynamic require.
affects: >=0.7.0
gotchaScripts loaded with script-loader are executed in the global context, not in module scope. Variables declared without var/let/const will leak to window.
fix
Use script-loader only for scripts that intentionally pollute global scope (e.g., jQuery plugins). Use 'use strict' to prevent accidental globals.
affects: >=0.7.0
gotchaScript loader does not support query parameters; all configuration must be done via webpack config rules.
fix
If you need options, consider using 'imports-loader' or 'expose-loader' instead.
affects: >=0.7.0
Errors
Common errors & fixes
Module build failed: TypeError: Cannot read property 'replace' of undefined
The loader is being used on a file that doesn't exist or is not properly resolved.
fix
Ensure the file path is correct and webpack can resolve it. For inline usage, verify the path after 'script-loader!'.
Uncaught ReferenceError: <variable> is not defined
The script expects certain global variables to exist before execution, but they are not defined.
fix
Load dependencies in the correct order using multiple rules or ensure the global environment includes the needed definitions (e.g., via expose-loader).
Upgrade
Version history
0.7.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
script-loader — npm install script-loader · libregistry