vue3+vite 引入全局的less文件

直接在 vite.config.ts 写入以下代码就可以了

import path from 'path'
css: {
    preprocessorOptions: {
      less: {
        modifyVars: {
          hack: `true; @import (reference) "${path.resolve('src/assets/styles/color.less')}";`,
        },
        javascriptEnabled: true
      }
    }
  },

如果 path报错 改为

import {resolve} from 'path'
css: {
    preprocessorOptions: {
      less: {
        modifyVars: {
          hack: `true; @import (reference) "${resolve('src/assets/styles/color.less')}";`,
        },
        javascriptEnabled: true
      }
    }
  },

你可能感兴趣的:(vue3+vite 引入全局的less文件)