-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
48 lines (45 loc) · 1.2 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
import { defineConfig } from 'vite';
import reactRefresh from '@vitejs/plugin-react-refresh';
import { ESLint } from 'eslint';
import { format } from 'prettier';
export default defineConfig({
plugins: [reactRefresh()],
build: {
target: 'esnext',
outDir: 'dist',
minify: 'esbuild',
},
server: {
open: true,
},
optimizeDeps: {
include: ['react', 'react-dom'],
},
// Add this to run ESLint and Prettier
esbuild: {
jsxInject: `import React from 'react';`,
jsxFactory: `React.createElement`,
jsxFragment: `React.Fragment`,
define: {
'__DEV__': JSON.stringify(true),
},
},
async onLoad({ filePath, contents }) {
if (/\.[jt]sx?$/.test(filePath)) {
const eslint = new ESLint();
const results = await eslint.lintText(contents, { filePath });
const formatter = await eslint.loadFormatter('stylish');
const resultText = formatter.format(results);
if (resultText) {
console.log(resultText);
}
const formattedCode = format(contents, { filepath: filePath });
if (formattedCode !== contents) {
console.log(`Formatted ${filePath}`);
}
return {
code: formattedCode,
};
}
},
});