Skip to content

Commit

Permalink
feat: cjs, esm and umd builds with minification and compression…
Browse files Browse the repository at this point in the history
… for the browser (enisdenjo#58)

* chore: cjs, esm and umd with minification and compression

* fix: node module resolution

* refactor: drop unnecessary comments

* chore: flatten build structure for unpkg support

* docs(recipe): client usage in browser
  • Loading branch information
enisdenjo committed Nov 4, 2020
1 parent 351963b commit ebb8dfe
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 26 deletions.
4 changes: 3 additions & 1 deletion .gitignore
@@ -1,6 +1,8 @@
**/.DS_Store
node_modules
lib
cjs
esm
umd
dist
.vscode
.yarn/*
Expand Down
30 changes: 30 additions & 0 deletions README.md
Expand Up @@ -330,6 +330,36 @@ const link = new WebSocketLink({

</details>

<details>
<summary>Client usage in browser</summary>

```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>GraphQL over WebSocket</title>
<script
type="text/javascript"
src="https://unpkg.com/graphql-ws/umd/graphql-ws.min.js"
></script>
</head>
<body>
<script type="text/javascript">
(function () {
const client = graphqlWs.createClient({
url: 'wss://umdfor.the/win/graphql',
});
// consider other recipes for usage inspiration
})();
</script>
</body>
</html>
```

</details>

<details>
<summary>Client usage in Node</summary>

Expand Down
18 changes: 13 additions & 5 deletions package.json
Expand Up @@ -24,11 +24,14 @@
"engines": {
"node": ">=10"
},
"main": "lib/index.js",
"browser": "lib/client.js",
"types": "lib/index.d.ts",
"main": "cjs/index.js",
"module": "esm/index.js",
"browser": "umd/graphql-ws.js",
"types": "esm/index.d.ts",
"files": [
"lib",
"cjs",
"esm",
"umd",
"README.md",
"LICENSE.md",
"PROTOCOL.md"
Expand All @@ -41,7 +44,10 @@
"lint": "eslint 'src'",
"type-check": "tsc --noEmit",
"test": "jest",
"build": "tsc -b tsconfig.build.json",
"build:cjs": "tsc -b tsconfig.cjs.json",
"build:esm": "tsc -b tsconfig.esm.json",
"build:umd": "rollup -c && gzip umd/graphql-ws.min.js -c > umd/graphql-ws.min.js.gz",
"build": "yarn build:cjs && yarn build:esm && yarn build:umd",
"release": "semantic-release"
},
"peerDependencies": {
Expand Down Expand Up @@ -71,6 +77,8 @@
"graphql": "^15.4.0",
"jest": "^26.6.1",
"prettier": "^2.1.2",
"rollup": "^2.33.1",
"rollup-plugin-terser": "^7.0.2",
"semantic-release": "^17.2.2",
"typedoc": "^0.19.2",
"typedoc-plugin-markdown": "^3.0.11",
Expand Down
18 changes: 18 additions & 0 deletions rollup.config.js
@@ -0,0 +1,18 @@
import { terser } from 'rollup-plugin-terser';

export default {
input: './esm/client.js',
output: [
{
file: './umd/graphql-ws.js',
format: 'umd',
name: 'graphqlWs',
},
{
file: './umd/graphql-ws.min.js',
format: 'umd',
name: 'graphqlWs',
plugins: [terser()],
},
],
};
4 changes: 0 additions & 4 deletions tsconfig.build.json

This file was deleted.

8 changes: 8 additions & 0 deletions tsconfig.cjs.json
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "./cjs"
},
"exclude": ["src/tests", "cjs", "esm"]
}
8 changes: 8 additions & 0 deletions tsconfig.esm.json
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "es2015",
"outDir": "./esm"
},
"exclude": ["src/tests", "cjs", "esm"]
}
23 changes: 11 additions & 12 deletions tsconfig.json
@@ -1,18 +1,17 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
"target": "es2017" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"declaration": true /* Generates corresponding '.d.ts' file. */,
"outDir": "./lib" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
"strict": true /* Enable all strict type-checking options. */,
"noUnusedLocals": true /* Report errors on unused locals. */,
"noUnusedParameters": true /* Report errors on unused parameters. */,
"baseUrl": "./src" /* Base directory to resolve non-absolute module names. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
"skipLibCheck": true /* Skip type checking of declaration files. */,
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
"moduleResolution": "node",
"target": "es2017",
"declaration": true,
"rootDir": "./src",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"baseUrl": "./src",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"exclude": ["lib"]
}
87 changes: 83 additions & 4 deletions yarn.lock
Expand Up @@ -3129,6 +3129,13 @@ __metadata:
languageName: node
linkType: hard

