-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathvite.config.js
88 lines (84 loc) · 2.07 KB
/
vite.config.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import react from "@vitejs/plugin-react";
import { resolve } from "path";
import { defineConfig, transformWithEsbuild } from "vite";
import pkg from "./package.json";
const getName = ({originalFileNames}) => {
// regex matches string after last slash and before the last dot
// e.g. /path/to/file.css -> file
// e.g. /path/to/file.min.css -> file.min
const name = originalFileNames?.at(0)?.match(/\/([^/]*)?\..*$/).at(1) || "[name]";
return name;
}
/** @type {import('vite').UserConfig} */
const c = {
root: resolve(__dirname),
plugins: [
react(),
{
name: "treat-js-files-as-jsx",
async transform(code, id) {
if (!id.match(/stories\/.*\.js$/)) return null;
return transformWithEsbuild(code, id, {
loader: "jsx",
jsx: "automatic",
});
},
},
],
optimizeDeps: {
esbuildOptions: {
target: "es2021",
loader: {
".js": "jsx",
},
},
},
build: {
emptyOutDir: true,
sourcemap: true,
cssMinify: true,
cssCodeSplit: true,
outDir: "dist",
rollupOptions: {
external: [...Object.keys(pkg.peerDependencies), "chart.js"],
treeshake: true,
input: [
resolve(__dirname, "src/scss/unity-bootstrap-theme.bundle.scss"),
resolve(__dirname, "src/scss/unity-bootstrap-theme.scss"),
resolve(__dirname, "src/scss/unity-bootstrap-header-footer.scss"),
],
output: {
globals: {
"chart.js": "Chart",
},
entryFileNames: (info) => `js/${getName(info)}.[format].js`,
chunkFileNames: (info) => `js/${getName(info)}.[format].js`,
assetFileNames: (info) => `css/${getName(info)}.[ext]`,
},
},
},
esbuild: {
loader: "jsx",
include: /.*\.jsx?$/,
exclude: [],
},
css: {
preprocessorOptions: {
scss: {
api: "modern-compiler",
},
},
},
server: {
port: 9000,
},
resolve: {
alias: [
{
find: "@shared",
replacement: resolve(__dirname, "../../shared"),
},
],
},
};
export default defineConfig(c);