generated from Tim-W-James/react-ts-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ts
109 lines (105 loc) · 3.26 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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/// <reference types="vitest" />
import react from "@vitejs/plugin-react-swc";
import autoprefixer from "autoprefixer";
import * as path from "path";
import postCssTsClassnames from "postcss-ts-classnames";
import { visualizer } from "rollup-plugin-visualizer";
import tailwind from "tailwindcss";
import AutoImport from "unplugin-auto-import/vite";
import { defineConfig } from "vite";
import sassDts from "vite-plugin-sass-dts";
import tsconfigPaths from "vite-tsconfig-paths";
export default defineConfig(() => {
// Certain processes shouldn't generate CSS types
const enableCssTypeGen = !(process.env.DISABLE_CSS_TYPE_GEN === "true");
return {
// Port must equal port in ./netlify.toml
server: {
port: 3000,
watch: {
ignored: [
"**/cssClasses.d.ts",
"**/*module.scss.d.ts",
"playwright-report",
"storybook-static",
],
},
},
// Define paths relative to the ./public directory here.
// Otherwise, use ./tsconfig.paths.json
resolve: {
alias: {
"@assets": path.resolve(__dirname, "/assets"),
"@images": path.resolve(__dirname, "/assets/images"),
"@pdfs": path.resolve(__dirname, "/assets/pdfs"),
},
},
css: {
postcss: {
plugins: [
tailwind,
autoprefixer,
...(enableCssTypeGen
? [
postCssTsClassnames({
dest: "src/styles/cssClasses.d.ts",
// Set isModule if you want to import ClassNames from another file
isModule: true,
exportAsDefault: true, // to use in combination with isModule
}),
]
: []),
],
},
preprocessorOptions: {
scss: {
// Global SCSS modules
additionalData:
`@use "src/styles/colors.scss" as colors;` +
`@use "src/styles/mixins.scss" as mixins;`,
},
},
},
plugins: [
react(),
AutoImport({
/// Targets to transform
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.md$/, // .md
],
// Global imports to register
imports: [
// presets
"react",
],
// Generate corresponding .eslintrc-auto-import.json file.
// ESLint globals Docs - https://eslint.org/docs/user-guide/configuring/language-options#specifying-globals
eslintrc: {
enabled: true,
filepath: "./.eslintrc-auto-import.json",
globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
},
// Filepath to generate corresponding .d.ts file.
// Defaults to './auto-imports.d.ts' when `typescript` is installed locally.
// Set `false` to disable.
dts: "./types/auto-imports.d.ts",
}),
tsconfigPaths(),
...(enableCssTypeGen ? [sassDts()] : []),
visualizer(),
],
build: {
sourcemap: true,
},
// https://github.com/vitest-dev/vitest
test: {
include: ["src/**/*.test.{ts,tsx}"],
environment: "happy-dom",
globals: true,
setupFiles: ["src/setupTests.ts"],
reporters: ["verbose"],
passWithNoTests: true,
},
};
});