zoukankan      html  css  js  c++  java
  • vite ant Design vue按需加载

    vite ant Design vue按需加载

    main.ts

    import { createApp } from 'vue'
    import { setupAntd } from './antd-ui'
    import App from './App.vue'
    
    const app = createApp(App)
    setupAntd(app)
    app.mount('#app')
    
    
    

    antd-ui.ts

    import {
      Button, Pagination, PageHeader, Select, Table, Layout, Menu, Form, Input, Spin,
      BackTop, Modal, message, Space, Breadcrumb, Popconfirm, Avatar, Skeleton
    } from 'ant-design-vue';
    const plugins = [Button, Pagination, PageHeader, Select, Table, Layout, Menu, Form, Input, Spin,
      BackTop, Modal, message, Space, Breadcrumb, Popconfirm, Avatar, Skeleton];
    
    export const setupAntd = (app: any, options = {}) => {
      app.config.globalProperties.$mes = message;
      plugins.forEach((plugin) => {
        app.use(plugin);
      });
    };
    

    vite.config.ts

    安装 3个插件

    npm install less less-loader vite-plugin-style-import -D
    

    由于 vite 本身已按需导入了组件库,因此仅样式不是按需导入的,因此只需按需导入样式即可。

    import { defineConfig } from 'vite'
    import vue from '@vitejs/plugin-vue'
    import styleImport from 'vite-plugin-style-import'
    

    // 如果编辑器提示 path 模块找不到,则可以安装一下

    @types/node -> npm i @types/node -D

     import { resolve } from 'path'
    // https://vitejs.dev/config/
    export default defineConfig({
      resolve: {
        alias: {
          '@': resolve(__dirname, 'src') // 设置 `@` 指向 `src` 目录
        }
      },
      plugins: [
        vue(),
        styleImport({
          libs: [
            {
              libraryName: 'ant-design-vue',
              esModule: true,
              resolveStyle: (name) => {
                return `ant-design-vue/es/${name}/style/index`
              }
            }
          ]
        }),
      ],
    
      css: {
        preprocessorOptions: {
          less: {
            modifyVars: { // 更改主题在这里
              'primary-color': '#52c41a',
              'link-color': '#1DA57A',
              'border-radius-base': '2px'
            },
            javascriptEnabled: true
          }
        }
      }
      }
    })
    

    参考

    https://blog.csdn.net/weixin_46602773/article/details/116048113

  • 相关阅读:
    ZOJ 2859 Matrix Searching
    URAL 1102. Strange Dialog
    ZOJ 1986 Bridging Signals
    POJ 3233 Matrix Power Series
    POJ 1836 Alignment
    POJ 3267 The Cow Lexicon
    ZOJ 3471 Most Powerful
    IIS:HTTP 错误 403.9 禁止访问:连接的用户过多
    使用Command对象执行数据库操作
    C#类型转换
  • 原文地址:https://www.cnblogs.com/ouyangkai/p/15597262.html
Copyright © 2011-2022 走看看