diff --git a/package.json b/package.json index 999753c..b4232c9 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,21 @@ "version": "3.0.2", "description": "Highly customizable notification snackbars (toasts) that can be stacked on top of each other", "main": "./index.js", - "module": "./notistack.esm.js", + "module": "./notistack.esm.mjs", "types": "./index.d.ts", + "exports": { + ".": { + "import": { + "types": "./notistack.esm.d.mts", + "default": "./notistack.esm.mjs" + }, + "require": { + "types": "./index.d.ts", + "default": "./index.js" + } + }, + "./package.json": "./package.json" + }, "license": "MIT", "author": { "name": "Hossein Dehnokhalaji", diff --git a/tsdx.config.js b/tsdx.config.js index b9b8722..8ba68cf 100644 --- a/tsdx.config.js +++ b/tsdx.config.js @@ -1,3 +1,4 @@ +const path = require('node:path'); const copy = require('rollup-plugin-copy'); const bundleSize = require('rollup-plugin-bundle-size'); @@ -6,11 +7,18 @@ const DIST_FOLDER = 'dist'; module.exports = { rollup(config) { config.plugins.push(bundleSize()); + + let dts = 'index.d.ts'; + // Write ESM as .mjs to match Node.js expectations. + if (config.output && config.output.format === 'esm') { + config.output.file = config.output.file.replace(/\.js$/, '.mjs'); + dts = path.basename(config.output.file, '.mjs') + '.d.mts'; + } config.plugins.push( copy({ targets: [ - // copy decleration file over - { src: 'src/types.ts', dest: DIST_FOLDER, rename: 'index.d.ts' }, + // copy declaration file over + { src: 'src/types.ts', dest: DIST_FOLDER, rename: dts }, ], }) );