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 },