Skip to content

Commit fec3cfd

Browse files
committed
Shim process.
1 parent 971db65 commit fec3cfd

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

browser/process.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Based on https://github.com/defunctzombie/node-process
2+
// Copyright (c) 2013 Roman Shtylman <shtylman@gmail.com>
3+
4+
// Changes:
5+
// - use setImmediate for process.nextTick
6+
7+
var process = module.exports = {};
8+
9+
process.nextTick = setImmediate;
10+
11+
process.title = 'browser';
12+
process.browser = true;
13+
process.env = {};
14+
process.argv = [];
15+
process.version = ''; // empty string to avoid regexp issues
16+
process.versions = {};
17+
18+
function noop() {}
19+
20+
process.on = noop;
21+
process.addListener = noop;
22+
process.once = noop;
23+
process.off = noop;
24+
process.removeListener = noop;
25+
process.removeAllListeners = noop;
26+
process.emit = noop;
27+
process.prependListener = noop;
28+
process.prependOnceListener = noop;
29+
30+
process.listeners = function (name) { return [] }
31+
32+
process.binding = function (name) {
33+
throw new Error('process.binding is not supported');
34+
};
35+
36+
process.cwd = function () { return '/' };
37+
process.chdir = function (dir) {
38+
throw new Error('process.chdir is not supported');
39+
};
40+
process.umask = function() { return 0; };

webpack/webpack.common.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ module.exports = ({ outputDir }) => ({
2727
new CleanWebpackPlugin([outputDir]),
2828
// Use latest readable-stream version (as opposed to stream-browserify)
2929
new NormalModuleReplacementPlugin(/^stream$/, require.resolve('readable-stream/readable-browser')),
30+
// Shim process to use faster process.nextTick implementation
31+
new NormalModuleReplacementPlugin(/process\/browser\.js$/, require.resolve('../browser/process')),
3032
],
3133
externals: {
3234
'solid-auth-client': ['solid', 'auth'],

0 commit comments

Comments
 (0)