Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vite-plugin-antd-theme

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-antd-theme

vite下的antd-design-vue主题生成插件

  • 1.0.0
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

vite-plugin-antd-theme

vite 下的 antd-design-vue 主题生成插件,依赖 antd-theme-generator

demo

vite.config.ts

// ...
import viteAntdTheme, { ThemeEntry, AntdThemeOptions } from 'vite-plugin-antd-theme';


const themesEntry: Array<ThemeEntry> = [
  // 暗黑主题
  {
    entryPath: './node_modules/ant-design-vue/lib/style/themes/dark.less',
    outputName: 'dark',
    outputPath: './src/config'
  },
  // 默认主题
  {
    entryPath: './src/styles/vars.less',
    outputName: 'light',
    outputPath: './src/config'
  },
  // 紧凑主题
  {
    entryPath: './node_modules/ant-design-vue/lib/style/themes/compact.less',
    outputName: 'compact',
    outputPath: './src/config'
  },
  // ...其他自定义主题
];

const options: AntdThemeOptions = {
  themesEntry,
  // 是否提取全部变量,默认false,优先级低于设置themeVariables
  allVariables: true,
  // 以下是antd-theme-generator配置项
  antdDir: path.join(__dirname, './node_modules/ant-design-vue'),
  stylesDir: path.join(__dirname, './src'),
  varFile: path.join(__dirname, './src/styles/vars.less'),
  themeVariables: [],
  outputFilePath: path.join(__dirname, './public/static/color.less')
  customColorRegexArray: [/^fade\(.*\)$/]
};

export default ({ command }: ConfigEnv): UserConfigExport => {
  return {
    // ...
    plugins: [
      // ...
      viteAntdTheme(options)
    ],
    css: {
      preprocessorOptions: {
        less: {
          javascriptEnabled: true
        }
      }
    }
  };
};

index.html

<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" href="/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>vite-plugin-antd-theme</title>
  </head>
  <body>
    <div id="app"></div>
    <script type="module" src="/src/main.ts"></script>
    <!--必须将引用放在最后,否则生成的主题会被其他覆盖-->
    <link rel="stylesheet/less" type="text/css" href="/static/color.less" />
    <script src="/static/libs/less.min.js"></script>
  </body>
</html>

App.tsx(App.vue?)

// ...
import { defineComponent } from 'vue';
import 'ant-design-vue/dist/antd.less';
import darkVars from '@/config/dark.json';

export default defineComponent({
  mounted() {
    window.ddd = () => {
      window['less'].modifyVars(darkVars).then(console.log);
    };
  },
  setup() {
    return () => <span>嗯嗯</span>;
  },
});

// 测试

window.ddd();

Keywords

FAQs

Package last updated on 21 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc