Over the years, we received many inquiries from the Bit community about Vue.js support. People love Vue.js and want to use it with Bit.
Today, we are super excited to beta release the Vue development environment (Vue env) on Bit and its official docs publicly. We hope:
In this article, we'll explore the potential of Vue.js with Bit. But before we dive into the details, let’s take a moment to know what Vue.js is and how it works.
Vue.js is one of the most popular JavaScript frameworks. It progressively enables developers to build user interfaces for web applications.
Vue.js is designed to be approachable, performant, and versatile. It allows developers to use familiar HTML, CSS, and JavaScript to build web apps. To optimize the app performance automatically, it utilizes the power of the compilation process as well. Also, Vue.js has a rich ecosystem for all kinds of stuff.
One of the key features of Vue.js is the Single File Components (SFC), which allows developers to encapsulate their HTML, CSS, and JavaScript into a single file, making it easier to manage and reuse code. In addition, Vue.js also allows developers to write Vue composables, which are reusable functions that can be shared across different Vue components. Here is what a Vue SFC looks like:
<script setup>
import { ref } from 'vue'
const msg = ref('Hello World!')
</script>
<template>
<h1>{{ msg }}</h1>
<input v-model="msg">
</template>
<style>
h1 { color: red }
</style>
Vue.js makes the codebase easier to manage and maintain, as they encourage developers to abstract, decouple, and reuse high-quality code by breaking down complex functionality into smaller pieces. However, as projects become more complex and teams grow:
Those are how Bit can help you further.
Bit is a component-based development platform that helps developers to build, share, and reuse code across different projects. Everything on Bit is an independent Bit component that has its own isolated developement environment, build pipeline, and versioning control.
The philosophy behind Vue.js and Bit are perfectly matched. With Bit and Vue.js together, developers can make a big move forward in:
One of the key benefits of using Bit with Vue.js is that it truly enables component-based development. In Vue.js, SFCs and Vue composables are the building blocks of web applications, and Bit makes it easy to create, share, and reuse them as Bit components across different projects. This can help to streamline development and improve code quality, as developers can focus on building high-quality content rather than writing the same code over and over again.
Bit makes the collaboration with other developers much easier. It allows developers to truly share their Vue SFCs or Vue composables across different projects, teams, and organizations. This can help a team to reduce duplication of effort. Meanwhile, you can clearly see the impact of your components and yourself in the whole project or company.
Bit also helps developers to streamline the development workflow. It allows you to create, test, and share Vue SFCs and Vue composables from a single platform, making it easier to manage the development process. You can easily control the version of your components and track the impact of the changes made. Bit can also help you to ensure that your components are high-quality and well-documented.
To showcase the benefits of using Bit with Vue.js, now let's walk through a demo of how to use Bit with Vue.js.
The first step in using Bit with Vue.js is to initialize a Bit workspace, particularly in Vue env:
Then you can cd my-vue-workspace
and create a Vue component named “my-counter” in there:
and install the dependencies:
Now you have your first Vue component in this structure:
Now you can preview the component by bit start
:
You can feel free to modify the code as you want, and at the same time, run Bit commands like bit test
, bit lint
, bit format
for your components. These steps ensure that your component is high-quality, well-documented, and ready to be shared across different projects.
To share your component, run bit snap
, bit tag
, and bit export
to complete. Here are some well-published Vue components as examples you can refer to:
Besides Vue SFCs, you can also create a Bit component for reusable Vue composables through this command:
Comparing to a Vue SFC, the main file of the Vue composable is a ts file:
The else part of the development experience is quite similar to the one for a Vue SFC. Here are some well-published examples you can refer to:
Once you have created and exported your components, the next step is to create an app that uses your components. To create a new Vue.js app, run the following command:
This will create a new Vue.js app in the "welcome" directory with those files:
To run the app locally, you need 2 steps:
welcome.vue-app.cjs
:You can also import other existing components on Bit into your app for sure.
To see a well-completed Vue app with Vue SFCs and Vue composables, here is a TodoMVC app you can refer to. Don't forget to click the "Code" tab at the right-top corner to see its source code:
If you are interested in the details of all the dependency Vue SFCs and Vue composables in this app, feel free to check them out further on Bit:
And with a simple configuration, you can easily publish your app to 3rd-party platforms. Here is the app we already deployed on Netlify as an example.
As you can see, using Bit with Vue.js can make it easier to focus on your own content in a component-based way with streamlined development. You can also easily collaborate with Vue SFCs and Vue composables made by other developers. It can truly unlock the power of Vue.js and your team to the next level. To learn more about Bit, please check out our official docs.
The whole Vue env is in beta today. That means the core implementation has been completed and is ready to use. In terms of the extensibility and the development experience, we’d like to still keep improving it with your voice and support.
So far, you already know what Vue.js is and how to create your Vue SFCs, Vue composables, and Vue apps on Bit. We also introduced the Vue env in beta with the official docs, the way of feature requests & bug reports, and the Vue discussion channel. We hope you will enjoy it. And feel free to reach out to us in any way.
Cheers!