Repository navigation
Expand file tree
/
Copy pathvite.config.js
More file actions
46 lines (43 loc) · 1.65 KB
/
Copy pathvite.config.js
File metadata and controls
46 lines (43 loc) · 1.65 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
import path from 'path';
import { fileURLToPath } from 'url';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
const projectRoot = path.dirname(fileURLToPath(import.meta.url));
const escapeRegExp = (string) => string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
// Anchored to the project's own src/ so that node_modules/**/src/*.js
// never matches. Vite module ids always use forward slashes, even on
// Windows: normalize the root the same way before building the regex.
const srcJsRE = new RegExp(`^${escapeRegExp(projectRoot.split(path.sep).join('/'))}/src/.*\\.js$`);
// The demo (src/docs) and the published library (src/lib) both use JSX inside
// plain .js files. Renaming the src/lib files is not an option (they are
// published as-is by `dist:js`), so esbuild is told to parse every src/*.js
// file with the JSX loader instead.
export default defineConfig({
// GH Pages serves the demo under /react-jsonschema-form-validation/
// (parity with the CRA "homepage" field). Routing itself uses HashRouter,
// only asset URLs are affected.
base: '/react-jsonschema-form-validation/',
plugins: [
// react 16.12 predates react/jsx-runtime -> classic runtime.
react({ jsxRuntime: 'classic' }),
],
esbuild: {
loader: 'jsx',
include: srcJsRE,
// Vite's esbuild plugin excludes .js files by default; the default
// exclude wins over include, so it must be reset explicitly.
exclude: [],
},
optimizeDeps: {
esbuildOptions: {
loader: {
'.js': 'jsx',
},
},
},
build: {
// Demo output, uploaded to GitHub Pages by .github/workflows/pages.yml.
// Not to be confused with dist/ (npm package build).
outDir: 'build',
},
});