script-loader essentially allows JavaScript to be loaded in a single instance. This applies globally throughout your project. Let's set this up by going through the following steps:
- To install script-loader, type the following in the command line:
npm install --save-dev script-loader
Note that this doesn't work in Node.js.
- Use webpack.config.js to configure Webpack, which will export exec from 'script.exec.js';.:
module.exports = {
module: {
rules: [{
test: /.exec.js$/,
use: ['script-loader']
}]
}
}
There is also an inline way of doing this, as follows:
import exec from 'script-loader!./script.js';
That should be all you need to be able to use script-loader with your Webpack application. Next is source-map-loader.