From 420c24e118827979cadaec2b965fd5cdc5607f63 Mon Sep 17 00:00:00 2001 From: Dan Fabulich Date: Fri, 1 May 2020 23:16:03 -0700 Subject: [PATCH] Export mjs files so Node can natively import them. Fixes #87. --- package.json | 16 +++++++++++++++- rollup.config.js | 11 ++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 727ce8922..a0934726b 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,20 @@ "version": "0.1.2", "license": "MIT", "description": "JSX-based components with functions, promises and generators.", + "exports": { + ".": { + "import": "./esm/index.mjs", + "require": "./cjs/index.js" + }, + "./html": { + "import": "./esm/html.mjs", + "require": "./cjs/html.js" + }, + "./dom": { + "import": "./esm/dom.mjs", + "require": "./cjs/dom.js" + } + }, "files": [ "cjs", "esm", @@ -12,7 +26,7 @@ "html.js" ], "main": "cjs/index.js", - "module": "esm/index.js", + "module": "esm/index.mjs", "types": "esm/index.d.ts", "scripts": { "prebuild": "yarn run clean", diff --git a/rollup.config.js b/rollup.config.js index 9a26beba1..f76e4fbf0 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,19 +1,20 @@ import resolve from "@rollup/plugin-node-resolve"; import typescript from "rollup-plugin-typescript2"; -export default { - input: ["src/index.ts", "src/dom.ts", "src/html.ts"], +import {basename} from "path"; +export default ["src/index.ts", "src/dom.ts", "src/html.ts"].map((input) => ({ + input, output: [ { format: "cjs", - dir: "cjs", + file: `cjs/${basename(input).replace(/\.ts$/, ".js")}`, sourcemap: true, }, { format: "esm", - dir: "esm", + file: `esm/${basename(input).replace(/\.ts$/, ".mjs")}`, sourcemap: true, }, ], external: ["@repeaterjs/repeater"], plugins: [typescript(), resolve()], -}; +}));