vite-plugin / vite-plugin-dynamic-import

Enhance Vite builtin dynamic import
https://www.npmjs.com/package/vite-plugin-dynamic-import
MIT License
193 stars 11 forks source link

Aliases not working with astro #25

Closed ShivamJoker closed 2 years ago

ShivamJoker commented 2 years ago

Thanks for the lib

invalid import "import(`@assets/${imageName}-${scale}x.${format}`)". Variable bare imports are not supported, imports must start with ./ in the static part of the import. For example: import(`./foo/${bar}.js`).

Config

import { defineConfig } from "astro/config";
import tailwind from "@astrojs/tailwind";
import sitemap from "@astrojs/sitemap";
import preact from "@astrojs/preact";
import { resolve } from "path";
import { normalizePath } from "vite";
import blurhash from "rollup-plugin-blurhash-as";
import image from "@astrojs/image";
import dynamicImport from "vite-plugin-dynamic-import";
// https://astro.build/config
//

export default defineConfig({
  site: "https://introvert-test.com",
  integrations: [tailwind(), sitemap(), preact()],
  vite: {
    resolve: {
      alias: { "@": normalizePath(resolve(process.cwd(), "./src")) },
    },
    plugins: [
      dynamicImport(),
      {
        ...blurhash(),
        enforce: "pre",
      },
    ],
  },
});
caoxiemeihao commented 2 years ago

Can you provide a minimal reproduce Demo?

caoxiemeihao commented 2 years ago

Ensure the alias of @assets is avaiable.