Skip to content

Improved file structure for Node.js

Compare
Choose a tag to compare
@motss motss released this 16 Mar 02:52

Notable changes

To support both different module systems in Node.js, there are 2 different types of modules are built:-

  1. index.mjs - ES Modules in Node.js favors .mjs extension.
  2. index.js - CommonJS in Node.js favors .js extension.

In package.json, by specifiying main: dist/index. The correct file will be picked up by the module system used by the users.

This allows more straightforward and intuitive approach when using the module without the need to worry much about which file is used correctly:

ES Modules

import { html } from 'lit-ntml'; /** This reads content from `index.mjs` */

CommonJS

const { html } = require('lit-ntml'); /** This reads content from `index.js` */

🎉 Voila! Happy templating!