https://github.com/webpack-contrib/script-loader
[deprecated] Script Loader
https://github.com/webpack-contrib/script-loader
webpack-loader
Last synced: 8 months ago
JSON representation
[deprecated] Script Loader
- Host: GitHub
- URL: https://github.com/webpack-contrib/script-loader
- Owner: webpack-contrib
- License: mit
- Archived: true
- Created: 2012-04-07T02:16:16.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2019-11-05T13:53:35.000Z (over 6 years ago)
- Last Synced: 2025-06-13T00:06:25.440Z (9 months ago)
- Topics: webpack-loader
- Language: JavaScript
- Homepage:
- Size: 85.9 KB
- Stars: 326
- Watchers: 18
- Forks: 44
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[![npm][npm]][npm-url]
[![node][node]][node-url]
[![deps][deps]][deps-url]
[![chat][chat]][chat-url]
# ! NO LONGER MAINTAINED !
This module is deprecated and will no longer be maintained.
It has a known issue of generating non-deterministic hashes (see #49, #56, #60).
*Do not use it.*
In most cases, you can replace the functionality by using `raw-loader` instead:
```diff
- import('script-loader!someScript.js')
+ import('raw-loader!someScript.js').then(rawModule => eval.call(null, rawModule.default))
```
If you need some transformations to be applied to the script you want to load, you may need to find or write yourself a separate loader for that. Some documentation that might be helpful:
- https://webpack.js.org/loaders/
- https://webpack.js.org/concepts/loaders/
- https://webpack.js.org/contribute/writing-a-loader/
----------
Install
```bash
npm install --save-dev script-loader
```
Usage
Executes JS script once in global context.
> :warning: Doesn't work in NodeJS
### Config (recommended)
```js
import './script.exec.js';
```
**webpack.config.js**
```js
module.exports = {
module: {
rules: [
{
test: /\.exec\.js$/,
use: [ 'script-loader' ]
}
]
}
}
```
### Inline
```js
import 'script-loader!./script.js';
```
## Options
| Name | Type | Default | Description |
| :-----------------------------------------: | :-------------------: | :-------------: | :------------------------------------------ |
| **[`sourceMap`](#sourcemap)** | `{Boolean}` | `false` | Enable/Disable Sourcemaps
| **[`useStrict`](#usestrict)** | `{Boolean}` | `true` | Enable/Disable useStrict
### `sourceMap`
Type: `Boolean`
Default: `false`
To include source maps set the `sourceMap` option.
**webpack.config.js**
```js
module.exports = {
module: {
rules: [
{
test: /\.script\.js$/,
use: [
{
loader: 'script-loader',
options: {
sourceMap: true,
},
},
]
}
]
}
}
```
### `useStrict`
Type: `Boolean`
Default: `true`
To disable use strict set the `useStrict` option to `false`.
**webpack.config.js**
```js
module.exports = {
module: {
rules: [
{
test: /\.script\.js$/,
use: [
{
loader: 'script-loader',
options: {
useStrict: false,
},
},
]
}
]
}
}
```
Maintainers
Juho Vepsäläinen
Joshua Wiens
Kees Kluskens
Sean Larkin
[npm]: https://img.shields.io/npm/v/script-loader.svg
[npm-url]: https://npmjs.com/package/script-loader
[node]: https://img.shields.io/node/v/script-loader.svg
[node-url]: https://nodejs.org
[deps]: https://david-dm.org/webpack/script-loader.svg
[deps-url]: https://david-dm.org/webpack/script-loader
[chat]: https://badges.gitter.im/webpack/webpack.svg
[chat-url]: https://gitter.im/webpack/webpack