Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Tomorrow's ECMAScript modules today!

License

NotificationsYou must be signed in to change notification settings

PolymerLabs/esm

 
 

Repository files navigation

A fast, production ready, zero-dependency ES module loader for Node 6+!

See the releasepostandvideo for all the details.

Install

  • New projects

    Runnpm init esm oryarn create esm.

    💡 Use the-y flag to answer “yes” to all prompts.

  • Existing projects

    Runnpm i esm oryarn add esm.

Getting started

There are two ways to enableesm.

  1. Enableesm for packages:

    Useesm to load the main ES module and export it as CommonJS.

    index.js

    // Set options as a parameter, environment variable, or rc file.require=require("esm")(module/*, options*/)module.exports=require("./main.js")

    main.js

    // ESM syntax is supported.export{}

    💡 These files are automagically created withnpm init esm oryarn create esm.

  2. Enableesm for local runs:

    node -r esm main.js

    💡 Omit the filename to enableesm in the REPL.

Features

Theesm loader bridges the ESM oftoday to theESM oftomorrow.

👏 By default, 💯 percent CJS interoperability is enabled so you can get stuff done fast.
🔒.mjs files are limited to basic functionality without support foresm options.

Out of the boxesm just works, no configuration necessary, and supports:

Options

Specify options with one of the following:

  • "esm" field inpackage.json
  • CJS/ESM in an.esmrc.js or.esmrc.mjs file
  • JSON6 in an.esmrc or.esmrc.json file
  • JSON6 or file path in theESM_OPTIONS environment variable
  • ESM_DISABLE_CACHE environment variable
{
"cjs":true

A boolean or object for toggling CJS features in ESM.

Features
{
"cache":true

A boolean for storing ES modules inrequire.cache.

"esModule":true

A boolean for__esModule interoperability.

"extensions":true

A boolean for respectingrequire.extensions in ESM.

"mutableNamespace":true

A boolean for mutablenamespace objects.

"namedExports":true

A boolean forimporting named exports of CJS modules.

"paths":true

A boolean for following CJSpath rules in ESM.

"vars":true

A boolean for__dirname,__filename, andrequire in ESM.

"dedefault":false

A boolean for requiring ES modules without the danglingrequire().default.

"topLevelReturn":false

A boolean for top-levelreturn support.

}
"mainFields":["main"]

An array of fields checked when importing a package.

"mode":"auto"

A string mode:

  • "auto" detect files withimport,import.meta,export,
    "use module", or.mjs as ESM.
  • "all" script files are treated as ESM.
  • "strict" to treatonly.mjs files as ESM.
"await": false

A boolean fortop-levelawait in modules without ESM exports.(Node 10+)

"force":false

A boolean to apply these options to all module loads.

"wasm":false

A boolean forWebAssembly module support.(Node 8+)

}

DevOpts

{
"cache":true

A boolean for toggling cache creation or cache directory path.

"sourceMap":false

A boolean for including inline source maps.

}

Tips

Bundling

  • For bundlers likebrowserify+esmify,parcel-bundler, andwebpackadd a"module" field topackage.json pointing to the main ES module.

    "main":"index.js","module":"main.js"

    💡 This is automagically done withnpm init esm oryarn create esm.

Extensions

Loading

About

Tomorrow's ECMAScript modules today!

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript99.9%
  • Other0.1%

[8]ページ先頭

©2009-2025 Movatter.jp