"commander@npm:^2.20.0":
version: 2.20.3
resolution: "commander@npm:2.20.3"
checksum: b73428e97de7624323f81ba13f8ed9271de487017432d18b4da3f07cfc528ad754bbd199004bd5d14e0ccd67d1fdfe0ec8dbbd4c438b401df3c4cc387bfd1daa
languageName: node
linkType: hard

"compare-func@npm:^2.0.0":
version: 2.0.0
resolution: "compare-func@npm:2.0.0"
Expand Down Expand Up @@ -4540,7 +4547,7 @@ __metadata:
languageName: node
linkType: hard

fsevents@^2.1.2:
"fsevents@^2.1.2, fsevents@~2.1.2":
version: 2.1.3
resolution: "fsevents@npm:2.1.3"
dependencies:
Expand All @@ -4549,7 +4556,7 @@ fsevents@^2.1.2:
languageName: node
linkType: hard

"fsevents@patch:fsevents@^2.1.2#builtin<compat/fsevents>":
"fsevents@patch:fsevents@^2.1.2#builtin<compat/fsevents>, fsevents@patch:fsevents@~2.1.2#builtin<compat/fsevents>":
version: 2.1.3
resolution: "fsevents@patch:fsevents@npm%3A2.1.3#builtin<compat/fsevents>::version=2.1.3&hash=127e8e"
dependencies:
Expand Down Expand Up @@ -4827,6 +4834,8 @@ fsevents@^2.1.2:
graphql: ^15.4.0
jest: ^26.6.1
prettier: ^2.1.2
rollup: ^2.33.1
rollup-plugin-terser: ^7.0.2
semantic-release: ^17.2.2
typedoc: ^0.19.2
typedoc-plugin-markdown: ^3.0.11
Expand Down Expand Up @@ -6187,6 +6196,17 @@ fsevents@^2.1.2:
languageName: node
linkType: hard

"jest-worker@npm:^26.2.1":
version: 26.6.2
resolution: "jest-worker@npm:26.6.2"
dependencies:
"@types/node": "*"
merge-stream: ^2.0.0
supports-color: ^7.0.0
checksum: 5eb349833b5e9750ce8700388961dfd5d5e207c913122221e418e48b9cda3c17b0fb418f6a90f1614cfdc3ca836158b720c5dc1de82cb1e708266b4d76e31a38
languageName: node
linkType: hard

"jest-worker@npm:^26.6.1":
version: 26.6.1
resolution: "jest-worker@npm:26.6.1"
Expand Down Expand Up @@ -8573,6 +8593,15 @@ fsevents@^2.1.2:
languageName: node
linkType: hard

"randombytes@npm:^2.1.0":
version: 2.1.0
resolution: "randombytes@npm:2.1.0"
dependencies:
safe-buffer: ^5.1.0
checksum: ede2693af09732ceab1c273dd70db787f34a7b8d95bab13f1aca763483c0113452a78e53d61ff18d393dcea586d388e01f198a5132a4a85cebba31ec54164b75
languageName: node
linkType: hard

