-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
47 lines (44 loc) · 1.17 KB
/
vite.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { defineConfig } from "vite";
import reactRefresh from "@vitejs/plugin-react-refresh";
import { each, trimEnd } from "lodash";
import path from "path";
import pathsAliasJson from "./tsconfig.paths.json";
import legacy from "@vitejs/plugin-legacy";
function convertTsPathAlias() {
const pathAlias = {};
each(pathsAliasJson.compilerOptions.paths, (targetPaths, aliasName) => {
each(targetPaths, (targetPath) => {
const matched = targetPath.match(/src(.*)\/\*/);
if (matched[1]) {
// eslint-disable-next-line no-param-reassign
aliasName = trimEnd(aliasName, "/*");
pathAlias[aliasName] = path.join(__dirname, "src", matched[1]);
}
});
});
return pathAlias;
}
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
reactRefresh(),
legacy({
targets: ["ie >= 11"],
additionalLegacyPolyfills: ["regenerator-runtime/runtime"],
}),
],
esbuild: {
jsxInject: `import React from 'react'`,
},
resolve: {
alias: {
...convertTsPathAlias(),
},
},
build: {
target: "es6",
rollupOptions: {
// https://rollupjs.org/guide/en/#big-list-of-options
},
},
});