Unlock the Power of Vue.js with Bit

zhaojinjiang2 months ago

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:

  • If you are a Vue.js developer, you can find Bit as a amazingly collaborative platform and workflow to work on.
  • At the same time, if you already work on Bit, it's a good time to meet Vue.js, which can potentially benefit your projects from the unlocked power and its ecosystem.

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.

What is Vue.js

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!')

  <h1>{{ msg }}</h1>
  <input v-model="msg">

  h1 { color: red }

Vue.js x Bit

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:

  1. It can be challenging to maintain a consistent coding style and ensure that everyone is working collaboratively.
  2. It can be difficult to reuse code across different projects, as developers often have to copy and paste code from one project to another.
  3. It can be hard to do version control in a fine-grained way, especially when multiple developers are working on different components in the same project.
  4. It can be impossible to analyze the impact of changes to the codebase, as it can be difficult to track down its dependents.

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:

Component-Based Development

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.

Improved Collaboration

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.

Streamlined Workflow

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.

A Demo of Vue.js on Bit

Create your first Vue Single-File Component (SFC)

The first step in using Bit with Vue.js is to initialize a Bit workspace, particularly in Vue env:

See command synopsis

Then you can cd my-vue-workspace and create a Vue component named “my-counter” in there:

See command synopsis

and install the dependencies:

See command synopsis

Now you have your first Vue component in this structure:

my-counter ├── my-counter.vue (the main file) ├── my-counter.docs.md (the docs) ├── my-counter-basic.fixture.vue (the basic example) ├── my-counter.composition.ts (the entry file of compositions) └── my-counter.spec.ts (the test cases)

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:

Create your first Vue composable

Besides Vue SFCs, you can also create a Bit component for reusable Vue composables through this command:

See command synopsis

Comparing to a Vue SFC, the main file of the Vue composable is a ts file:

use-counter ├── use-counter.ts (the main file) ├── use-counter.docs.md (the docs) ├── use-counter-basic.fixture.vue (the basic example) ├── use-counter.composition.ts (the entry file of compositions) └── use-counter.spec.ts (the test cases)

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:

Create your first Vue application

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:

See command synopsis

This will create a new Vue.js app in the "welcome" directory with those files:

welcome ├── welcome.vue-app.cjs (the app config) ├── welcome.root.ts (the entry file of the app) ├── static/index.html (the base HTML of the app) ├── welcome.vue (the main content of the app) └── ... (other files)

To run the app locally, you need 2 steps:

  1. Register the app by the component name:
See command synopsis
  1. run the app by its name in welcome.vue-app.cjs:
See command synopsis

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.

A quick review

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.

Vue development environment is now in beta

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.

  1. To get started, you can check out the official docs of Vue env.
  2. For feature requests and bugs, feel free to create an issue on GitHub.
  3. We also have a vue channel on Slack to welcome you to share and discuss more.

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.