• vue组件库开发,webpack打包,发布npm


    做一个像elment-ui一样的vue组件库
    那多好啊!这是我前几年就想做的
    webpack真的太难用,也许是我功力不够
    今天看到一个视频,早上6-13点,终于实现了,呜呜

    感谢视频的分享-来龙去脉-大家可以看这个视频:https://www.bilibili.com/video/BV1Zf4y1u75o?p=9&vd_source=125d808bbbad2b8400f221b816a0f674

    有些能力你可能不用,但你必须具备,就像这个vue组件库开发

    1.我终于发布了一个自己的组件库

    1.1在npm上面
    在这里插入图片描述

    1.2 别人如何使用:
    在这里插入图片描述
    1.3 本地使用效果:
    在这里插入图片描述

    2.核心代码

    全部源码地址:https://gitee.com/618859/yiz-ui
    核心文件1:webpack.config.js

    // 不懂可以微信我yizheng369
    const path = require('path');
    // const VueLoaderPlugin = require('vue-loader/lib/plugin');
    const { VueLoaderPlugin } = require("vue-loader");
    const { CleanWebpackPlugin } = require('clean-webpack-plugin');
    
    module.exports = {
      mode: 'development',
      // entry: './src/components/index.js',
      entry: {
        // 把组件一个个写到这里才能正常打包喔
        card: './src/components/card/index.js',
        myInput: './src/components/my-input/index.js',
        yizTitle: './src/components/yiz-title/index.js',
        index: './src/components/index.js',
      },
      output: {
        path: path.resolve(__dirname, 'dist'),
        filename: '[name].umd.js',
        library: 'YizUI',
        libraryTarget: 'umd',
      },
      // resolve: {
      //   alias: {
      //     '@': path.resolve(__dirname, 'src'),
      //   },
      // },
      plugins: [
        // 先删除原来的文件,再打包
        new CleanWebpackPlugin(),
        new VueLoaderPlugin()
      ],
      module: {
        rules: [
          {
            test: /\.css$/,
            use: ['style-loader', 'vue-style-loader', 'css-loader']
          },
          {
            test: /\.vue$/,
            use: [
              {
                loader: 'vue-loader'
              }
            ]
          },
        ]
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49

    核心文件2: 集中注册文件

    // 集中在这里注册
    import Card from './card/src/main.vue'
    import MyInput from './my-input/src/main.vue'
    import yizTitle from './yiz-title/src/main.vue'
    // console.log('card', Card);
    const components = [Card, MyInput, yizTitle]
    function install(Vue){
      components.forEach(component => {
        // 全局注册组件
        Vue.component(component.name, component)
      })
    }
    // 将注册函数导出去
    export default { install }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    大家将源码下载下来,一看就明白了。

  • 相关阅读:
    whip和whep
    Java利用RedisTemplate给redis存储map集合数据
    【源码+文档+调试讲解】微信小程序家政项目小程序
    MySQL排序查询
    轻量级网络结构
    腾讯mini项目-【指标监控服务重构】2023-08-13
    CSS3_字体图标
    java调用Excel中的GAMMADIST函数返回伽玛分布
    网络编程 10.26
    Ansible 连接受控端sudo超时
  • 原文地址:https://blog.csdn.net/yuan_618859/article/details/132793254