-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathvite.config.js
More file actions
82 lines (78 loc) · 2.12 KB
/
Copy pathvite.config.js
File metadata and controls
82 lines (78 loc) · 2.12 KB
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
import fs from 'node:fs';
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import svgr from 'vite-plugin-svgr';
import * as esbuild from 'esbuild';
const SourceJSPattern = /\/src\/.*\.js$/;
// this plugin will force Vite to look for JSX in all .js files while building the production
// bundler, so we don't have to rename every single file
const rollupPlugin = (matchers) => ({
name: 'js-in-jsx',
load(id) {
if (matchers.some((matcher) => matcher.test(id))) {
const file = fs.readFileSync(id, { encoding: 'utf-8' });
return esbuild.transformSync(file, { loader: 'jsx' });
}
},
});
// proxy these routes to the server running on port 4000. this takes the place
// of setupProxy.js in webpack.
const proxy = ['/api', '/auth', '/libraries', '/wss'].reduce(
(result, route) => ({
...result,
[route]: {
target: 'http://localhost:4000',
changeOrigin: true,
ws: true,
},
}),
{}
);
export default defineConfig({
server: {
// vite defaults to an unused port, so force it to 3000
port: 3000,
// if port 3000 is being used, then quit (though it's not clear this actually works)
strict: true,
// no idea why this is necessary, but without it, the Vite dev server isn't reachable
// from a browser on the host machine
host: true,
proxy,
},
plugins: [
// raw SVG icons are imported in some places, so add a plugin so they get
// wrapped in a React component like in webpack
svgr(),
react(),
],
build: {
outDir: 'build',
rollupOptions: {
plugins: [
rollupPlugin([SourceJSPattern])
],
},
commonjsOptions: {
transformMixedEsModules: true,
},
},
optimizeDeps: {
include: [
'uswds',
'shared/constants',
'shared/metadata'
],
esbuildOptions: {
loader: {
'.js': 'jsx',
},
},
},
esbuild: {
// point the JSX parser at all .js files, so we don't have to rename them all to .jsx
loader: 'jsx',
include: [SourceJSPattern],
// we have to explicitly include this empty exclude key, for some reason
exclude: [],
},
});