,

Creating and Sharing a Vue.js Component Library Using GitHub Actions and Vite

Posted by

How to Build and Publish a Vue.js Component Library with GitHub Actions and Vite

How to Build and Publish a Vue.js Component Library with GitHub Actions and Vite

Building and publishing a Vue.js component library can be a great way to share reusable Vue components with the community. GitHub Actions and Vite can help automate the build and publish process, making it easier for developers to consume your library.

Setting up the Project

The first step is to create a new Vue.js project using Vite. Vite is a build tool that is designed to be fast and efficient for Vue projects. You can install Vite using npm or yarn:


npm init @vitejs/app my-component-library --template vue

This will create a new Vue.js project with Vite as the build tool. You can then create your Vue components inside the project and organize them into a library structure.

Automating the Build Process with GitHub Actions

GitHub Actions is a powerful tool for automating various tasks within your GitHub repositories. You can use GitHub Actions to automate the build and publishing process for your Vue component library.

Create a .github/workflows/build.yml file in your project and add the following code to set up a build workflow:


name: Build and Publish
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install dependencies
run: npm install
- name: Build library
run: npm run build
- name: Publish to npm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}

This workflow will run whenever code is pushed to the main branch, checking out the code, installing dependencies, building the library, and then publishing it to npm.

Publishing the Library

After setting up the build workflow with GitHub Actions, you can now publish your Vue component library to npm. Make sure to create an npm account and obtain an access token, then add the access token as a secret in your GitHub repository settings with the name NPM_AUTH_TOKEN.

Conclusion

By using GitHub Actions and Vite, you can automate the build and publish process for your Vue.js component library, making it easier for developers to consume and contribute to your library. This can help to foster a strong community around your library and make it more accessible to the wider Vue.js community.

0 0 votes
Article Rating
6 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@Auiydssyz
6 months ago

"dist/MyBrandButton/MyBrandButton.vue.d.ts" and "dist/MyBrandInput/MyBrandInput.vue.d.ts" are both containing just two lines:

declare const _default: any;
export default _default;

Nothing more. It also says "Component is missing template or render function." in the console.
dist/ui-lib.js seems to be fine, but it doesn't render anything in the frontend. Any ideas why and how to fix it?

@degradiranjepodcast6776
6 months ago

Good tutorial, but missing the usage. Also, an advice – someone told you, or you have read somewhere that by waving your hands like this in front of the camera – that you are improving your authority, but you are just mingling with those hands in unnatural way so it becomes annoying :). Just and advice, don't take it personally.

@peoray
6 months ago

Very insightful video. If I want to publish this to a normal (I guess public npm name), what would I do differently?

@blindpupil
6 months ago

Thank you. I added some scoped styles in scss and installed the vite sass package to handle it. But after bundling and importing the library, the custom styles are not being implied. Any idea how to fix this so that scoped scss styles in the CL work when imported somewhere in a different project?

@donnacasterr6223
6 months ago

Thanks for the Precise and useful tutorial.

So many videos on here were just beating around the bush or talking about a totally different technology.
Great job.

@nomadsland6886
6 months ago

Best 🤩