From 5cf5392222681eed921a049a46fcf1a277347975 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Thu, 7 Jan 2021 13:57:32 -0600 Subject: [PATCH] maint/build ~ add `rollup` for ESM generation - TypeScript fails to correctly generate an ESM module with correct line endings - ref: - ref: - ref: - ref: --- .rollup.config.js | 19 +++++++++++++++++++ package.json | 3 +++ 2 files changed, 22 insertions(+) create mode 100644 .rollup.config.js diff --git a/.rollup.config.js b/.rollup.config.js new file mode 100644 index 0000000..9f28d17 --- /dev/null +++ b/.rollup.config.js @@ -0,0 +1,19 @@ +// ref: +// setup: `npm i rollup @rollup/plugin-typescript` or `npm i rollup rollup-plugin-typescript2` (for visible TS error output) + +// import typescript from '@rollup/plugin-typescript'; +import typescript from 'rollup-plugin-typescript2'; + +export default [ + // ES module build (replaces broken basic TypeScript compilation) + // * ref: , + // * ref: + // * ref: + { + preserveModules: true, + input: ['src/index.ts'], + external: ['path', 'os'], + output: [{ exports: 'auto', dir: 'build/esm', format: 'esm', entryFileNames: '[name].mjs' }], + plugins: [typescript({ tsconfig: './tsconfig/tsconfig.esm.json' })], + }, +]; diff --git a/package.json b/package.json index ee53a05..05b3c76 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "build:cjs": "tsc -p tsconfig/tsconfig.cjs.json", "build:cjs/esm": "shx mkdir -p build/cjs && shx cp -r src/esm-wrapper build/cjs", "## build:esm * [2020-12-22; rivy] TS compiles to ESMs are broken due to extension mishandling (use `rollup`)": "tsc -p tsconfig/tsconfig.esm.json", + "build:esm": "rollup -c .rollup.config.js", "build:umd": "tsc -p tsconfig/tsconfig.umd.json", "build:tests": "tsc -p tsconfig/tsconfig.tests.json", "build:types": "tsc -p tsconfig/tsconfig.types.json && run-s --silent _:update:dist.types", @@ -177,6 +178,8 @@ "remark-footnotes": "^3.0.0", "remark-preset-lint-recommended": "^5.0.0", "rimraf": "^3.0.2", + "rollup": "^2.36.1", + "rollup-plugin-typescript2": "^0.29.0", "shx": "^0.3.3", "ts-node": "^9.0.0", "tsd": "^0.13.1",