π€ 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.