安装view-ui-plus、less、less-loader、style-resources-loader
- npm install view-ui-plus --save
- npm install less@^2.7.3 --save-dev
- npm install less-loader@^6.2.0 --save-dev
- npm install style-resources-loader --save-dev
在main.js(mian.ts)中引入viewUI主键和样式
- import { createApp } from 'vue'
- import { createPinia } from 'pinia'
- import ViewUIPlus from 'view-ui-plus'//viewui 相关配置
- import App from './App.vue'
- import router from './router'
- import 'view-ui-plus/dist/styles/viewuiplus.css'//viewui 相关配置
-
- import './styles/index.less';
-
- const app = createApp(App)
-
- app.use(createPinia())
- app.use(router).use(ViewUIPlus)//viewui 相关配置
-
- app.mount('#app')
在vite.config.js中配置css的loaderOptions
- import { fileURLToPath, URL } from 'url'
- import { defineConfig } from 'vite'
- import vue from '@vitejs/plugin-vue'
-
- // https://vitejs.dev/config/
- export default defineConfig({
- plugins: [vue()],
- resolve: {
- alias: {
- '@': fileURLToPath(new URL('./src', import.meta.url))
- }
- },
- //关键代码
- css: {
- // // css预处理器
- // preprocessorOptions: {
- // less: {
- // charset: false,
- // additionalData: '@import "./src/styles/index.less";',
- // },
- // },
- loaderOptions: {
- less: {
- lessOptions: {
- javascriptEnabled: true
- }
- }
- }
- }
- })
首先在项目中先建一个目录,比如 styles
,然后在 styles
下建立一个 less 文件 index.less
,并写入下面内容:
- // @import '~view-ui-plus/src/styles/index.less'; 有问题
- @import 'view-ui-plus/src/styles/index.less';
-
- @primary-color: #8c0776;
在main.js(mian.ts)中引入 ./styles/index.less
import './styles/index.less';
或者在vite.config.js中配置css的preprocessorOptions
- css: {
- // css预处理器
- preprocessorOptions: {
- less: {
- charset: false,
- additionalData: '@import "./src/styles/index.less";',
- },
- },
- }
参照相关文档:
vue3.0 使用ant-design-vue 按需加载时报错.bezierEasingMixin()_与BUG战斗的小绵羊的博客-CSDN博客