Skip to content

Commit 5234838

Browse files
committed
feat($config): Mock-out Node.js libraries to secure the run-time in the browser
1 parent 1250f60 commit 5234838

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

config/webpack.config.dev.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,5 +197,15 @@ module.exports = {
197197
new HotModuleReplacementPlugin(),
198198

199199
new NamedModulesPlugin()
200-
]
200+
],
201+
202+
// Some libraries import Node modules but don't use them in the browser.
203+
// Tell Webpack to provide empty mocks for them so importing them works.
204+
node: {
205+
dgram: 'empty',
206+
fs: 'empty',
207+
net: 'empty',
208+
tls: 'empty',
209+
child_process: 'empty',
210+
},
201211
};

config/webpack.config.prod.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,5 +242,14 @@ module.exports = {
242242
// Don't precache sourcemaps (they're large) and build asset manifest:
243243
staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/]
244244
})
245-
]
245+
],
246+
// Some libraries import Node modules but don't use them in the browser.
247+
// Tell Webpack to provide empty mocks for them so importing them works.
248+
node: {
249+
dgram: 'empty',
250+
fs: 'empty',
251+
net: 'empty',
252+
tls: 'empty',
253+
child_process: 'empty',
254+
},
246255
};

0 commit comments

Comments
 (0)