npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@as1024/wyrd-ui

v0.2.19

Published

Vue3 Component Library

Downloads

26

Readme

WYRD UI

A fairly modern Vue 3 component library.

npm (scoped) npm bundle size (scoped) NPM

Install

import { createApp } from 'vue'
import { WyrdUI } from 'wyrd-ui'
import 'wyrd-ui/dist/style.css'

const app = createApp(App)
app.use(WyrdUI)

Use

<template>
  <WuiButton>naive-ui</WuiButton>
</template>

<script>
  import { defineComponent } from 'vue'
  import { WuiButton } from 'wyrd-ui'

  export default defineComponent({
    components: {
      WuiButton,
    },
  }),
</script>

Types

If you are using Volar, you can specify global component types by configuring compilerOptions.types in tsconfig.json.

// tsconfig.json
{
  "compilerOptions": {
    // ...
    "types": ["wyrd-ui/volar"]
  }
}

Utilities and constants

The library includes example utilities and constants. They are also exported in index.ts. The client app may use them as below:

<script lang="ts">
import { MyConstants, MyUtil } from 'my-lib'

export default {
  data () {
    return {
      magicNum: MyConstants.MAGIC_NUM
    }
  },
  methods: {
    add (a:number, b:number) {
      return MyUtil.add(a, b)
    }
  }
}
</script>

Styling

Individual compopnent may have styles defined in its .vue file. They will be processed, combined and minified into dist/style.css, which is included in the exports list in package.json.

If you have library level styles shared by all components in the library, you may add them to src/assets/main.scss. This file is imported in index.ts, therefore the processed styles are also included into dist/style.css. To avoid conflicting with other global styles, consider pre-fixing the class names or wrapping them into a namespace class.

If you have your own special set of SVG icons, you may create a font file (.woff format) using tools like Icomoon or Fontello. This starter includes an example font file src/assets/fonts/myfont.woff and references it in src/assets/main.scss, with utility icon CSS classes. An icon from the font file is used in Component A. Vite will include the font file into the build, see https://vitejs.dev/guide/assets.html.

The client app shall import style.css, usually in the entry file:

import 'my-lib/dist/style.css'

Third-party dependencies

Third-party libraries used by you library may bloat up the size of your library, if you simply add them to the dependencies in package.json.

The following are some strategies to reduce the size of your library:

Externalization

If you expect the client app of your library may also need the same dependency, you may externalize the dependency. For example, to exclude WyrdUI from your library build artifact, in vite.config.ts, you may have

module.exports = defineConfig({
    rollupOptions: {
      external: ['vue', 'wyrd-ui']
    }
  }
})

The dependency to be externalized may be declared as peer dependency in your library.

Cherry picking

If you don't expect the client app of your library also needing the same dependency, you may embed cherry-picked functions. For example, to embed the fill function of popular library lodash, import the fill function like the following:

import fill from 'lodash/fill'

Even with tree-shaking, the codes being brought into your library may still be large, as the function may have its own dependencies.

Note that import { fill } from 'lodash' or import _ from 'lodash' will not work and will embed the whole lodash library.

Finally, if your client app also use lodash and you don't want lodash to be in both the client app and your libraries, even after cherry-picking, you may consider cherry-picking in component library and re-export them as utils for client to consume, so that the client does not need to depend on lodash, therefore avoiding duplication.

Type generation

In tsconfig.json, the following options instructs tsc to emit declaration (.d.ts files) only, as vite build handles the .js file generation. The generated .d.ts files are sent to dist/types folder.

  "compilerOptions": {
    "declaration": true,
    "emitDeclarationOnly": true,
    "declarationDir": "./dist/types"
  }

In package.json, the line below locates the generated types for library client.

  "types": "./dist/types/index.d.ts",

In vite.config.ts, build.emptyOutDir is set to false and rimraf is used instead to remove the dist folder before the build. This is to avoid the dist/types folder generated by tsc being deleted when running vite build.

Configuration

TypeScript

In tsconfig.json, compilerOptions.isolatedModules is set to true as recommended by Vite (since esbuild is used). However, enableing this option leads to https://github.com/vitejs/vite/issues/5814. The workaround is to also enable compilerOptions.skipLibCheck.

Dependencies

In package.json, vue and wyrd-ui are declared in both peerDependencies and devDependencies. The former requires the client app to add these dependencies, and the later makes it easier to setup this library by simply running npm install.