Skip to content
Snippets Groups Projects
Commit f0e47ffa authored by Mateusz Tyszczak's avatar Mateusz Tyszczak :scroll: Committed by Bartek Wrona
Browse files

Add nuxt app example

parent 3b6b7a0b
No related branches found
No related tags found
1 merge request!260Typescript & toolset version update
This commit is part of merge request !260. Comments created here will be created in the context of that merge request.
# Nuxt dev/build outputs
.output
.data
.nuxt
.nitro
.cache
dist
# Node dependencies
node_modules
# Logs
logs
*.log
# Misc
.DS_Store
.fleet
.idea
# Local env files
.env
.env.*
!.env.example
# https://gitlab.syncad.com/hive group specification, offering aggregated package view: https://gitlab.syncad.com/groups/hive/-/packages
@hiveio:registry=https://gitlab.syncad.com/api/v4/groups/136/-/packages/npm/
# Nuxt (Vite)
[app.vue](app.vue) file was modified.
Important note!:
__**When importing Wax in Vite, remember to import dedicated Vite bundle everywhere in your project: `@hiveio/wax/vite`**__
Also remember that you have to asynchronously import Wax in Nuxt (e.g. using onBeforeMount hook or store)
## WASM-related Vite issues
Internal Note:
Vite currently does not fully support .WASM files as described [here](https://vite.dev/guide/features#webassembly), so we had to create some workarounds
* https://github.com/rustwasm/wasm-pack/issues/1106#issuecomment-2237247752
* https://stackoverflow.com/a/79204138
* https://github.com/vitejs/vite/issues/10761#issuecomment-1334844871
* https://vite.dev/guide/assets#explicit-url-imports
* https://www.npmjs.com/package/vite-plugin-wasm
import { expect, test } from '@playwright/test';
const waitForServerReady = async (url: string, interval: number = 1000, attempts: number = 10): Promise<void> => {
console.log(`Awaiting a server: ${url}...`);
for (let count = 0; count < attempts; ++count) {
try {
console.log(`Trying to connect ${count}/${attempts})`);
const response = await fetch(url, {
method: "GET",
signal: AbortSignal.timeout(interval)
});
if (response.ok && response.status === 200) {
console.log(`Connected successfully (${count}/${attempts}). Exiting.`);
return;
}
}
catch (error) {
if (typeof error !== "object" || !(error instanceof Error))
console.log(`Caught an UNKNOWN error (${JSON.stringify(error)})`);
else
if (error.name === "TimeoutError")
console.log(`Caught a TIMEOUT error (${JSON.stringify(error)})`);
else
if (error.name === "AbortError")
console.log(`Caught an ABORT error (${JSON.stringify(error)})`);
}
console.log(`Waiting for ${interval} ms...)`);
await new Promise(resolve => { setTimeout(resolve, interval); });
}
console.log(`Still down - bailing out.`);
};
test.describe('Proper WASM Wax loading on playwright ', () => {
test.beforeEach(async ({ page }) => {
/// use >> marker for each texts printed in the browser context
page.on('console', msg => {
console.log('>>', msg.type(), msg.text());
});
await waitForServerReady("http://localhost:5173");
await page.goto("http://localhost:5173", { waitUntil: "load" });
});
test('WASM should be properly loaded during development', async ({ page }) => {
// Wait for wax to be loaded
await page.waitForFunction(() => typeof (window as any).waxLoaded !== "undefined");
const result = await page.evaluate(async() => {
return (window as any).waxLoaded; // This value is set by this app in App.vue after successfull wax initialization
});
// Wax should be loaded
expect(result).toBe(true);
});
});
<script setup>
import { createWaxFoundation } from "@hiveio/wax/vite";
import { onBeforeMount } from 'vue';
const version = ref('');
onBeforeMount(async () => {
try {
const wax = await createWaxFoundation();
version.value = wax.getVersion();
window.waxLoaded = true;
} catch (error) {
console.error(error);
window.waxLoaded = false;
}
});
</script>
<template>
<div>
{{ version }}
</div>
</template>
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
compatibilityDate: '2024-11-01',
build: {
transpile: ['@hiveio/wax', '@hiveio/beekeeper']
}
})
{
"name": "nuxt-app",
"private": true,
"type": "module",
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev --host 0.0.0.0 --port 5173",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare",
"test": "unset CI && DEBUG=pw:webserver playwright test --workers 1 --max-failures 1 --project=wax_nuxt_vite_testsuite"
},
"dependencies": {
"@hiveio/wax": "file:../../../ts",
"@playwright/test": "1.49.1",
"nuxt": "^3.15.3",
"playwright": "1.49.1",
"vue": "latest",
"vue-router": "latest"
}
}
// This is a workaround for https://github.com/microsoft/playwright/issues/18282#issuecomment-1612266345
import { defineConfig } from '@playwright/test';
export default defineConfig({
projects: [
{
name: "wax_nuxt_vite_testsuite",
testDir: "./__tests__"
}
],
// Run your local dev server before starting the tests
webServer: {
command: 'npm run dev'
}
});
{
// https://nuxt.com/docs/guide/concepts/typescript
"extends": "./.nuxt/tsconfig.json"
}
...@@ -22,7 +22,8 @@ ...@@ -22,7 +22,8 @@
"examples:node-app": "cd ../examples/ts/node-app && pnpm install && pnpm run test && cd ../../../ts", "examples:node-app": "cd ../examples/ts/node-app && pnpm install && pnpm run test && cd ../../../ts",
"examples:vue-webpack": "cd ../examples/ts/vue-webpack && pnpm install && pnpm run build && cd ../../../ts", "examples:vue-webpack": "cd ../examples/ts/vue-webpack && pnpm install && pnpm run build && cd ../../../ts",
"examples:vue-vite": "cd ../examples/ts/vue-vite && pnpm install && pnpm run test && pnpm run build && cd ../../../ts", "examples:vue-vite": "cd ../examples/ts/vue-vite && pnpm install && pnpm run test && pnpm run build && cd ../../../ts",
"examples:react-vite": "cd ../examples/ts/react-vite && pnpm install && pnpm run test && pnpm run build && cd ../../../ts" "examples:react-vite": "cd ../examples/ts/react-vite && pnpm install && pnpm run test && pnpm run build && cd ../../../ts",
"examples:nuxt-app": "cd ../examples/ts/nuxt-app && pnpm install && pnpm run test && pnpm run build && cd ../../../ts"
}, },
"exports": { "exports": {
".": { ".": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment