standard-things / esm
- суббота, 12 августа 2017 г. в 03:12:56
ES modules in Node today!
This fast, small, zero dependency, package is all you need to enable ES modules in Node 4+ today!
Run npm i --save @std/esm
in your app or package directory.
Call require("@std/esm")
before importing ES modules.
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'
The @std/esm
loader is as spec-compliant
as possible and follows Node’s rules.
.mjs
extension..js
use with the "esm":"js"
option.
Out of the box @std/esm
just works, no configuration necessary, and supports:
import
/ export
import()
.mjs
files as ESMUnlock 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.
|
|
"await": |
A boolean for top-level |
"gz": |
A boolean for gzipped module support (i.e.
|
"esm": |
A string ESM mode
|
"cjs": |
A boolean for CJS features in ESM
|
|