Skip to content

Commit 9735a1f

Browse files
authored
chore: Replace custom externals with webpack-node-externals (#1814)
1 parent b27863d commit 9735a1f

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
"shelljs": "0.8.3",
119119
"sinon": "8.1.1",
120120
"webpack": "4.41.6",
121+
"webpack-node-externals": "1.7.2",
121122
"yauzl": "2.10.0"
122123
},
123124
"author": "Kumar McMillan",

webpack.config.js

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,10 @@
22
var path = require('path');
33

44
var webpack = require('webpack');
5-
6-
var nodeModules = {};
7-
85
// Do not bundle any external module, because those are explicitly added as
96
// "dependencies" in package.json. Bundling them anyway could result in bugs
107
// like https://github.com/mozilla/web-ext/issues/1629
11-
Object.keys(require('./package.json').dependencies)
12-
.forEach(function(mod) {
13-
nodeModules[mod] = 'commonjs ' + mod;
14-
});
15-
16-
// Allow use of importing parts of an external module, without bundling them.
17-
function nodeModulesExternalsHandler(context, request, callback) {
18-
var mod = request.split('/', 1)[0];
19-
if (Object.prototype.hasOwnProperty.call(nodeModules, mod)) {
20-
callback(null, 'commonjs ' + request);
21-
return;
22-
}
23-
callback();
24-
}
8+
var nodeExternals = require('webpack-node-externals');
259

2610
var rules = [
2711
{
@@ -50,8 +34,11 @@ module.exports = {
5034
rules,
5135
},
5236
externals: [
53-
nodeModules,
54-
nodeModulesExternalsHandler,
37+
nodeExternals({
38+
modulesFromFile: {
39+
include: ['dependencies'],
40+
},
41+
}),
5542
],
5643
plugins: [
5744
new webpack.BannerPlugin({

0 commit comments

Comments
 (0)