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

@zhiq1/mcui

v0.1.7

Published

1. 使用`vue-cli`创建一个新项目 2. 在src目录下新建packages目录用来放组件代码 3. 在`packages/index.js`中引入所有组件,使用Vue插件形式 ```js // Vue组件要暴露一个有install函数的对象或者暴露一个函数作为install函数 const files = require.context('./components', true) const install = function (Vue) { files.keys().forEach(ke

Downloads

4

Readme

组件库

  1. 使用vue-cli创建一个新项目
  2. 在src目录下新建packages目录用来放组件代码
  3. packages/index.js中引入所有组件,使用Vue插件形式
// Vue组件要暴露一个有install函数的对象或者暴露一个函数作为install函数
const files = require.context('./components', true)
const install = function (Vue) {
  files.keys().forEach(key => {
    const fileContext = files(key).default
    Vue.component(fileContext.name, fileContext)
  })
}

// 判断是否直接引入文件,如果是,就不用调用vue.use,手动调用install并传入Vue
if (typeof window !== 'undefined' && window.Vue) {
  install(window.Vue)
}

export default {
  install
}
  1. package.json配置
{
// 这里的名字会被作为npm包名
  "name": "@zhiq1/mcui",
  "version": "0.1.0",
  "private": true,
// 入口文件,在被import时,会以此文件作为入口,要与build:lib中的name对应起来
//如果不配置,我们在其他项目中就不用import XX from '包名'来引用了,只能以包名作为起点来指定相对的路径
  "main": "dist/McUi.umd.min.js",
  // 要打包的目录和文件,package.json会被默认打包
  "files": [
    "dist",
    "src/packages"
  ],
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint",
    // vue-cli内置的打包lib的方法,指定name替换项目名称。最终产生的文件名即为这里指定的name
    "build:lib": "vue-cli-service build --target lib --name mcui src/packages/index.js"
  },
  // 项目基础依赖,避免核心依赖重复下载
  "peerDependencies": {
    "vue": "^2.6.11",
    "element-ui": "^2.13.1"
  },
  "dependencies": {
    "@meicloud/simple-table": "^1.0.0",
    // npm pack打本地包后执行npm install zhiq1-mcui-0.1.0.tgz后会生成这个依赖,node_modules里会安装@zhiq1/mcui文件
    "@zhiq1/mcui": "file:zhiq1-mcui-0.1.0.tgz",
    "core-js": "^3.6.5",
    "vue": "^2.6.11",
    "vue-router": "^3.2.0"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-plugin-router": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "@vue/eslint-config-standard": "^5.1.2",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-import": "^2.20.2",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-promise": "^4.2.1",
    "eslint-plugin-standard": "^4.0.0",
    "eslint-plugin-vue": "^6.2.2",
    "sass": "^1.26.5",
    "sass-loader": "^8.0.2",
    "vue-template-compiler": "^2.6.11"
  },
  "author": {
    "name": "zhiq",
    "github": "https://gitee.com/zhiq1/vue_components"
  }
}
  1. 测试是否可用,button/index.vue代码完成后,执行npm run build:lib 进行打包,会在根目录生成dist目录和打包的结果。
  2. 测试使用(两种引入方式)
  • 直接使用绝对路径import McUi from '/dist/mcui.umd.js'
  • 执行npm pack打成本地包,会在根目录看到类似zhiq1-cui-0.1.0.tgz的文件,然后执行npm install base_components-0.1.0.tgz安装后直接使用 import McUi from '@zhiq1/mcui'引入
  1. main.js引入后,使用Vue.use(McUi) 进行install 即可作为全局组件使用
  2. 发布到npm,建议发一个带前缀的,
    1. npm login
    2. npm publish --access public
      然后在npmjs上就可以看到自己的包了
  3. 在发包前修改版本号 以下命令会自动提升一个版本并将改动添加到git仓库
# version = v1.0.0
npm version patch
# v1.0.1
npm version prepatch
# v1.0.2-0
npm version minor
# v1.1.0
npm version major
# v2.0.0
  1. 安装使用 发布成功后,通过npm install @zhiq1/mcui安装后,import 'mcUI' from @zhiq1/mcui即可使用