美文网首页
vue3 mockjs集成

vue3 mockjs集成

作者: 邦_ | 来源:发表于2024-03-26 13:37 被阅读0次

安装mockjs

pnpm install -D vite-plugin-mock@2.9.6  mockjs

vite.config.js 配置

import { UserConfigExport, ConfigEnv, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import path from 'path';
//svg的引用
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import { viteMockServe } from 'vite-plugin-mock';
// https://vitejs.dev/config/
export default ({ command, mode }: ConfigEnv): UserConfigExport => {
  //获取各种环境下对应的变量
  let env = loadEnv(mode, process.cwd());
  console.log(env);
  return {
    plugins: [
      vue(),
      createSvgIconsPlugin({
        iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
        symbolId: 'icon-[dir]-[name]',
      }),
      viteMockServe({
        localEnabled: command === 'serve',
      }),
    ],
    resolve: {
      alias: {
        '@': path.resolve('./src'),
      },
    },
    css: {
      preprocessorOptions: {
        scss: {
          javascriptEnabled: true,
          additionalData: '@import "./src/styles/variable.scss";',
        },
      },
    },
  };
};

相关文章

网友评论

      本文标题:vue3 mockjs集成

      本文链接:https://www.haomeiwen.com/subject/yugftjtx.html