feat: introduce browser support (#201)

This commit introduces a second `tsc` execution which generates JS in ES5 form.
Then, webpack is used to generate a browser bundle.

Fixes: https://github.com/cloudevents/sdk-javascript/issues/94

Signed-off-by: Lance Ball <lball@redhat.com>
This commit is contained in:
Lance Ball 2020-06-10 17:49:01 -04:00 committed by GitHub
parent 0378f4cdf9
commit 8b2725b10a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 3715 additions and 4 deletions

2
.gitignore vendored
View File

@ -9,6 +9,8 @@ yarn-error.log*
*.d.ts
index.js
/lib
/browser
/bundles
# Runtime data
pids

3678
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"watch": "tsc --project tsconfig.json --watch",
"build": "tsc --project tsconfig.json",
"build": "tsc --project tsconfig.json && tsc --project tsconfig.browser.json && webpack",
"prelint": "npm run build",
"lint": "standardx src examples",
"fix": "standardx --fix",
@ -119,7 +119,9 @@
"standardx": "^5.0.0",
"ts-node": "^8.10.2",
"typedoc": "^0.17.7",
"typescript": "^3.8.3"
"typescript": "^3.8.3",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11"
},
"publishConfig": {
"access": "public"

17
tsconfig.browser.json Normal file
View File

@ -0,0 +1,17 @@
{
"compilerOptions": {
"allowJs": true, /* Allow javascript files to be compiled. */
"checkJs": false, /* Report errors in .js files. */
"strict": true, /* Enable all strict type-checking options. */
"baseUrl": ".",
"outDir": "./browser",
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"esModuleInterop": true,
"lib": ["es2016", "dom", "es5"]
},
"include": [
"src/**/*.ts"
]
}

16
webpack.config.js Normal file
View File

@ -0,0 +1,16 @@
const path = require("path");
module.exports = {
entry: {
"cloudevents-sdk": "./browser/index.js"
},
output: {
path: path.resolve(__dirname, "_bundles"),
filename: "[name].js",
libraryTarget: "umd",
library: "cloudevents-sdk",
umdNamedDefine: true
},
devtool: "source-map",
mode: "production"
};