Git Product home page Git Product logo

th-components-starter's Introduction

th-components-starter ๐Ÿงฑ

th-components-starter is a heavily opionated boilerplate for a Vue 3 component library.

  • โœŒ๏ธ uses Vue 3 with setup script syntax
  • ๐Ÿ’ช exports typed props, slot props and events for components
  • ๐Ÿ›  can be extended with utilities and composables
  • โœจ pre configured ESlint with Prettier integration
  • โšก๏ธ powered by Vite as build tool
  • ๐Ÿงฉ support for ES6 imports and fully tree shakable
  • ๐ŸŽจ components use SCSS as CSS preprocessor

How to start ๐Ÿš€

Fork or clone this project and make sure that you follow these steps in order to customize your component library:

  • rename the project in package.json of project root
  • optional: rename the @ prefix in packages/lib/package.json and packages/playground/package.json project names respectively, also rename the lib dependency in packages/playground/package.json, if you have renamed the lib project
  • run yarn install
  • run yarn lib:prepare
  • run yarn playground:dev to get playground dev server running

Add new components and composables

Folder structure

This folder structure is just an example

.
โ””โ”€โ”€ packages/
    โ””โ”€โ”€ lib/
        โ””โ”€โ”€ src/
            โ”œโ”€โ”€ components/
            โ”‚   โ”œโ”€โ”€ ThButton/
            โ”‚   โ”‚   โ”œโ”€โ”€ ThButton.vue
            โ”‚   โ”‚   โ””โ”€โ”€ ThButton.scss
            โ”‚   โ””โ”€โ”€ ThLayout.vue
            โ”œโ”€โ”€ composables/
            โ”‚   โ”œโ”€โ”€ useFeature/
            โ”‚   โ”‚   โ””โ”€โ”€ useFeature.ts
            โ”‚   โ”œโ”€โ”€ useNewFeature.ts
            โ”‚   โ””โ”€โ”€ index.ts
            โ””โ”€โ”€ index.ts

Please try to separate types, SCSS style and Vue SFC to separate files. Especially SCSS stylesheets need to be separate files, since they can be imported individually without using the whole css file.

Export components and composables

In order to export components and composables and get the support for typings you have to add the components and composables in the corresponding index.ts.

Components

// packages/lib/components/index.ts
export { default as ThButton } from './ThButton/ThButton.vue';
export { default as ThLayout } from './ThLayout.vue';

Composables

// packages/lib/composables/index.ts
export { default as useFeature } from './useFeature/useFeature.ts';
export { default as useNewFeature } from './useNewFeature.ts';

Build library

# build library
yarn run lib:build

The build step for lib also generates the typescript definitions for components, composables and other modules exported in src/index.ts.

How to use library

Vue Components

In order to use the library, just import the component directly from the library. Make sure to import every module individually to make use of Vite tree shaking.

Example:

<script lang="ts">
  import { ThHeader } from '@th-components/lib';
</script>

<template>
  <th-header title="Awesome title" />
</template>

The SCSS stylesheet of the component has to be imported either in a vue component.

<!-- App.vue -->
<script>
  import "@th-components/lib/src/ThButton/ThButton.scss";
  import { ThButton } from "@th-components/lib";
</script>

Or in a single main SCSS file

// main.scss
@import "@th-components/lib/src/ThButton/ThButton.scss";

th-components-starter's People

Contributors

thetimewaster avatar

Watchers

James Cloos avatar  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.