[vite] Internal server error: Failed to parse source for import analysis because the content contains invalid JS syntax. You may need to install appropriate plugins to handle the .md file format, or if it's an asset, add "**/*.md" to assetsInclude
in your configuration.
import { defineConfig, type Plugin } from "vite"
import vue from "@vitejs/plugin-vue"
import type { TransformResult } from "rollup"
import { VitePWA } from "vite-plugin-pwa"
import mdLoader from "vite-plugin-md-loader"
import { readFileSync } from "fs"
import { resolve } from "path"
const fileRegex = /\.(md)$/
function myPlugin() {
return {
name: "my-plugin",
enforce: "pre",
transform(code, src): TransformResult {
if (fileRegex.test(src)) {
console.log("src=", src)
console.log("code=", code)
return {
code: readFileSync(src, "utf8"),
map: null,
}
}
},
handleHotUpdate(ctx) {
if (fileRegex.test(ctx.file)) {
const defaultRead = ctx.read
console.log("defaultRead=", defaultRead)
}
},
} as Plugin
}
export default defineConfig({
server: {
port: 3333,
},
define: {
_VUE_OPTIONS_API_: JSON.stringify(false),
},
assetsInclude: ["icon.png", "articles/*.md"],
build: {
cssCodeSplit: false,
chunkSizeWarningLimit: 1024,
// rollupOptions: {
// output: {
// manualChunks(id) {
// if (id.includes("node_modules")) {
// return id.toString().split("node_modules/")[1].split("/")[0].toString()
// }
// },
// },
// },
},
// server: {
// port: 3333,
// proxy: {
// "/Api/": "https://fuyouplus.cn",
// },
// },
plugins: [
vue({
template: {
compilerOptions: {
// 将所有包含短横线的标签作为自定义元素处理
// isCustomElement: tag => tag.includes("my-"),
},
},
}),
// mdLoader({ defaultImport: "raw" }),
myPlugin(),
VitePWA({
registerType: "autoUpdate",
devOptions: {
enabled: true,
},
manifest: {
icons: [
{
src: "/assets/icon-f111d216.png",
sizes: "200x200",
type: "image/png",
},
],
},
}),
],
css: {
preprocessorOptions: {
scss: {
additionalData: `@import "@/styles/index.module.scss";`, //全局混入scss
},
},
},
resolve: {
extensions: [".js", ".ts", ".tsx", ".jsx"],
alias: [
//配置路径别名
{ find: "@", replacement: resolve(__dirname, "src") },
{ find: "@cop", replacement: resolve(__dirname, "src/components") },
{ find: "@api", replacement: resolve(__dirname, "src/api") },
],
},
})
i want export markdown file content