Giter VIP home page Giter VIP logo

vue3-pnpm-workspace's Introduction

Vue 3 and pnpm workspace boilerplate

Reuse Components & Composables across multiple Applications

Description

This boilerplate is to demo a setup where we can take advantage of pnpm workspaces where multiple Vue 3 applications can share Components and Composables. This setup will provide the ability for different teams to work on different applications while being able to share reusable Components & Composables to follow a DRY (Don't Repeat Yourself) setup.

The other ability that pnpm workspace is providing us is the ability to have our workspace running with and even without publishing the Component, Composable packages on NPM (under an npm organization to take advantage or workspace) or locally with Verdaccio... in other words you could publish each packages of the workspace (in this demo that would be 4 of them: application1, application2, components and composables) or simply skip all of that and simply build & run them locally without ever publishing them anywhere.

For a great versioning/publishing tool in a workspace environment, take a look at Lerna-Lite which is what I use in a workspace monorepo structure.

What is included/configured

How does it work?

Since we are using pnpm workspace and Vite, we can take advantage of Vite's library mode and build the Components and Composables packages in that mode and make them available as distributed libraries/packages (via their dist folder), then we can use them in application1 and/or application2 separately. What if you need develop a Component or Composables, do we need to rebuild every single time? Yes we do, but for that we can take advantage of Vite's build.watch, which will rebuild for us and allow us to develop faster.

For more info about Vite library mode, this article explains it well.

Project structure

Components (/components)

A very simple MyButton Component is provided as an example of a reusable component

Composables (/composables)

A very simple useMouse Composable, which is a mouse position tracker, is provided as an example of a reusable composable.

Apps (/apps)

The Apps folder is where you will want to include all your applications.

Can we expand on this?

Sure, you could maybe add Directives and/or anything else that you deemed reusable. The steps are simple, just add a folder (probably easier to copy Component and rename/remove what is different) and then add it to the pnpm workspace via the pnpm-workspace.yaml file and add proper build scripts in the package.json file in the project root.

Inspiration

All credit goes to the Gun-Vue project when I was researching on how to do a Vue 3 pnpm workspace structure for reusability. I did not know how to build the Components/Composables as libraries and that project got me started. Thanks to them.

Contributions

Feel free to contribution to the project if you think that you can improve it.

Installation

The steps should be straightforward, simply run pnpm install, execute a build of all packages and then run application1 or application2. The steps assume that you already have installed pnpm, if not then follow the pnpm installation

  1. run pnpm install
pnpm install  # or pnpm i
  1. run a build
# run a full build of everything
pnpm build

# or run Components build separately
pnpm build:components

# or run Composables build separately
pnpm build:composables

# or run a build watch, which will be picked up by both the Components & Composables
pnpm build:watch
  1. run dev server (app1 or app2)
pnpm app1:dev
  1. run prod build (app1 or app2)
pnpm app1:build

# or run a full build of everything
pnpm build

vue3-pnpm-workspace's People

Contributors

ghiscoding avatar ghiscoding-se avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.