import{_ as s,o as n,c as a,R as l}from"./chunks/framework.6241eaf2.js";const A=JSON.parse('{"title":"Webpack 4 vue.config.js 基础配置","description":"","frontmatter":{},"headers":[],"relativePath":"guide/vue2/base.md","filePath":"guide/vue2/base.md","lastUpdated":1731315864000}'),p={name:"guide/vue2/base.md"},o=l(`

Webpack 4 vue.config.js 基础配置

如果你的 Vue Router 模式是 hash

javascript
publicPath: './',

如果你的 Vue Router 模式是 history 这里的 publicPath 和你的 Vue Router base 保持一致

javascript
publicPath: '/app/',

配置如下

javascript
import { createVitePlugins } from "./config/vite/plugins";
import { resolve } from "path";
import { ConfigEnv, UserConfigExport } from "vite";

const pathResolve = (dir: string) => {
  return resolve(process.cwd(), ".", dir);
};

// https://vitejs.dev/config/
export default function ({ command }: ConfigEnv): UserConfigExport {
  const isProduction = command === "build";
  const root = process.cwd();
  return {
    root,
    resolve: {
      alias: [
        {
          find: "vue-i18n",
          replacement: "vue-i18n/dist/vue-i18n.cjs.js",
        },
        // /@/xxxx => src/xxxx
        {
          find: /\\/@\\//,
          replacement: pathResolve("src") + "/",
        },
        // /#/xxxx => types/xxxx
        {
          find: /\\/#\\//,
          replacement: pathResolve("types") + "/",
        },
      ],
    },
    server: {
      host: true,
      hmr: true,
    },
    plugins: createVitePlugins(isProduction),
    css: {
      preprocessorOptions: {
        scss: {
          // 配置 nutui 全局 scss 变量
          additionalData: \`@import "@nutui/nutui/dist/styles/variables.scss";@import '/@/styles/mixin.scss';\`,
        },
      },
    },
  };
}
`,7),e=[o];function t(c,r,F,D,y,i){return n(),a("div",null,e)}const u=s(p,[["render",t]]);export{A as __pageData,u as default};