From 2108174eb5e1f48656287a2e55adc67112a05314 Mon Sep 17 00:00:00 2001 From: Denis Badurina Date: Thu, 17 Dec 2020 12:29:48 +0100 Subject: [PATCH] feat: Package ECMAScript Modules too (#87) * chore: provide esm mjs files * refactor: simplify by building esm first --- package.json | 6 ++++-- tsconfig.cjs.json | 9 +++++++++ tsconfig.build.json => tsconfig.esm.json | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 tsconfig.cjs.json rename tsconfig.build.json => tsconfig.esm.json (84%) diff --git a/package.json b/package.json index ff75bd6c..8c105f54 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "node": ">=10" }, "main": "lib/index.js", + "module": "lib/index.mjs", "types": "lib/index.d.ts", "browser": "umd/graphql-ws.js", "files": [ @@ -42,9 +43,10 @@ "lint": "eslint 'src'", "type-check": "tsc --noEmit", "test": "jest", - "build:lib": "tsc -b tsconfig.build.json", + "build:esm": "tsc -b tsconfig.esm.json && find ./lib -name \"*.js\" -exec sh -c 'mv \"$0\" \"${0%.js}.mjs\"' \"{}\" \\;", + "build:cjs": "tsc -b tsconfig.cjs.json", "build:umd": "rollup -c && gzip umd/graphql-ws.min.js -c > umd/graphql-ws.min.js.gz", - "build": "yarn build:lib && yarn build:umd", + "build": "yarn build:esm && yarn build:cjs && yarn build:umd", "release": "semantic-release" }, "peerDependencies": { diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 00000000..12694c27 --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "./lib", + "declaration": false // already built by `tsconfig.esm.json` + }, + "exclude": ["src/tests", "lib"] +} diff --git a/tsconfig.build.json b/tsconfig.esm.json similarity index 84% rename from tsconfig.build.json rename to tsconfig.esm.json index bf13fd3d..6c152431 100644 --- a/tsconfig.build.json +++ b/tsconfig.esm.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "module": "commonjs", + "module": "es2015", "outDir": "./lib", "declaration": true },