Skip to content

Commit

Permalink
Merge pull request #122 from whereby/holvik/rollup-take-2
Browse files Browse the repository at this point in the history
Replace esbuild with Rollup
  • Loading branch information
thyal authored Nov 8, 2023
2 parents d53d4a9 + 183b8bf commit c9cda9e
Show file tree
Hide file tree
Showing 11 changed files with 351 additions and 560 deletions.
2 changes: 1 addition & 1 deletion .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runs:
steps:
- uses: actions/setup-node@v3
with:
node-version: "16"
node-version: "20"
cache: "yarn"

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v3
with:
node-version: "16.x"
node-version: "20.x"
registry-url: "https://registry.npmjs.org"

- name: Build
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
cache: "yarn"
cache-dependency-path: |
yarn.lock
test/sample-app/yarn.lock
yarn.lock
test/sample-app/yarn.lock
- name: Install dependencies
run: yarn
- name: Install sample-app dependencies
Expand Down
38 changes: 0 additions & 38 deletions build.js

This file was deleted.

34 changes: 22 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@whereby.com/browser-sdk",
"version": "2.0.0-beta2",
"version": "2.0.0-alpha27",
"description": "Modules for integration Whereby video in web apps",
"author": "Whereby AS",
"license": "MIT",
Expand All @@ -11,9 +11,18 @@
"browserslist": "> 0.5%, last 2 versions, not dead",
"source": "src/index.js",
"exports": {
"./react": "./dist/react/index.js",
"./embed": "./dist/embed/index.js",
"./utils": "./dist/utils/index.js"
"./react": {
"import": "./dist/react/index.esm.js",
"types": "./dist/react/index.d.ts"
},
"./embed": {
"import": "./dist/embed/index.esm.js",
"types": "./dist/embed/index.d.ts"
},
"./utils": {
"import": "./dist/utils/index.esm.js",
"types": "./dist/utils/index.d.ts"
}
},
"typesVersions": {
"*": {
Expand All @@ -34,8 +43,7 @@
],
"scripts": {
"prebuild": "rimraf dist",
"build": "node build.js",
"postbuild": "tsc --project tsconfig.build.json",
"build": "rollup -c rollup.config.js",
"build:storybook": "storybook build",
"dev": "storybook dev -p 6006",
"install:e2e-sample-app": "cd test/sample-app && yarn custom_install",
Expand All @@ -55,10 +63,10 @@
"@babel/preset-react": "^7.22.15",
"@babel/preset-typescript": "^7.23.2",
"@playwright/test": "^1.38.1",
"@rollup/plugin-commonjs": "^24.0.0",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"@rollup/plugin-replace": "^4.0.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.5",
"@storybook/addon-actions": "^7.5.2",
"@storybook/addon-essentials": "^7.5.2",
"@storybook/addon-links": "^7.5.2",
Expand All @@ -75,8 +83,6 @@
"babel-loader": "^8.2.5",
"dotenv": "^16.3.1",
"dotenv-run-script": "^0.4.1",
"esbuild": "^0.19.4",
"esbuild-plugin-replace": "^1.4.0",
"eslint": "^8.29.0",
"eslint-plugin-jest": "^26.5.3",
"jest": "29.4.3",
Expand All @@ -86,6 +92,10 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rimraf": "^3.0.2",
"rollup": "^4.3.0",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.36.0",
"storybook": "^7.5.2",
"ts-jest": "29.0.5",
"tslib": "^2.4.1",
Expand Down
117 changes: 117 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
const nodeResolve = require("@rollup/plugin-node-resolve");
const commonjs = require("@rollup/plugin-commonjs");
const json = require("@rollup/plugin-json");
const replace = require("@rollup/plugin-replace");
const { terser } = require("rollup-plugin-terser");
const pkg = require("./package.json");
const typescript = require("rollup-plugin-typescript2");
const { dts } = require("rollup-plugin-dts");

const peerDependencies = [...Object.keys(pkg.peerDependencies || {})];

function makeCdnFilename() {
const major = pkg.version.split(".")[0];
const preRelease = pkg.version.split("-")[1];
let tag = "";

if (preRelease) {
tag = `-${preRelease.split(".")[0]}`;
}

return `v${major}${tag}.js`;
}

const replaceValues = {
preventAssignment: true,
values: {
__SDK_VERSION__: pkg.version,
"process.env.NODE_DEBUG": JSON.stringify(process.env.NODE_DEBUG),
"process.env.AWF_BASE_URL": JSON.stringify(process.env.AWF_BASE_URL),
"process.env.AWF_API_BASE_URL": JSON.stringify(process.env.AWF_API_BASE_URL),
"process.env.AP_ROOM_BASE_URL": JSON.stringify(process.env.AP_ROOM_BASE_URL),
"process.env.RTCSTATS_URL": JSON.stringify(process.env.RTCSTATS_URL || "wss://rtcstats.srv.whereby.com"),
"process.env.REACT_APP_API_BASE_URL": JSON.stringify(
process.env.REACT_APP_API_BASE_URL || "https://api.whereby.dev"
),
"process.env.REACT_APP_SIGNAL_BASE_URL": JSON.stringify(
process.env.REACT_APP_SIGNAL_BASE_URL || "wss://signal.appearin.net"
),
},
};

const plugins = [
replace(replaceValues),
replace({
preventAssignment: true,
// jslib-media uses global.navigator for some gUM calls, replace these
delimiters: [" ", "."],
values: { "global.navigator.mediaDevices": " navigator.mediaDevices." },
}),
nodeResolve({
// only include @whereby/jslib-media in our bundle
preferBuiltins: true,
resolveOnly: [/@whereby\/jslib-media/],
}),
commonjs(),
typescript(),
];

module.exports = [
// Esm build of lib, to be used with bundlers
{
input: "src/lib/react/index.ts",
output: {
exports: "named",
file: "dist/react/index.esm.js",
format: "esm",
},
external: ["heresy", ...peerDependencies],
plugins,
},
{
input: "src/lib/embed/index.ts",
output: {
exports: "named",
file: "dist/embed/index.esm.js",
format: "esm",
},
external: ["heresy", ...peerDependencies],
plugins,
},
{
input: "src/lib/utils/index.ts",
output: {
exports: "named",
file: "dist/utils/index.esm.js",
format: "esm",
},
external: ["heresy", ...peerDependencies],
plugins,
},
// Legacy build of embedded lib in ESM format, bundling the dependencies
{
input: "src/lib/embed/index.ts",
output: {
exports: "named",
file: `dist/${makeCdnFilename()}`,
format: "esm",
},
plugins: [nodeResolve(), commonjs(), json(), terser(), replace(replaceValues), typescript()],
},
// Roll-up .d.ts definition files
{
input: "src/lib/react/index.ts",
output: [{ file: "dist/react/index.d.ts", format: "es" }],
plugins: [dts()],
},
{
input: "src/lib/embed/index.ts",
output: [{ file: "dist/embed/index.d.ts", format: "es" }],
plugins: [dts()],
},
{
input: "src/lib/utils/index.ts",
output: [{ file: "dist/utils/index.d.ts", format: "es" }],
plugins: [dts()],
},
];
4 changes: 2 additions & 2 deletions src/lib/RoomConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ class RoomConnectionEvent<T extends RoomEventKey> extends CustomEvent<RoomEventP
}
}

const API_BASE_URL = process.env["REACT_APP_API_BASE_URL"] || "https://api.whereby.dev";
const SIGNAL_BASE_URL = process.env["REACT_APP_SIGNAL_BASE_URL"] || "wss://signal.appearin.net";
const API_BASE_URL = process.env.REACT_APP_API_BASE_URL || "https://api.whereby.dev";
const SIGNAL_BASE_URL = process.env.REACT_APP_SIGNAL_BASE_URL || "wss://signal.appearin.net";

const NON_PERSON_ROLES = ["recorder", "streamer"];

Expand Down
2 changes: 1 addition & 1 deletion src/stories/prebuilt-ui.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ WherebyEmbedElement.args = {
chat: true,
displayName: "Your name",
emptyRoomInvitation: "true",
externalId: null,
externalId: undefined,
floatSelf: false,
help: true,
leaveButton: true,
Expand Down
Loading

0 comments on commit c9cda9e

Please sign in to comment.