npm-es-modules

授权协议 Readme
开发语言 JavaScript
所属分类 Web应用开发、 常用JavaScript包
软件类型 开源软件
地区 不详
投 递 者 全流觞
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

npm-es-modules

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

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

 相关资料
  • JSDoc3 能够记录遵循ECMAScript 2015规范的模块。ES 2015 模块在JSDoc3.4.0及更高版本中支持。 Module identifiers(模块标识符) 当你描述一个 ES 2015 module(模块)时,您将使用@module 标签来描述模块的标识符。例如,如果用户通过调用import * as myShirt from 'my/shirt' 加载模块,你会写一个包

  • 背景 canal 1.1.1版本之后, 内置增加客户端数据同步功能, Client适配器整体介绍: [[ClientAdapter]] canal adapter 的 Elastic Search 版本支持6.x.x以上, 如需其它版本的es可替换依赖重新编译client-adapter.elasticsearch模块 ElasticSearch适配器 1 修改启动器配置: application

  • 未来的模块 TC39,负责讨论ECMAScript语法和语义定义问题和其未来迭代的标准机构,它是由许多的非常聪明的开发者组成的。这些开发者中的一些人(比如Alex Russell)对Javascript在大规模开发中的用例场景在过去几年一直保持者密切的关注,并且敏锐的意识到了人们对于能够使用其编写更加模块化JS的优良的语言特性的需求。 出于这个原因,目前已经有大量激动人心的,包括在客户端和服务器上

  • 框架简介 ES 是一款 极简、灵活、 高性能、扩建性强、上手快php 框架; 以“快速开发、轻松上手、高速执行”为理念,助你成为web开发的能手 ! 开发缘由 与其说开发此框架,更准确说法应该是一次代码的整理,本人在接触将近10年的php开发过程中,陆续也接触了一些优秀的框架。不仅仅php 有asp.net mvc、php laravel、php yii、python web.py、python

  • 为简化开发工作、提高生产效率而生 Easy-Es是一款简化 ElasticSearch 搜索引擎操作的开源框架,全自动智能索引托管。 目前功能丰富度和易用度及性能已全面领先SpringData-Elasticsearch. 简化CRUD及其它高阶操作,可以更好的帮助开发者减轻开发负担 底层采用Es官方提供的RestHighLevelClient,保证其原生性能及拓展性. 项目推广初期,还望大家能够

  • Searchdaimon ES是一个针对公司数据和网站的搜索引擎,拥有一个功能强大的管理员界面。ES可以索引一些常用的企业系统中的数据,比如SharePoint、Exchange、SQL数据库、Windows文件共享等,它还支持多种数据源,比如Word、PDF、Excel等。 ES可以作为搜索软件的一个集成套件来部署,你可以将其部署到类似于Amazon Web Services的云平台上,也可以部