[HELP] Bundling via esbuild
produces Runtime Error.
#99
-
I had this problem a few weeks ago and it seems that this one rather extends off of that one. This time, I am bundling multiple components via one file.
import "./Counter.tsx"
import "./HelloWorld.tsx"
import { Component, customElement, property, listen, h, Fragment } from "@chialab/dna"
@customElement("counter")
export class Counter extends Component {
@property() time = 0
render() {
return <>
<h1 id="counter">{this.time}</h1>
</>
}
@listen("click", "#counter")
function (event: Event, target: HTMLInputElement) {
this.time += 1
}
}
import { Component, customElement, property, listen, h, Fragment } from "@chialab/dna"
@customElement("hello-world")
export class HelloWorld extends Component {
@property() name = ""
render() {
return <>
<input name="firstName" value={this.name} />
<h1>Hello {this.name || "World"}!</h1>
</>
}
@listen("input", "input[name='firstName']")
function (event: Event, target: HTMLInputElement) {
this.name = target.value
}
} Buildscript: import { build, PluginBuild, BuildResult } from "esbuild"
import { httpImports } from "esbuild_plugin_http_imports"
import { load, plugin } from "esbuild_plugin_import_map"
load(JSON.parse(Deno.readTextFileSync("./import_map.json")))
const watcher = Deno.args.join(" ").match("--watch") ? true : false
const exitOnBuild = {
name: "close-on-complete",
setup(build: PluginBuild) {
build.onEnd((result: BuildResult) => {
console.log("Finished Complete Building!")
Deno.exit(result.errors.length >= 1 ? 1 : 0)
})
}
}
await build({
entryPoints: [
"platforms/material3/material3.ts"
],
outdir: "dist",
bundle: true,
platform: "browser",
format: "esm",
target: "esnext",
plugins: [
plugin()
],
tsconfig: "deno.json",
minify: true,
treeShaking: true,
watch: watcher
})
await build({
entryPoints: [
"dist/material3.js"
],
outdir: "build",
bundle: true,
platform: "browser",
format: "esm",
target: "esnext",
allowOverwrite: true,
plugins: [
exitOnBuild,
httpImports({
defaultToJavascriptIfNothingElseFound: true
})
],
tsconfig: "deno.json",
minify: true,
treeShaking: true,
watch: watcher
}) Deno configuration: {
"compilerOptions": {
"lib": [
"deno.window"
],
"jsxFactory": "h",
"jsxFragmentFactory": "Fragment",
"useDefineForClassFields": false
},
"tasks": {
"serve": "",
"build": "deno run --allow-write --allow-read --allow-net --allow-env --allow-run src/build.ts",
"dev": "",
"tailwind:build": "",
"tailwind:dev": ""
},
"importMap": "import_map.json"
} This all seems to bundle until I run it in a browser, and then, I am hit with this error: Now, if I take out |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hello @LePichu. Please note that DNA is built on Custom Elements standard. Custom Elements names must include an hyphen as described here. Try this instead: -@customElement("counter")
+@customElement("app-counter") |
Beta Was this translation helpful? Give feedback.
Hello @LePichu. Please note that DNA is built on Custom Elements standard. Custom Elements names must include an hyphen as described here.
Try this instead: