forked from weareseeed/react-square-web-payments-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
72 lines (67 loc) · 1.82 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
/// <reference types="vitest" />
// Dependencies
import react from '@vitejs/plugin-react';
import { resolve } from 'path';
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';
// Internals
import { peerDependencies, dependencies } from './package.json';
const externalPackages = [
// We need to build @square/web-sdk with the package to avoid problems with ES Modules in bundlers like Next.js
...Object.keys(dependencies).filter((name) => name !== '@square/web-sdk'),
...Object.keys(peerDependencies),
];
// Creating regexes of the packages to make sure subpaths of the
// packages are also treated as external
const regexesOfPackages = externalPackages.map((packageName) => new RegExp(`^${packageName}(/.*)?`));
export default defineConfig({
build: {
lib: {
entry: resolve(__dirname, 'src', 'index.ts'),
formats: ['cjs', 'es'],
fileName: (ext) => `rswps.${ext}.js`,
},
rollupOptions: {
external: regexesOfPackages,
output: [
{
dir: resolve(__dirname, 'dist'),
entryFileNames: '[name].cjs.js',
exports: 'named',
format: 'cjs',
preserveModules: true,
preserveModulesRoot: 'src',
},
{
dir: resolve(__dirname, 'dist'),
entryFileNames: '[name].es.mjs',
exports: 'named',
format: 'es',
preserveModules: true,
preserveModulesRoot: 'src',
},
],
},
target: 'esnext',
sourcemap: true,
},
plugins: [
react({
jsxRuntime: 'classic',
}),
tsconfigPaths(),
],
resolve: {
alias: {
'~': resolve(__dirname, 'src'),
},
},
test: {
coverage: {
reporter: ['text', 'json', 'html'],
},
environment: 'jsdom',
globals: true,
setupFiles: './jest.setup.ts',
},
});