forked from CDCgov/cdc-open-viz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateViteConfig.js
61 lines (56 loc) · 1.67 KB
/
generateViteConfig.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
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'
import svgr from 'vite-plugin-svgr' // Svg Support
import dsv from '@rollup/plugin-dsv' // CSV Support
import dns from 'dns' // nodeJS
import * as path from 'path'
// Force load dev server on `localhost` vs 127.0.0.1
dns.setDefaultResultOrder('verbatim')
// DEV NOTE: Modifications made to this file will not be hot-loaded through HMR for component.
// - Active dev servers ('lerna run start') must be restarted in order to view the changed settings.
const generateViteConfig = (componentName, configOptions = {}, reactOptions = {}) => {
let configOptionsDefault = {
server: { port: 8080 },
build: {
commonjsOptions: {
include: [/@cdc\/core/, /node_modules/]
},
sourcemap: false,
lib: {
entry: `src/${componentName}`,
formats: ['es'],
fileName: format => `${componentName.toLowerCase()}.js`
},
rollupOptions: {
external: ['react', 'reactDOM'],
output: {
chunkFileNames: `${componentName.toLowerCase()}-[hash].[format].js`,
globals: {
react: 'React',
reactDOM: 'ReactDOM'
}
}
}
},
plugins: [
react(reactOptions),
svgr({
exportAsDefault: true
}),
cssInjectedByJsPlugin(),
dsv()
],
test: {
globals: true,
environment: 'jsdom',
setupFiles: path.resolve(__dirname, 'testing-setup.js')
},
...configOptions
}
return defineConfig({
...configOptionsDefault,
...configOptions
})
}
export default generateViteConfig