generated from trytelework/MIT-node-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (39 loc) · 948 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* @license MIT
*/
/**
* @fileoverview
* A plugin which replaces any optional dependencies in a module's package.json.
*/
const webpack = require('webpack');
const noop = require('noop-webpack-plugin');
/**
* Generate a regex matcher for the source replacement.
*
* @param {...string} packages
* The list of packages to generate a regex match for.
*
* @return {RegExp} matcher
*/
const getDependencyRegex = (...packages) => {
return new RegExp(packages.join('|'));
};
/**
* Generate the actual plugin to provide Webpack.
*
* @param {...string} packages
* The packages to disable.
*
* @return {webpack.NormalModuleReplacementPlugin}
* The generated Module Replacement Plugin.
*/
const disablePackages = (...packages) => {
if (!packages.length) {
return noop();
}
return new webpack.NormalModuleReplacementPlugin(
getDependencyRegex(...packages),
'empty',
);
};
module.exports = disablePackages;