Shipping a Vue Library Without a Build Step

UI Vintage publishes its source and lets each Nuxt app compile it. That choice removes a whole class of problems, and adds a couple of new ones.

Author
BrumaBruma
Published
Reading time
1 min
Category
Engineering
Shipping a Vue Library Without a Build Step

Most libraries ship a second copy of themselves

A typical component library has two versions of its code: the source you edit and a compiled bundle in dist/ that you publish. Keeping them in sync is a job of its own, with a bundler config, declaration files, and the occasional bug that only exists in the build.

UI Vintage skips the second copy. The npm package contains the .vue and .ts files as they are written, and the Nuxt module tells each app to compile them like its own code.

What you get for free

The obvious win is less tooling. The less obvious one is that the library behaves exactly like app code, because it is compiled by the same tools with the same settings.

From install to page

The library never builds itself. The app does it once, together with everything else.

  1. 01
    npm install
  2. 02
    Module registers
  3. 03
    App compiles source
  4. 04
    Tree-shaken page

Tailwind scans the library's templates directly, so every utility class a component uses ends up in the app's stylesheet. Vite tree-shakes per subpath import, so a page that only uses a button never loads the date picker.

Installing the library
Installing the library
npm install @brumaombra/ui-vintage
npx nuxi module add @brumaombra/ui-vintage
Ln 2, Col 1UTF-8bash

The tradeoffs are real

The strongest argument against this approach is that it ties the library to its framework. A compiled bundle could, in theory, run in any Vue app. A source package needs the toolchain it was written for, which here means Nuxt.

There is also a version contract to keep. Because apps compile the source, a library update can surface a type error in the app's build that a prebuilt bundle would have hidden. That is arguably a feature, but it does mean releases need a typecheck before they ship.

For a library whose only consumers are Nuxt apps, the trade is easy to accept. The point is not that build steps are bad. It is that a build step is code too, and the cheapest code to maintain is the code you don't need.

Frequently asked questions

Find quick answers to the most common questions about this topic.

A little, because the app compiles the library along with its own code. In practice the difference is small, and the app only compiles the components it actually imports.

Bruma

Author

Bruma
Published

Read also

Explore categories