Skip to content

Commit cda2874

Browse files
committed
maint/build ~ add rollup for ESM generation
- TypeScript fails to correctly generate an ESM module with correct line endings - ref: <microsoft/TypeScript#18442 (comment)> - ref: <microsoft/TypeScript#18442> - ref: <microsoft/TypeScript#37582> - ref: <microsoft/TypeScript#35148>
1 parent 1cea465 commit cda2874

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

.rollup.config.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// ref: <https://devhints.io/rollup>
2+
// setup: `npm i rollup @rollup/plugin-typescript` or `npm i rollup rollup-plugin-typescript2` (for visible TS error output)
3+
4+
// import typescript from '@rollup/plugin-typescript';
5+
import typescript from 'rollup-plugin-typescript2';
6+
7+
export default [
8+
// ES module build (replaces broken basic TypeScript compilation)
9+
// * ref: <https://github.com/microsoft/TypeScript/issues/18442> , <https://github.com/alshdavid/rxjs/blob/main/rollup.config.js#L10>
10+
// * ref: <https://github.com/microsoft/TypeScript/pull/35148>
11+
// * ref: <https://github.com/microsoft/TypeScript/issues/37582>
12+
{
13+
preserveModules: true,
14+
input: ['src/index.ts'],
15+
external: ['path', 'os'],
16+
output: [{ exports: 'auto', dir: 'build/esm', format: 'esm', entryFileNames: '[name].mjs' }],
17+
plugins: [typescript({ tsconfig: './tsconfig/tsconfig.esm.json' })],
18+
},
19+
];

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"build:cjs": "shx rm -fr build/cjs && tsc -p tsconfig/tsconfig.cjs.json",
5858
"build:cjs/esm": "shx rm -fr build/cjs/esm-wrapper && shx mkdir -p build/cjs && shx cp -r src/esm-wrapper build/cjs",
5959
"## build:esm * [2020-12-22; rivy] TS compiles to ESMs are broken due to extension mishandling (use `rollup`)": "tsc -p tsconfig/tsconfig.esm.json",
60+
"build:esm": "shx rm -fr build/esm && rollup -c .rollup.config.js",
6061
"build:umd": "shx rm -fr build/umd && tsc -p tsconfig/tsconfig.umd.json",
6162
"build:tests": "shx rm -fr build/cjs+tests && tsc -p tsconfig/tsconfig.tests.json",
6263
"build:types": "shx rm -fr build/types && tsc -p tsconfig/tsconfig.types.json && run-s --silent _:update:dist.types",
@@ -177,6 +178,8 @@
177178
"remark-footnotes": "^3.0.0",
178179
"remark-preset-lint-recommended": "^5.0.0",
179180
"rimraf": "^3.0.2",
181+
"rollup": "^2.36.1",
182+
"rollup-plugin-typescript2": "^0.29.0",
180183
"shx": "^0.3.3",
181184
"ts-node": "^9.0.0",
182185
"tsd": "^0.13.1",

0 commit comments

Comments
 (0)