Giter Site home page Giter Site logo

Browser support about node-envelope HOT 4 OPEN

jhermsmeier avatar jhermsmeier commented on June 8, 2024
Browser support

from node-envelope.

Comments (4)

jhermsmeier avatar jhermsmeier commented on June 8, 2024

Producing a UMD build can easily be done with browserify – which is something we could add, so I don't really see the need to convert to ESM here (yet) – unless you have some convincing arguments?

from node-envelope.

brettz9 avatar brettz9 commented on June 8, 2024

Besides the ESM support already available in Node 12 through the --experimental-modules flag, IIRC, browserify, unlike Rollup, doesn't support making an ESM distribution, so one couldn't have an ESM build that could be imported in the browser). (I can't Google now to find the issue, as behind firewall in China with no working VPN.)

I like to use ESM in browser demos as it allows working against source without a build step. But this is not a pressing need for me at the moment. I just figured if making the steps to ensure the bundles worked in the browser, that one might as well future-proof the code and provide that functionality along the way.

from node-envelope.

jhermsmeier avatar jhermsmeier commented on June 8, 2024

IIRC, browserify, unlike Rollup, doesn't support making an ESM distribution, so one couldn't have an ESM build that could be imported in the browser).

Right – that's not supported yet. Would having dedicated browserify bundle with a global export help with that (i.e. browser/envelope.min.js which exposes Envelope)? I'm not familiar with rollup, but I'll test some things later and let you know what the conclusions are.

from node-envelope.

brettz9 avatar brettz9 commented on June 8, 2024

A global export would be helpful, sure, whether in a browser-specific build (wrapping the code in an IIFE to avoid conflicts and just setting the global window, this, or self), or UMD (i.e., combining global setting with Node/CJS and AMD support). (Rollup exposes these with its output.format as "iife" or "umd", or also allowing "cjs" for Node only and "esm" for the proposed ESM distribution.)

So while a regular global would satisfy the major concern of this issue, I happen to prefer ESM for avoiding any globals or keeping track of dependencies out of context within my HTML.

Rollup is very well documented and easy to setup and use (compared to Webpack or even Browserify), with the small caveat that you generally need to use plugins when importing npm dependencies (@rollup/plugin-node-resolve, and if the deps. don't themselves have an ESM export, e.g., as indicated in module of package.json, then also @rollup/plugin-commonjs and if you need native Node module polyfills for the browser, possibly rollup-plugin-node-builtins) or if replacing require of JSON (i.e., @rollup/plugin-json); and to minify one needs rollup-plugin-terser or such (and if babelifying, rollup-plugin-babel--all of which I have found work well).

Rollup also has the advantage of working with parcel, a popular means of making it easy to smoothly facilitate the installation of modules without users needing to manually manage this config.

from node-envelope.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.