Closed cpontvieux-systra closed 3 months ago
Based on a blog post of Charles Loder: https://dev.to/charlesloder/publishing-esm-and-commonjs-packages-with-typescript-4e20
This will offer two different folders for a ESM project (type: module) or a legacy CommonJs project..
type: module
Tested with the following CommonJS package.json:
package.json
{ "name": "test-cjs", "version": "1.0.0", "main": "index.js", "dependencies": { "django-vite-plugin": "./django-vite-plugin-v4.0.1.tgz" } }
and index.js:
index.js
const django_vite_plugin = require('django-vite-plugin'); const djangoVitePlugin = django_vite_plugin.djangoVitePlugin; console.log(djangoVitePlugin)
This produces the correct output with node:
$ node index.js The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details. [AsyncFunction: djangoVitePlugin]
And here with the following ESM package.json:
{ "name": "test-esm", "version": "1.0.0", "main": "index.js", "type": "module", "dependencies": { "django-vite-plugin": "./django-vite-plugin-v4.0.1.tgz" } }
import { djangoVitePlugin } from 'django-vite-plugin'; console.log(djangoVitePlugin)
$ node index.js [AsyncFunction: djangoVitePlugin]
Based on a blog post of Charles Loder: https://dev.to/charlesloder/publishing-esm-and-commonjs-packages-with-typescript-4e20
This will offer two different folders for a ESM project (
type: module
) or a legacy CommonJs project..Tested with the following CommonJS
package.json
:and
index.js
:This produces the correct output with node:
And here with the following ESM
package.json
:and
index.js
:This produces the correct output with node: