yanballas
yanballas

Reputation: 99

Change path in dist html in Vite

Hello everyone I have a problem. I use Vitek to build the application. My path to src img '../../../' When building, I want to get the path ./ But the paths are not replaced, although I specified base ./ My vite.config. Perhaps there is some kind of plugin to solve this problem? I also use custom plugins, I can provide them if necessary

export default defineConfig({
  root: "src",
  base: "./",
  build: {
    outDir: "../dist",
    emptyOutDir: "../dist",
    rollupOptions: {
      output: {
        assetFileNames: (assetInfo) => {
          const extType = assetInfo.name.split(".").pop();
          if (["png", "jpg", "jpeg", "gif", "webp", "avif"].includes(extType)) {
            return "img/[name].[hash][extname]";
          }
          if (["svg"].includes(extType)) {
            return "icons/[name].[hash][extname]";
          }
          if (["woff", "woff2", "ttf", "eot", "otf"].includes(extType)) {
            return "fonts/[name].[hash][extname]";
          }
          return "assets/[name].[hash][extname]";
        },
      },
    },
  },
  plugins: [
    ViteImageOptimizer(DEFAULT_OPTIONS),
    viteCompression({
      algorithm: "brotliCompress",
    }),
    {
      name: "optimize-images-and-wrap",
      closeBundle: async () => {
        await optimizeImages();
        await wrapImgWithPicture();
      },
    },
    [
      handlebars({
        partialDirectory: resolve(__dirname, "src/components"),
      }),
    ],
    GlobPlugin({}),
  ],
  css: {
    postcss: {
      plugins: [autoprefixer({})],
    },
  },
});

Upvotes: 0

Views: 6

Answers (0)

Related Questions