From 097ff51a7a6d7e2380f0f539cd56c880b129ff7d Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Thu, 30 Sep 2021 21:58:22 +0200 Subject: [PATCH] Implemented @theatre/browser-bundles --- packages/browser-bundles/.gitignore | 1 + packages/browser-bundles/LICENSE | 3 + packages/browser-bundles/README.md | 32 ++++++++++ packages/browser-bundles/devEnv/build.ts | 61 +++++++++++++++++++ packages/browser-bundles/devEnv/tsconfig.json | 3 + packages/browser-bundles/package.json | 32 ++++++++++ .../browser-bundles/src/core-and-studio.ts | 8 +++ packages/browser-bundles/src/core-only.ts | 12 ++++ packages/browser-bundles/test.html | 11 ++++ packages/browser-bundles/tsconfig.json | 14 +++++ yarn.lock | 18 ++++++ 11 files changed, 195 insertions(+) create mode 100644 packages/browser-bundles/.gitignore create mode 100644 packages/browser-bundles/LICENSE create mode 100644 packages/browser-bundles/README.md create mode 100644 packages/browser-bundles/devEnv/build.ts create mode 100644 packages/browser-bundles/devEnv/tsconfig.json create mode 100644 packages/browser-bundles/package.json create mode 100644 packages/browser-bundles/src/core-and-studio.ts create mode 100644 packages/browser-bundles/src/core-only.ts create mode 100644 packages/browser-bundles/test.html create mode 100644 packages/browser-bundles/tsconfig.json diff --git a/packages/browser-bundles/.gitignore b/packages/browser-bundles/.gitignore new file mode 100644 index 0000000..3e22129 --- /dev/null +++ b/packages/browser-bundles/.gitignore @@ -0,0 +1 @@ +/dist \ No newline at end of file diff --git a/packages/browser-bundles/LICENSE b/packages/browser-bundles/LICENSE new file mode 100644 index 0000000..52aae9a --- /dev/null +++ b/packages/browser-bundles/LICENSE @@ -0,0 +1,3 @@ +This is a bundle of @theatre/core and @theatre/studio packages. + +See their licenses in their repo: https://github.com/ariaminaei/theatre \ No newline at end of file diff --git a/packages/browser-bundles/README.md b/packages/browser-bundles/README.md new file mode 100644 index 0000000..1e8b193 --- /dev/null +++ b/packages/browser-bundles/README.md @@ -0,0 +1,32 @@ +# Theatre.js browser bundles + +A custom build of Theatre.js that you can use via a ` + +``` \ No newline at end of file diff --git a/packages/browser-bundles/devEnv/build.ts b/packages/browser-bundles/devEnv/build.ts new file mode 100644 index 0000000..e64126b --- /dev/null +++ b/packages/browser-bundles/devEnv/build.ts @@ -0,0 +1,61 @@ +import * as path from 'path' +import {build} from 'esbuild' +import type {Plugin} from 'esbuild' + +const definedGlobals = { + global: 'window', +} + +function createBundles(watch: boolean) { + const pathToPackage = path.join(__dirname, '../') + const esbuildConfig: Parameters[0] = { + bundle: true, + sourcemap: true, + define: definedGlobals, + watch, + platform: 'browser', + loader: { + '.png': 'dataurl', + '.glb': 'dataurl', + '.gltf': 'dataurl', + '.svg': 'dataurl', + }, + mainFields: ['browser', 'module', 'main'], + target: ['firefox57', 'chrome58'], + conditions: ['browser', 'node'], + } + + // build({ + // ...esbuildConfig, + // entryPoints: [path.join(pathToPackage, 'src/core-only.ts')], + // outfile: path.join(pathToPackage, 'dist/core-only.js'), + // format: 'iife', + // }) + + build({ + ...esbuildConfig, + entryPoints: [path.join(pathToPackage, 'src/core-and-studio.ts')], + outfile: path.join(pathToPackage, 'dist/core-and-studio.js'), + format: 'iife', + }) + + build({ + ...esbuildConfig, + entryPoints: [path.join(pathToPackage, 'src/core-only.ts')], + outfile: path.join(pathToPackage, 'dist/core-only.min.js'), + minify: true, + format: 'iife', + define: { + ...definedGlobals, + 'process.env.NODE_ENV': JSON.stringify('production'), + }, + }) + + // build({ + // ...esbuildConfig, + // outfile: path.join(pathToPackage, 'dist/index.mjs'), + // format: 'esm', + // }) +} + +createBundles(false) diff --git a/packages/browser-bundles/devEnv/tsconfig.json b/packages/browser-bundles/devEnv/tsconfig.json new file mode 100644 index 0000000..077404a --- /dev/null +++ b/packages/browser-bundles/devEnv/tsconfig.json @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/packages/browser-bundles/package.json b/packages/browser-bundles/package.json new file mode 100644 index 0000000..7801207 --- /dev/null +++ b/packages/browser-bundles/package.json @@ -0,0 +1,32 @@ +{ + "name": "@theatre/browser-bundles", + "version": "0.4.3", + "license": "SEE LICENSE IN LICENSE", + "author": { + "name": "Aria Minaei", + "email": "aria@theatrejs.com", + "url": "https://github.com/AriaMinaei" + }, + "repository": { + "type": "git", + "url": "https://github.com/AriaMinaei/theatre", + "directory": "packages/browser-bundles" + }, + "files": [ + "dist/**/*" + ], + "scripts": { + "build": "node -r esbuild-register ./devEnv/build.ts", + "prepublish": "node ../../devEnv/ensurePublishing.js" + }, + "devDependencies": { + "esbuild": "^0.12.15", + "esbuild-register": "^2.5.0", + "npm-run-all": "^4.1.5", + "typescript": "^4.4.2" + }, + "peerDependencies": { + "@theatre/core": "*", + "@theatre/studio": "*" + } +} diff --git a/packages/browser-bundles/src/core-and-studio.ts b/packages/browser-bundles/src/core-and-studio.ts new file mode 100644 index 0000000..8769291 --- /dev/null +++ b/packages/browser-bundles/src/core-and-studio.ts @@ -0,0 +1,8 @@ +import * as core from '@theatre/core' +import studio from '@theatre/studio' + +// @ts-ignore +window.Theatre = { + core, + studio, +} diff --git a/packages/browser-bundles/src/core-only.ts b/packages/browser-bundles/src/core-only.ts new file mode 100644 index 0000000..e02cd42 --- /dev/null +++ b/packages/browser-bundles/src/core-only.ts @@ -0,0 +1,12 @@ +import * as core from '@theatre/core' + +// @ts-ignore +window.Theatre = { + core, + get studio() { + alert( + "Theatre.studio is only available in the core-and-studio.js bundle. You're using the core-only.min.js bundle.", + ) + return undefined + }, +} diff --git a/packages/browser-bundles/test.html b/packages/browser-bundles/test.html new file mode 100644 index 0000000..2b1c427 --- /dev/null +++ b/packages/browser-bundles/test.html @@ -0,0 +1,11 @@ + + diff --git a/packages/browser-bundles/tsconfig.json b/packages/browser-bundles/tsconfig.json new file mode 100644 index 0000000..82235b4 --- /dev/null +++ b/packages/browser-bundles/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "dist", + "lib": ["ESNext", "DOM"], + "rootDir": "src", + "types": ["jest", "node"], + "emitDeclarationOnly": true, + "target": "es6", + "composite": true + }, + "include": ["./src/**/*"], + "references": [{"path": "../dataverse"}, {"path": "../../theatre"}] +} diff --git a/yarn.lock b/yarn.lock index 74ff78b..2da1638 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5207,6 +5207,24 @@ __metadata: languageName: node linkType: hard +"@theatre/browser-bundles@workspace:packages/browser-bundles": + version: 0.0.0-use.local + resolution: "@theatre/browser-bundles@workspace:packages/browser-bundles" + dependencies: + "@types/jest": ^26.0.23 + "@types/node": ^15.6.2 + "@types/react": ^17.0.9 + "@types/react-dom": ^17.0.6 + esbuild: ^0.12.15 + esbuild-register: ^2.5.0 + npm-run-all: ^4.1.5 + typescript: ^4.4.2 + peerDependencies: + "@theatre/core": "*" + "@theatre/studio": "*" + languageName: unknown + linkType: soft + "@theatre/core@workspace:*, @theatre/core@workspace:theatre/core": version: 0.0.0-use.local resolution: "@theatre/core@workspace:theatre/core"