Setup

The best way to start this section is to look at how we can develop and test a loader locally. This is a nice and palatable way to begin, and we will proceed as follows:

  1. When testing a single loader, you can simply use a path to resolve to a local file within a rule object in webpack.config.js, as follows:
module.exports = {
//...
module: {
rules: [
{
test: /.js$/,
use: [
{
loader: path.resolve('path/to/loader.js'),
options: {/* ... */}
}
]
}
]
}
};
  1. To test multiple loaders, you can utilize the resolveLoader.modules configuration, whereby Webpack will search for loaders in webpack.config.js. For example, if you had a local directory in your project with a loader inside of it, the code would look like this:
module.exports = {
resolveLoader: {
modules: [
'node_modules',
path.resolve(__dirname, 'loaders')
]
}
};

That should be all you need to begin. However, if you've already created a separate repository for your loader, you could use an npm link to the project in which you'd like to run the test.

There's more than one methodology depending on the usage of the loader, so—naturally—we will begin with simple usage.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.65.65