TinkoLiu / vue3-ts-lib-template

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vue 3 + TypeScript Library Template

A simple but complete library template for Vue 3 + TypeScript

Getting started

Getting the code by git clone or click Use this template right above.

Then use yarn or other package manager to install dependencies.

CSS

This template includes Scss with it. Scoped style in Vue SFC is also supported. All the styles will be build into a index.css right in the project root.

When using your library by npm package in another project, you can import this css by

import '{YOUR_LIB_NAME}/index.css'

Dev server

The dev server is provided by Vite. To start the dev server, run

yarn dev

Writing packages

Simply creating a folder in packages and add it to packages/index.ts, and it's done.

Build your packages

yarn build

Will build your packages in two format ( esm and CommonJS ) using rollup instead of Vite due to the issue when generating .d.ts file.

Once everything done, you can pack your library by npm pack or publish it by npm publish

External dependencies

If you want to exclude your dependencies from your build result:

  1. Add the package to peerDependencies in package.json
  2. Add the package to external in rollup.config.js

When using this library, remember to install these peerDependencies.

About d.ts

TypeScript declaration files will generated into lib folder once you build this template. That means the decalration files will be published in the npm package.

Also, .vue.d.ts will be generated for Vue SFC.

About


Languages

Language:JavaScript 58.1%Language:TypeScript 16.5%Language:Vue 15.3%Language:HTML 6.4%Language:Shell 2.8%Language:SCSS 1.0%