GithubHelp home page GithubHelp logo

esm's Introduction

@std/esm

This fast, small, zero dependency, package is all you need to enable ES modules in Node 4+ today!

πŸ“– See the release post for all the details.

Getting started

  1. Run npm i --save @std/esm in your app or package directory.

  2. Call require("@std/esm") before importing ES modules.

    index.js

    require("@std/esm")
    module.exports = require("./main.mjs").default

For package authors with sub modules:

// Have "foo" require only "@std/esm".
require("foo")
// Sub modules work!
const bar = require("foo/bar").default

Enable ESM in the Node CLI by loading @std/esm with the -r option:

node -r @std/esm file.mjs

Enable ESM in the Node REPL by loading @std/esm upon entering:

$ node
> require("@std/esm")
@std/esm enabled
> import path from "path"
undefined
> path.join("hello", "world")
'hello/world'

Standard Features

The @std/esm loader is as spec-compliant as possible and follows Node’s rules.

πŸ‘‰ This means, by default, ESM requires the use of the .mjs extension.
πŸ”“ You can unlock unambiguous .js use with the "esm":"js" option.

Out of the box @std/esm just works, no configuration necessary, and supports:

Unlockables

Unlock extra features with "@std/esm":options or "@std":{"esm":options} in your package.json.

Note: Options are off by default and may be specified as either an object or ESM mode string.

{
  "@std/esm": {
"await":

A boolean for top-level await in the main ES module

"gz":

A boolean for gzipped module support (i.e. .js.gz, .mjs.gz)

"esm":

A string ESM mode

  • "mjs" files as ESM (default)
  • "all" files as ESM
  • "js" files with import/export/"use module" as ESM
"cjs":

A boolean for CJS features in ESM

  }
}

esm's People

Contributors

abernix avatar benjamn avatar clayne11 avatar greenkeeper[bot] avatar greenkeeperio-bot avatar jdalton avatar olizilla avatar sebakerckhof avatar sokra avatar stanlindsey avatar

Watchers

 avatar  avatar

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.