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

my-vue-element-ui

v0.0.1

Published

## 一、组件库初始化

Downloads

3

Readme

从零搭建 Vue3 组件库之环境搭建

一、组件库初始化

1.monorepo 项目初始化

yarn global add lerna
lerna init

lerna.json

{
  "packages": ["packages/*"],
  "version": "0.0.0",
  "npmClient": "yarn",
  "useWorkspaces": true
}

package.json

{
  "name": "root",
  "private": true,
  "workspaces": ["packages/*"],
  "devDependencies": {
    "lerna": "^3.22.1"
  }
}

2.初始化组件

lerna create button
lerna create icon

3.tsconfig 生成

yarn add typescript -W
npx tsc --init

配置 tsconfig.js

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "esModuleInterop": true, // 支持模块化转化
    "skipLibCheck": true, // 跳过类库检查
    "forceConsistentCasingInFileNames": true, // 强制区分大小写
    "moduleResolution": "node", // 指定模块解析模式
    "jsx": "preserve", // 指定jsx解析模式
    "declaration": true, // 生成声明文件
    "sourceMap": true
  }
}

4. 解析 ts vue 文件类型,新建 typings/vue-element.d.ts 文件(文件名只要是.d.ts 结尾即可)

// 首先安装项目依赖Vue
yarn add vue@next -W

// 处理解析ts文件中申明的vue文件
declare module "*.vue" {
  import {defineComponent, App} from "vue";
  const component: ReturnType <typeof defineComponent> & {
    install: (app: App) => void;
  };
  export default component;
}

使用 x-ui

yarn add webpack webpack-cli webpack-dev-server vue-loader @vue/compiler-sfc -D -W


搭建文档环境

1. 安装 webpack 构建工具

yarn add webpack webpack-cli webpack-dev-server vue-loader@next @vue/compiler-sfc -D

yarn add babel-loader @babel/core @babel/preset-env @babel/preset-typescript babel-plugin-module-resolver url-loader file-loader html-webpack-plugin css-loader sass-loader style-loader sass -D

2.babel 配置

// 在项目根目录下新建babel.config.js
module.exports = {
  presets: ["@babel/preset-env", "@babel/preset-typescript"],
  overrides: [
    {
      test: /\.vue$/,
      plugins: ["@babel/transform-typescript"],
    },
  ],
  env: {
    utils: {
      plugins: [["babel-plugin-module-resolver", { root: "x-ui" }]],
    },
  },
};

二、组件库打包

1. 打包 umd 格式组件库

使用 webpack 大包 umd 格式

// 在项目根目录下新建build/webpack.config.js文件
const path = require("path");
const { VueLoaderPlugin } = require("vue-loader");

module.exports = {
  mode: "production",
  entry: path.resolve(__dirname, "../packages/x-ui/index.ts"),
  output: {
    path: path.resolve(__dirname, "../lib"),
    filename: "index.js",
    libraryTarget: "umd",
    library: "x-ui",
  },
  externals: {
    vue: {
      root: "Vue",
      commonjs: "vue",
      commonjs2: "vue",
    },
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: "vue-loader",
      },
      {
        test: /\.(ts|js)x?$/,
        use: "babel-loader",
        exclude: /node_modules/,
      },
    ],
  },
  resolve: {
    extensions: [".tsx", ".ts", ".js", ".json"], // 表示在import 文件时文件后缀名可以不写
  },
  plugins: [new VueLoaderPlugin()],
};

三、组件样式打包 组件样式采用 EBM 规范

1. 使用 gulp 打包 scss 文件

安装 gulp 打包样式

yarn add gulp gulp-autoprefixer gulp-cssmin gulp-dart-sass gulp-rename -D

样式文件目录

| button.scss | icon.scss | common | -- var.scss #提供 scss 变量 | fonts #字体 | mixins | -- config.scss #提供名称前缀 | -- mixins.scss #提供 mixin 方法 | index.scss #整合所有的 scss

config.scss

$namespace: "z"; // 修饰命名空间
$state-prefix: "is-"; // 修饰状态
$modifier-separator: "--"; // 修饰类型
$element-separator: "__"; // 划分空间分割符

var.scss

@import "../minxins/config.scss";
$--color-primary: #409EFF;
$--color-white: #FFFFFF;
$--color-black: #000000;
$--color-success: #67C23A;
$--color-warning: #E6A23C;
$--color-danger: #F56C6C;
$--color-info: #909399;

mixin.scss

@import "../common/var.scss"

@mixin b($block) {
  $B: $namespace + "-" + $block;
  .#($B) {
    @content;
  }
}

@mixin when($state) {
  @at-root {
    &.#($state-prefix + $state) {
      @content;
    }
  }
}

@mixin m($modifier) {
  @at-root {
    #{&+$modifier-separator+$modifier} {
      @content;
    }
  }
}

@mixin e($element) {
  @at-root {
    #{&+$element-separator+$element} {
      @content;
    }
  }
}