创建了一个新的苗条应用程序:
npx degit sveltejs/template svelte-typescript-app
cd svelte-typescript-app
node scripts/setupTypeScript.js
将此包添加@vertx/eventbus-bridge-client.js
为依赖项。
{
"name": "svelte-app",
"version": "1.0.0",
"scripts": {
"build": "rollup -c",
"dev": "rollup -c -w",
"start": "sirv public",
"validate": "svelte-check"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.0.0",
"@rollup/plugin-typescript": "^8.0.0",
"@tsconfig/svelte": "^1.0.0",
"rollup": "^2.0.0",
"rollup-plugin-css-only": "^3.0.0",
"rollup-plugin-livereload": "^2.0.0",
"rollup-plugin-svelte": "^7.0.0",
"rollup-plugin-terser": "^7.0.0",
"sirv-cli": "^1.0.0",
"svelte": "^3.0.0",
"svelte-check": "^1.0.0",
"svelte-preprocess": "^4.0.0",
"tslib": "^2.0.0",
"typescript": "^4.1.3"
},
"dependencies": {
"@vertx/eventbus-bridge-client.js": "^1.0.0"
}
}
App.svelte 看起来像这样:
<script lang="ts">
import EventBus from "@vertx/eventbus-bridge-client.js";
export let name: string;
const eb = new EventBus("http://localhost:8888/eventbus");
const handleClick = () => {
eb.send("chat-message", {message: "hello"});
}
</script>
<style></style>
<main>
<h1>Hello {name}!</h1>
<p>
Visit the
<a href="https://svelte.dev/tutorial">Svelte tutorial</a>
to learn how to build Svelte apps.
</p>
<button on:click={handleClick}>Send message</button>
</main>
我启动了 svelte 应用程序,yarn dev
这就是我在浏览器控制台中看到的内容:
Uncaught ReferenceError: process is not defined
app url.js:6
<anonymous> bundle.js:6388
...
为什么 svelte bundle 寻找进程?
PS:后端使用vertx4事件总线桥: https ://vertx.io/docs/vertx-web/java/#_sockjs_event_bus_bridge