-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
111 lines (104 loc) · 3.06 KB
/
vite.config.ts
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/// <reference types="vitest" />
import path from 'path';
import react from '@vitejs/plugin-react';
import { exec } from 'node:child_process';
import { defineConfig, loadEnv, PluginOption } from 'vite';
import dts from 'vite-plugin-dts';
import svgr from 'vite-plugin-svgr';
import tsconfigPaths from 'vite-tsconfig-paths';
import { configDefaults, coverageConfigDefaults } from 'vitest/config';
// @ts-ignore
import pkg from './package.json';
const regexesOfPackages = (externalPackages = []) =>
externalPackages.map((packageName) => new RegExp(`^${packageName}(/.*)?`));
const viteOnBuildSuccess = (): PluginOption => {
return {
name: 'vite:on-build-success',
apply: 'build',
buildEnd: async () => {
exec('yarn yalc:push --no-scripts', (_, output, err) => {
if (output) console.log(output);
if (err) console.log(err);
});
},
};
};
const plugins = [
react({
babel: {},
}),
tsconfigPaths(),
svgr(),
dts({
// eslint-disable-next-line @typescript-eslint/naming-convention
insertTypesEntry: true,
exclude: ['__mocks__'],
}),
];
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
// Load env file based on `mode` in the current working directory.
// Set the third parameter to '' to load all env regardless of the `REACT_APP_` prefix.
const env = loadEnv(mode, process.cwd(), '');
console.log(mode);
return {
// eslint-disable-next-line @typescript-eslint/naming-convention
publicDir: false,
envPrefix: 'REACT_APP_',
// Define these to keep compatibility with ictinus, toolbox and SSO
define: {
'process.env.NODE_ENV': JSON.stringify(mode),
'process.env.STORYBOOK_ENV': JSON.stringify(env.STORYBOOK_ENV),
'process.env.PORT': JSON.stringify(env.PORT),
},
plugins: mode === 'watch' ? [...plugins, viteOnBuildSuccess()] : plugins,
build: {
watch:
mode === 'watch'
? {
include: 'src/**',
}
: null,
lib: {
entry: path.resolve(__dirname, 'src/index.ts'),
name: pkg.name,
// the proper extensions will be added
fileName: 'index',
},
minify: 'esbuild',
outDir: 'dist',
rollupOptions: {
external: [
'react',
'react/jsx-runtime',
'react-dom',
/@emotion\/styled/,
/@emotion\/react/,
...regexesOfPackages([
'__mocks__',
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
]),
],
},
},
test: {
// eslint-disable-next-line @typescript-eslint/naming-convention
globals: true,
environment: 'jsdom',
setupFiles: './src/testing/setupTest.ts',
coverage: {
provider: 'v8', // or 'istanbul'
exclude: [
...coverageConfigDefaults.exclude,
'**/*.styles.ts',
'**/styles.ts',
'**/__mocks__/',
'src/config/',
'src/test/',
],
},
exclude: [...configDefaults.exclude],
},
};
});