1 Star 0 Fork 0

Apple_Sun/turns-data

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
vite.config.ts 2.52 KB
Copy Edit Raw Blame History
Apple Sun authored 2024-03-26 17:25 . chore: init
import { ConfigEnv, defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import tailwind from "tailwindcss";
import autoprefixer from "autoprefixer";
import path, { resolve, dirname } from "path";
import { fileURLToPath } from "url";
import VueI18nPlugin from "@intlify/unplugin-vue-i18n/vite";
import Components from "unplugin-vue-components/vite";
import Icons from "unplugin-icons/vite";
import IconsResolver from "unplugin-icons/resolver";
import { FileSystemIconLoader } from "unplugin-icons/loaders";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import { getSrcPath } from "./src/utils";
// https://vitejs.dev/config/
export default ({ command, mode }: ConfigEnv) => {
const root = process.cwd();
const env = loadEnv(mode, root);
const VITE_ICON_PREFIX = "icon";
const VITE_ICON_LOCAL_PREFIX = "icon-local";
const srcPath = getSrcPath();
const localIconPath = `${srcPath}/assets/svg-icon`;
/** 本地svg图标集合名称 */
const collectionName = VITE_ICON_LOCAL_PREFIX.replace(
`${VITE_ICON_PREFIX}-`,
""
);
console.log(`build mode: ${mode}`, env);
return defineConfig({
root,
base: "/",
publicDir: "public",
css: {
postcss: {
plugins: [tailwind(), autoprefixer()],
},
},
plugins: [
vue(),
VueI18nPlugin({
include: resolve(
dirname(fileURLToPath(import.meta.url)),
"./src/locales/**"
),
fullInstall: false,
compositionOnly: true,
}),
Icons({
compiler: "vue3",
customCollections: {
[collectionName]: FileSystemIconLoader(localIconPath, (svg) =>
svg.replace(/^<svg\s/, '<svg width="1em" height="1em" ')
),
},
scale: 1,
defaultClass: "inline-block",
}),
Components({
dts: "src/typings/components.d.ts",
types: [{ from: "vue-router", names: ["RouterLink", "RouterView"] }],
resolvers: [
IconsResolver({
customCollections: [collectionName],
componentPrefix: VITE_ICON_PREFIX,
}),
],
}),
createSvgIconsPlugin({
iconDirs: [localIconPath],
symbolId: `${VITE_ICON_LOCAL_PREFIX}-[dir]-[name]`,
inject: "body-last",
customDomId: "__SVG_ICON_LOCAL__",
}),
],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
build: {
target: mode === "development" ? "modules" : "es2015",
sourcemap: mode === "development",
},
});
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ues/turns-data.git
git@gitee.com:ues/turns-data.git
ues
turns-data
turns-data
master

Search