Skip to content
This repository has been archived by the owner on Dec 29, 2019. It is now read-only.

Better support for node core modules? #6

Open
billiegoose opened this issue Sep 21, 2017 · 5 comments
Open

Better support for node core modules? #6

billiegoose opened this issue Sep 21, 2017 · 5 comments

Comments

@billiegoose
Copy link

I'm trying to use a lot of modules that were originally written for browserify and really jumping through a lot of hoops. Is that a use case you'd be willing to consider? I believe it would be a matter of adding new entries in getlibs/config/ for assert, util, and so on that point at the correct browserify shims.

@xkam
Copy link
Contributor

xkam commented Sep 23, 2017

Should I map node built-in packages to https://www.npmjs.com/package/browser-builtins ?

@xkam
Copy link
Contributor

xkam commented Sep 23, 2017

Looks like browserify no longer relies on browser-builtins bundle but maps to individual packages - https://unpkg.com/[email protected]/lib/builtins.js . So I guess I should do the same thing here.

@billiegoose
Copy link
Author

I spent a while looking at this topic yesterday... namely comparing https://github.com/calvinmetcalf/rollup-plugin-node-builtins and https://unpkg.com/[email protected]/lib/builtins.js. Unfortunately, some of the choices rollup makes (like buffer-es6) are just forks of the browserify versions that are not as well maintained. (buffer-es6 is a good 100 commits behind buffer). I ultimately decided not to use rollup-plugin-node-builtins but rather use both rollup and browserify in consecutive build steps.

So... that illustrates the wonderful wonderful thing about getlibs I like so much. When it works It just works (TM). None of these awful build tools... which are wonderful yes, but now that I've tasted dynamic module loading I can't see how anyone would ever want to go back.

I'm rambling off topic. Yes, let's use the mappings in https://unpkg.com/[email protected]/lib/builtins.js except for the empty ones and ones that don't make sense. (console?)

@billiegoose
Copy link
Author

billiegoose commented Sep 23, 2017

Test playground: https://codepen.io/wmhilton/project/editor/XbNoRz

Using configuration:

  System.config({
  meta: {
    //util: {loader: 'js'}
  },
  map: {
    assert: 'https://unpkg.com/assert',
    buffer: 'https://unpkg.com/buffer',
    crypto: 'https://unpkg.com/crypto-browserify',
    domain: 'https://unpkg.com/domain-browser',
    events: 'https://unpkg.com/events',
    http: 'https://unpkg.com/stream-http',
    https: 'https://unpkg.com/https-browserify',
    os: 'https://unpkg.com/os-browserify',
    path: 'https://unpkg.com/path-browserify',
    punycode: 'https://unpkg.com/punycode',
    querystring: 'https://unpkg.com/querystring',
    stream: 'https://unpkg.com/stream-browserify',
    util: 'https://unpkg.com/util/util.js',
    'util/': 'https://unpkg.com/util/util.js',
    tty: 'https://unpkg.com/tty-browserify',
    url: 'https://unpkg.com/url',
    vm: 'https://unpkg.com/vm-browserify',
    zlib: 'https://unpkg.com/browserify-zlib',
    process: 'https://unpkg.com/process'
  }
})
System.load('./main.js')

Here's my results so far. commented out ones fail.

const { Buffer } = require('buffer');
alert(Buffer.isBuffer);
global.Buffer = Buffer

alert(require('process'));
global.process = require('process');

alert(require('assert'));
//alert(require('crypto'));
alert(require('domain'));
alert(require('events'));
//alert(require('http'));
//alert(require('https'));
alert(require('os'));
alert(require('path'));
alert(require('punycode'));
//alert(require('querystring'));
alert(require('stream'));
alert(require('util'));
alert(require('tty'));
alert(require('vm'));
//alert(require('zlib'));
//alert(require('url'));

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants