How to build a Vue app with Vite, Oak, and Deno
If you’re looking to build a modern web application using Vue.js, Vite, Oak, and Deno can be a great stack to work with. In this article, we will walk through the steps to set up a Vue app using these technologies.
Step 1: Install Deno
Deno is a secure runtime for JavaScript and TypeScript. To use it, you need to install Deno on your machine. Visit the Deno website (deno.land) and follow the instructions to install it.
Step 2: Set up a Vite app
Vite is a build tool specifically designed for development with Vue. To create a new Vite app, open your terminal and run the following command:
deno run --unstable --import-map=import_map.json --allow-net [VITE_URL]
Replace [VITE_URL] with the URL of the Vite template you want to use. This will create a new Vite app in your current directory.
Step 3: Set up Oak
Oak is a middleware framework for Deno, which can be used for building web applications. To set up Oak, create a new file called server.ts in the root of your project and add the following code:
import { Application } from "https://deno.land/x/oak/mod.ts";
const app = new Application();
app.use((ctx) => {
ctx.response.body = "Hello, Oak!";
});
await app.listen({ port: 8000 });
This code sets up a basic Oak server that listens on port 8000 and returns “Hello, Oak!” as the response. You can customize this to fit your needs.
Step 4: Connect Vite with Oak
To connect Vite with Oak, open your Vite app’s main.ts file and add the following code:
import { createApp } from 'vue'
import App from './App.vue'
import { oakPlugin } from './oakPlugin.ts'
const app = createApp(App)
app.use(oakPlugin)
app.mount('#app')
This code imports the Oak plugin and sets it up to be used with your Vue app. The oakPlugin function should be defined in oakPlugin.ts and should export a Vue plugin object.
Step 5: Start the server
To start the server, run the following command in your terminal:
deno run --unstable server.ts
Now, your Vue app should be running at http://localhost:8000. You can access it in your web browser and start building your application.
With Vite, Oak, and Deno, you have a powerful and efficient stack to build your Vue app. Take advantage of the benefits these technologies offer and build amazing web applications.
I try to run this template but it does not work in development. I am getting fail to construct websocket error message. And I have raise issue in github.
Great example
Q? What do think to use trpc instead of oak router?
Doesn't work properly on windows, you can't pick a template because the arrow keys don't work.