What is null-loader?
The null-loader npm package is a webpack loader that returns an empty module. It is useful for ignoring specific files or modules during the build process, effectively making them 'null' or non-existent in the final bundle.
What are null-loader's main functionalities?
Ignore specific files
This feature allows you to ignore all JavaScript files in your project. The null-loader will replace the content of these files with an empty module, effectively removing them from the final bundle.
module.exports = {
module: {
rules: [
{
test: /\.js$/,
use: 'null-loader'
}
]
}
};
Ignore specific modules
This feature allows you to ignore a specific module, such as 'some-module'. The null-loader will replace the content of this module with an empty module, effectively removing it from the final bundle.
module.exports = {
module: {
rules: [
{
test: /some-module/,
use: 'null-loader'
}
]
}
};
Other packages similar to null-loader
ignore-loader
The ignore-loader package is similar to null-loader in that it allows you to ignore specific files or modules during the build process. However, instead of replacing the content with an empty module, it simply ignores the files, which can be useful for different use cases.
file-loader
The file-loader package is used to resolve import/require() on a file into a url and emit the file into the output directory. While it doesn't ignore files like null-loader, it can be used to manage how files are included in the bundle, providing more control over file handling.
url-loader
The url-loader works similarly to file-loader but can also inline files as base64 URIs. It provides more flexibility in handling files, especially for small assets that can be inlined to reduce the number of requests. It doesn't ignore files but offers different file management capabilities.

null-loader
A webpack loader that returns an empty module.
One use for this loader is to silence modules imported by a dependency. Say, for
example, your project relies on an ES6 library that imports a polyfill you don't
need, so removing it will cause no loss in functionality.
Getting Started
To begin, you'll need to install null-loader
:
$ npm install null-loader --save-dev
Then add the loader to your webpack
config. For example:
const path = require('path');
module.exports = {
module: {
rules: [
{
test: path.resolve(__dirname, 'node_modules/library/polyfill.js'),
use: 'null-loader',
},
],
},
};
And run webpack
via your preferred method.
Contributing
Please take a moment to read our contributing guidelines if you haven't yet done so.
CONTRIBUTING
License
MIT