-
Notifications
You must be signed in to change notification settings - Fork 255
/
vite.config.js
95 lines (94 loc) · 2.65 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
89
90
91
92
93
94
95
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import fs from 'fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'url';
import { globSync } from 'glob';
import * as packageJson from './package.json';
/**
* Vite configuration
*/
export default defineConfig({
...(
process.env.NETLIFY ? {
build: {
rollupOptions: {
external: ['__tests__/*', '__mocks__/*'],
input: Object.fromEntries(
globSync('./__tests__/integration/mirador/*.html').map((file) => [
// This remove `src/` as well as the file extension from each
// file, so e.g. src/nested/foo.js becomes nested/foo
path.relative(
'__tests__/integration/mirador',
file.slice(0, file.length - path.extname(file).length),
),
// This expands the relative paths to absolute paths, so e.g.
// src/nested/foo becomes /project/src/nested/foo.js
fileURLToPath(new URL(file, import.meta.url)),
]),
),
},
sourcemap: true,
},
} : {
build: {
lib: {
entry: './src/index.js',
fileName: (format) => (format === 'umd' ? 'mirador.js' : 'mirador.es.js'),
formats: ['es', 'umd'],
name: 'Mirador',
},
rollupOptions: {
external: [
...Object.keys(packageJson.peerDependencies),
'react/jsx-runtime',
'__tests__/*',
'__mocks__/*',
],
output: {
assetFileNames: 'mirador.[ext]',
globals: {
react: 'React',
'react-dom': 'ReactDOM',
'react/jsx-runtime': 'react/jsx-runtime',
},
},
},
sourcemap: true,
},
}
),
esbuild: {
exclude: [],
// Matches .js and .jsx in __tests__ and .jsx in src
include: [/__tests__\/.*\.(js|jsx)$/, /src\/.*\.jsx?$/],
loader: 'jsx',
},
optimizeDeps: {
esbuildOptions: {
plugins: [
{
name: 'load-js-files-as-jsx',
// TODO: rename all our files to .jsx ...
/** */
setup(build) {
build.onLoad({ filter: /(src|__tests__)\/.*\.js$/ }, async (args) => ({
contents: await fs.readFile(args.path, 'utf8'),
loader: 'jsx',
}));
},
},
],
},
},
plugins: [react()],
resolve: {
alias: {
'@tests/': fileURLToPath(new URL('./__tests__', import.meta.url)),
},
},
server: {
open: '/__tests__/integration/mirador/index.html',
port: '4444',
},
});