š¤ Modern Module is a zero-config starter template that allows you to create modern npm packages with support for both CommonJS modules (Node) and ES modules (browser + Node) out of the box providing no-hassle modern creating of modules. š
By using it you are creating a hybrid-module and a cross-over until ES modules become a standard in Node too and CommonJS modules become obsolete. š¤øāāļø
š·Ā Ā Node support,
Ā Ā Ā Ā Ā Ā Ā Ā CommonJS modules and ES modules compatible
š«Ā Ā browser supportĀ¹ - ES modules compatible,
Ā Ā Ā Ā Ā Ā Ā Ā other module systems are available too
ā”Ā Ā zero-config,
š„Ā Ā JavaScript supported,
āļøĀ Ā TypeScript supported,
šĀ Ā modules interoperability,
š“Ā Ā tree-shaking supported,
šĀ Ā single codebase for you to mantain,
š¦Ā Ā codebase written in ES modules style,
š¦Ā Ā type-checked codebase,
š³Ā Ā TypeScript declarations (*.d.ts
) exported by default,
š¦Ā Ā transpilation supported.
Ā¹ - if you don't use Node-specific code, of course.
šāāļøĀ For compatibility reasons this starter usesĀ .jsĀ file extension for the ES modules code andĀ .cjsĀ for CommonJS module code which in turn allows ES modules to be consumed by both Node and compatible browsers while also fixing a Node module lookup issue which currently occurs in Visual Studio Code and probably other Node-compatible editors/IDEs causing them to show an error when importingĀ .mjsĀ modules. CommonJS modulesĀ .cjsĀ behave as expected. Also, TypeScript compiler doesn't support non-.jsĀ files when generatingĀ d.tsĀ declaration files.
Another thing to consider, when consuming ES modules, (most) servers are not configured to serve .mjs
files with a mime type of application/javascript
which is necessary for JavaScript files (including modules) to work properly while the same does not happen when ES modules have the "regular" .js
extension.