2022-06-28 14:40:39 +00:00
|
|
|
/// <reference types="vitest" />
|
|
|
|
|
|
|
|
import { defineConfig } from 'vite'
|
|
|
|
|
|
|
|
import { dependencies } from './package.json'
|
|
|
|
|
2022-07-19 15:45:29 +00:00
|
|
|
import type { Alias } from 'vite'
|
|
|
|
|
2022-06-28 14:40:39 +00:00
|
|
|
const external = [
|
|
|
|
...Object.keys(dependencies || {}),
|
|
|
|
// ...Object.keys(peerDependencies || {}),
|
|
|
|
].map(name => new RegExp(`^${name}(/.*)?`))
|
|
|
|
|
2022-06-28 14:54:21 +00:00
|
|
|
export default defineConfig(({ mode }) => {
|
2022-07-19 15:45:29 +00:00
|
|
|
const alias: Alias[] = []
|
|
|
|
|
2022-09-16 13:49:20 +00:00
|
|
|
if (process.env.VITEST === 'true' || mode === 'test') {
|
2022-07-19 15:45:29 +00:00
|
|
|
alias.push({
|
|
|
|
/**
|
|
|
|
* Note: `happy-dom` nor `jsdom` have Crypto implemented (@see https://github.com/jsdom/jsdom/issues/1612)
|
|
|
|
*/
|
|
|
|
find: /^.*\/crypto\/pbkdf2.browser$/,
|
|
|
|
replacement: 'ethereum-cryptography/pbkdf2',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-06-28 14:40:39 +00:00
|
|
|
return {
|
|
|
|
build: {
|
2022-06-28 14:54:21 +00:00
|
|
|
target: 'es2020',
|
2022-06-28 14:40:39 +00:00
|
|
|
lib: {
|
|
|
|
entry: './src/index.ts',
|
|
|
|
fileName: 'index',
|
|
|
|
formats: ['es'],
|
|
|
|
},
|
2022-06-28 14:54:21 +00:00
|
|
|
sourcemap: true,
|
|
|
|
emptyOutDir: mode === 'production',
|
2022-06-28 14:40:39 +00:00
|
|
|
rollupOptions: {
|
|
|
|
external,
|
|
|
|
},
|
|
|
|
},
|
2022-07-19 15:45:29 +00:00
|
|
|
resolve: {
|
|
|
|
alias,
|
|
|
|
},
|
2022-06-28 14:40:39 +00:00
|
|
|
test: {
|
2022-07-19 15:45:29 +00:00
|
|
|
environment: 'happy-dom',
|
2022-06-28 14:40:39 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
})
|