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

@rollup-build-components/icon-select-vue3.x

v1.1.1

Published

基于 Vue3.x Ant Design Vue 图标选择器

Downloads

5

Readme

用 Rollup 打包 Vue3.x UI 组件

IconSelect 组件是基于 @ant-design/icons-vue Icon 和 Vue3.x Ant-Design-Vue 的 Select 组件组合封装而成
作为 Rollup 打包 Vue3.x UI 组件的范例,后续仅维护 Rollup Build Configure And Package Upgrade
其中引用的 Select 组件为了样式, 关闭 virtual(false), 存在性能问题, 不可生产环境中使用

Rollup 打包所涉及的处理

  1. Rollup 打包 Vue3.x 组件 - 所需依赖
  2. Rollup 打包 Vue3.x 组件 - 插件选项
  3. Rollup 打包 Vue3.x 组件 - Typescript 配置
  4. Rollup 打包 Vue3.x 组件 - Script 脚本配置
  5. 如何下载使用 IconSelect 组件?

1. Rollup 打包 Vue3.x 组件 - 所需依赖 (详见 package.json)

  • @rollup/plugin-alias

    • 用途: rollup 路径别名配置
  • @rollup/plugin-node-resolve

    • 用途: 用于解析 node_modules 中第三方模块
  • @rollup/plugin-commonjs

    • 用途: 用于将CommonJS模块转换为ES6,以便 Rollup 解析处理
  • @rollup/plugin-babel

    • 用途: rollup babel plugin

    • 配置: babel.config.js

        module.exports = {
          plugins: [
            '@vue/babel-plugin-jsx'
          ]
        }
    • 依赖:

      • @babel/core babel 核心
      • @vue/babel-plugin-jsx babel 处理 Vue3.x jsx 语法
      • @vue/babel-helper-vue-jsx-merge-props babel 处理 Vue jsx props
  • rollup-plugin-vue

    • 用途: 解析 Vue SFC (Single File Component)
    • 版本: Vue3.x时, version >= 6.0.0
    • 依赖:
      • vue version >= 3.2.0
      • less version >= 4.1.3
      • vue-template-compiler version >= 3.2.0
  • rollup-plugin-postcss

    • 用途: 用于处理 css 样式, 包括 Vue 单文件中 <style> 样式
  • rollup-plugin-typescript2

    • 用途: 用于处理 .vue 及 .ts文件中 ts 语法的解析
    • 问题: 在 rollup 处理中为什么不使用 @rollup/plugin-typescript 呢?, 因为在解析 .vue 文件中 ts 语法存在问题, 查看 Issue
  • @rollup/plugin-typescript

    • 用途: 用于解析 rollup.config.ts 配置文件
    • 使用: rollup --config rollup.config.ts --configPlugin typescript // 此处 typescript 即 @rollup/plugin-typescript

2. Rollup 打包 Vue3.x 组件 - 插件选项


  import { defineConfig } from 'rollup'
  import { nodeResolve } from '@rollup/plugin-node-resolve'
  import typescript from 'rollup-plugin-typescript2'
  import commonjs from '@rollup/plugin-commonjs'
  import postcss from 'rollup-plugin-postcss'
  import babel from '@rollup/plugin-babel'
  import alias from '@rollup/plugin-alias'
  import vue from 'rollup-plugin-vue'

  /**
   * Rollup Configuration
   */
  export default defineConfig([
    {
      input: 'src/index.vue',
      output: [
        {
          dir: 'dist',
          format: 'es',
          entryFileNames: chunk => `[name].mjs`
        },
        {
          dir: 'dist',
          format: 'cjs',
          exports: 'named',
          entryFileNames: chunk => `[name].cjs`
        }
      ],

      plugins: [
        alias({
          entries: [{
            find: '@',
            replacement: new URL('./src', import.meta.url).pathname
          }]
        }),
        nodeResolve(),
        commonjs(),
        typescript({
           check: false  // 需使用 rollup-plugin-typescript2
        }),              // 而不是 @rollup/plugin-typescript
        vue(),
        postcss(),
        babel({                       // 指定 babel 处理文件类型
          babelHelpers: 'bundled',    // 如果 vue 存在 jsx 语法,
          extensions: ['.js', '.vue'] // 则会从 babel.config.js, 调用 @vue/babel-plugin-jsx 处理
        })
      ],

      // 排除不需要混入代码中的第三方依赖
      external: [
        /^vue(\/.+|$)/,
        /^ant-design-vue(\/.+|$)/,
        /^@ant-design\/icons-vue/
      ]
    }
  ])

3. Rollup 打包 Vue3.x 组件 - Typescript 配置

  • 创建 tsconfig.json 配置文件,需生成声明文件,则需要增加 declaration: true
  {
    "compilerOptions": {
      "baseUrl": "./",
      "outDir": "dist",
      "target": "ESNext",
      "module": "ESNext",
      "jsx": "preserve",
      "moduleResolution": "Node",
      "useDefineForClassFields": true,
      "allowSyntheticDefaultImports": true,
      "strict": true,
      "sourceMap": true,
      "resolveJsonModule": true,
      "isolatedModules": true,
      "esModuleInterop": true,
      "skipLibCheck": true,
      "declaration": true,
      "lib": [
        "ESNext",
        "DOM"
      ],
      "paths": {
        "@/*": [
          "src/*"
        ]
      }
    },
    "include": [
      "src/**/*.ts",
      "src/**/*.d.ts",
      "src/**/*.tsx",
      "src/**/*.vue"
    ]
  }

4. Rollup 打包 Vue3.x 组件 - Script 脚本配置

  {
    "scripts": {
      "build": "shx rm -rf dist && rollup --config rollup.config.ts --configPlugin typescript"
    }
  }

5. 如何下载使用 IconSelect 组件?

  • 安装

  yarn add @rollup-build-components/icon-select-vue3.x

  pnpm add @rollup-build-components/icon-select-vue3.x
  • 使用
  <template>
    <section class="section-container">
      <icon-select v-model="value"/>
    </section>
  </template>
  <script setup lang="ts">
    import { ref, watch } from 'vue'
    import IconSelect from '@rollup-build-components/icon-select-vue3.x'
    const value = ref('fast-forward')
    watch(value, v => console.log(v))
  </script>

许可证

MIT