"rc@npm:^1.0.1, rc@npm:^1.1.6, rc@npm:^1.2.8":
version: 1.2.8
resolution: "rc@npm:1.2.8"
Expand Down Expand Up @@ -9089,6 +9118,34 @@ fsevents@^2.1.2:
languageName: node
linkType: hard

"rollup-plugin-terser@npm:^7.0.2":
version: 7.0.2
resolution: "rollup-plugin-terser@npm:7.0.2"
dependencies:
"@babel/code-frame": ^7.10.4
jest-worker: ^26.2.1
serialize-javascript: ^4.0.0
terser: ^5.0.0
peerDependencies:
rollup: ^2.0.0
checksum: 553cc21efcea3e4d46c61fbd41cb4a82a3ab8e02ae4ce7c03f9248dea93e5a91c3624e2271490ee05b2bb481568305733b496d968d3ac9c99b777a588a336f01
languageName: node
linkType: hard

"rollup@npm:^2.33.1":
version: 2.33.1
resolution: "rollup@npm:2.33.1"
dependencies:
fsevents: ~2.1.2
dependenciesMeta:
fsevents:
optional: true
bin:
rollup: dist/bin/rollup
checksum: cf727ca4d1c6d6ad7679c8cf0a8258e41339d7d3eef5a7671cd54f4506c23f5492f6331c05d76697fa608d870407a5d2eb796647ce6add68101ca3bbb77c7d66
languageName: node
linkType: hard

"rsvp@npm:^4.8.4":
version: 4.8.5
resolution: "rsvp@npm:4.8.5"
Expand Down Expand Up @@ -9269,6 +9326,15 @@ fsevents@^2.1.2:
languageName: node
linkType: hard

"serialize-javascript@npm:^4.0.0":
version: 4.0.0
resolution: "serialize-javascript@npm:4.0.0"
dependencies:
randombytes: ^2.1.0
checksum: f17305aaabab9ae443505d1bf477c13b09adb7031c397d18400bec16f43f788febdd3311ca6043fdebd1d446cfa70a5804ef7268da54351dec51080f56d52fa9
languageName: node
linkType: hard

"set-blocking@npm:^2.0.0, set-blocking@npm:~2.0.0":
version: 2.0.0
resolution: "set-blocking@npm:2.0.0"
Expand Down Expand Up @@ -9492,7 +9558,7 @@ fsevents@^2.1.2:
languageName: node
linkType: hard

"source-map-support@npm:^0.5.6":
"source-map-support@npm:^0.5.6, source-map-support@npm:~0.5.19":
version: 0.5.19
resolution: "source-map-support@npm:0.5.19"
dependencies:
Expand Down Expand Up @@ -9523,7 +9589,7 @@ fsevents@^2.1.2:
languageName: node
linkType: hard

"source-map@npm:^0.7.3":
"source-map@npm:^0.7.3, source-map@npm:~0.7.2":
version: 0.7.3
resolution: "source-map@npm:0.7.3"
checksum: 351ce26ffa1ebf203660c0d70d7566c81e65d2d994d1c2d94da140808e02da34961673ce12ecea9b40797b96fbeb8c70bf71a4ad9f779f1a4fdbba75530bb386
Expand Down Expand Up @@ -10027,6 +10093,19 @@ fsevents@^2.1.2:
languageName: node
linkType: hard

"terser@npm:^5.0.0":
version: 5.3.8
resolution: "terser@npm:5.3.8"
dependencies:
commander: ^2.20.0
source-map: ~0.7.2
source-map-support: ~0.5.19
bin:
terser: bin/terser
checksum: 3fc070378ba9981d8088a4012060f16428a97dc8f98d5a731b2ab51b8c9bc8cb651ca068aef499faad863584ae4d4883872c4f51db053bc2575c2e0bc11ab411
languageName: node
linkType: hard

"test-exclude@npm:^6.0.0":
version: 6.0.0
resolution: "test-exclude@npm:6.0.0"
Expand Down

0 comments on commit ebb8dfe

Please sign in to comment.