All Projects β†’ transitive-bullshit β†’ npm-es-modules

transitive-bullshit / npm-es-modules

Licence: other
Breakdown of 7 different ways to use ES modules with npm today.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to npm-es-modules

nanobundle
Yet another build tool for libraries, powered by esbuild
Stars: ✭ 45 (-32.84%)
Mutual labels:  commonjs, esmodules, esm
Wmr
πŸ‘©β€πŸš€ The tiny all-in-one development tool for modern web apps.
Stars: ✭ 4,372 (+6425.37%)
Mutual labels:  rollup, esmodules
Esm
Tomorrow's ECMAScript modules today!
Stars: ✭ 5,093 (+7501.49%)
Mutual labels:  esmodules, esm
Webpack
A bundler for javascript and friends. Packs many modules into a few bundled assets. Code Splitting allows for loading parts of the application on demand. Through "loaders", modules can be CommonJs, AMD, ES6 modules, CSS, Images, JSON, Coffeescript, LESS, ... and your custom stuff.
Stars: ✭ 60,034 (+89502.99%)
Mutual labels:  commonjs, esm
mock-spy-module-import
JavaScript import/require module testing do's and don'ts with Jest
Stars: ✭ 40 (-40.3%)
Mutual labels:  commonjs, esm
Jsdelivr
A free, fast, and reliable Open Source CDN for npm, GitHub, Javascript, and ESM
Stars: ✭ 4,052 (+5947.76%)
Mutual labels:  esmodules, esm
Cjstoesm
A tool that can transform CommonJS to ESM
Stars: ✭ 109 (+62.69%)
Mutual labels:  commonjs, rollup
absurdum
The Ridiculous Application of Reduce
Stars: ✭ 61 (-8.96%)
Mutual labels:  esmodules, esm
babel-plugin-rewire-exports
Babel plugin for stubbing [ES6, ES2015] module exports
Stars: ✭ 62 (-7.46%)
Mutual labels:  rollup, esm
motion-hooks
A simple Hooks wrapper over Motion One, An animation library, built on the Web Animations API for the smallest filesize and the fastest performance.
Stars: ✭ 93 (+38.81%)
Mutual labels:  rollup, esm
unpack
Create Web apps without a bundler
Stars: ✭ 39 (-41.79%)
Mutual labels:  esmodules, esm
vitext
The Next.js like React framework for better User & Developer experience!
Stars: ✭ 376 (+461.19%)
Mutual labels:  rollup, esm
tape-es
ESM-compatible Tape.js test runner
Stars: ✭ 24 (-64.18%)
Mutual labels:  esmodules, esm
oletus
Minimal ECMAScript Module test runner
Stars: ✭ 43 (-35.82%)
Mutual labels:  esmodules, esm
extract-files
A function to recursively extract files and their object paths within a value, replacing them with null in a deep clone without mutating the original value. FileList instances are treated as File instance arrays. Files are typically File and Blob instances.
Stars: ✭ 48 (-28.36%)
Mutual labels:  esm
timezz
With this plugin, you can easily make a stopwatch or timer on your site. Just init, style and enjoy.
Stars: ✭ 35 (-47.76%)
Mutual labels:  commonjs
yantra
JavaScript Engine for .NET Standard
Stars: ✭ 32 (-52.24%)
Mutual labels:  commonjs
rollup-plugin-jscc
Conditional compilation and compile-time variable replacement for Rollup
Stars: ✭ 52 (-22.39%)
Mutual labels:  rollup
rollup-jest-boilerplate
πŸŽ‰ Full featured boilerplate for building JavaScript libraries the modern way
Stars: ✭ 81 (+20.9%)
Mutual labels:  rollup
array-sort-by
Powerful mechanism to sort arrays or array of objects by one or more properties. You can also specify a custom comparer function.
Stars: ✭ 37 (-44.78%)
Mutual labels:  commonjs

npm-es-modules

Breakdown of 7 different ways to use ES modules with npm today.

Build Status JavaScript Style Guide

ES Modules are the future of JavaScript, but unlike many other es@next features that developers have raced to take advantage of mainly thanks to build tools like babel, working with ES modules alongside of existing NPM modules is a lot harder to get started with.

The purpose of this tutorial is to provide a thorough set of examples for different ways you can approach writing ES modules, without losing interop with the vast library of mostly commonjs modules that exist on NPM today.

We'll start with a naive ES module in step 1 and work our way through a series of increasingly complex example approaches, all of which are intended to define the same, basic module.

Goals

Every approach must satisfy the following requirements:

  • generate a valid npm module
  • support the same consistent functionality
  • be usable from both node.js and browser environments
  • import at least one existing commonjs module from npm
  • import at least one es module source file locally
  • include at least one unit test

Functionality

The functionality of our example NPM module is a bit contrived, but it should touch on all the potential pain points, and trust me, there are a lot of them...

Every approach will define an NPM module with a single default export, async getImageDimensions(input), that takes in an image and returns its { width, height }.

To show how you can bundle modules with slightly different semantics for Node.js and the browser:

  • the node version supports input as a string that can either be a local path, http url, or data url.
  • the browser version supports input as a string URL or an HTMLImageElement.

Both versions return a Promise for { width: number, height: number }.

Approaches

  1. naive - The most naive possible use of ES modules supporting our functionality. This approach is broken and provided as an example starting point.
  2. babel - Uses babel to transpile all Node.js and browser source files.
  3. esm-rollup - Uses esm for Node.js and babel+rollup to compile browser source files.
  4. esm-webpack - Uses esm for Node.js and babel+webpack to compile browser source files.
  5. rollup - Uses babel+rollup to compile all Node.js and browser source files.
  6. webpack - Uses babel+webpack to compile all Node.js and browser source files.
  7. typescript - Uses typescript to transpile all Node.js and browser source files.

Related

  • esm - Tomorrow's ECMAScript modules today!
  • babel - A compiler for writing next generation JavaScript.
  • rollup - A module bundler for JavaScript.
  • webpack - A bundler for javascript and friends.
  • typescript - TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.
  • systemjs - Configurable module loader enabling dynamic ES module workflows in browsers and NodeJS.

Related Tutorials

License

MIT Β© Travis Fischer

Support my OSS work by following me on twitter twitter

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].