Skip to content

Commit

Permalink
Added an IIFE for the browser runtime and removed unnecessary depende…
Browse files Browse the repository at this point in the history
…ncies
  • Loading branch information
Zaydek Michels-Gualtieri committed Dec 20, 2020
1 parent 4c82934 commit 8acf222
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"build-css-prod": "sass --style=compressed scripts/prod.scss dist/prod.css",
"build-css-prod-full": "sass --style=compressed scripts/prod-full.scss dist/prod-full.css",
"build-js": "tsc",
"build-browser-js": "NODE_ENV=production node scripts/browser.js",
"build-browser-js": "node scripts/browser.js",
"build": "rm -rf dist && yarn concurrently --raw 'yarn build-css-dev' 'yarn build-css-dev-full' 'yarn build-css-prod' 'yarn build-css-prod-full' 'yarn build-js' 'yarn build-browser-js'",
"publish-dist-dry-run": "yarn build && npm publish --dry-run"
},
Expand Down
2 changes: 1 addition & 1 deletion scripts/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { build } = require("esbuild")
build({
bundle: true,
define: { "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || "development") },
entryPoints: ["src/runtime/index.ts"],
entryPoints: ["src/runtime/runtime.ts"],
minify: process.env.NODE_ENV === "production",
outfile: "dist/browser/index.js",
sourcemap: true,
Expand Down
14 changes: 13 additions & 1 deletion src/runtime/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function OSPrefersDarkMode() {
}

const Duomo: IRuntime = {
init(mode: DevMode) {
init(mode: DevMode = "production") {
const deferers: Array<() => void> = []

console.log("[Duomo] init=true")
Expand Down Expand Up @@ -103,4 +103,16 @@ const Duomo: IRuntime = {
},
}

declare global {
interface Window {
Duomo: IRuntime
}
}

;(() => {
if (typeof window !== "undefined") {
window.Duomo = Duomo
}
})()

export default Duomo

0 comments on commit 8acf222

Please sign in to comment.