2022-06-28 14:40:39 +00:00
|
|
|
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 14:27:47 +00:00
|
|
|
if (process.env.VITE_NODE === '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: {
|
2023-05-29 15:11:02 +00:00
|
|
|
entry: [
|
|
|
|
'./src/index.ts',
|
|
|
|
'./src/utils/encode-url-data.ts',
|
|
|
|
'./src/utils/encode-url-hash.ts',
|
|
|
|
],
|
|
|
|
fileName: (format, entryName) => {
|
|
|
|
if (!['es'].includes(format)) {
|
|
|
|
throw new Error(`Unexpected format: ${format}`)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
case 'es':
|
|
|
|
return `${entryName}.js`
|
|
|
|
default:
|
|
|
|
throw new Error(`Undefined format: ${format}`)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
formats: ['es'],
|
2022-06-28 14:40:39 +00:00
|
|
|
},
|
2022-06-28 14:54:21 +00:00
|
|
|
sourcemap: true,
|
|
|
|
emptyOutDir: mode === 'production',
|
2022-06-28 14:40:39 +00:00
|
|
|
rollupOptions: {
|
2023-03-21 10:05:59 +00:00
|
|
|
external: [...external, 'zlib'],
|
2022-06-28 14:40:39 +00:00
|
|
|
},
|
|
|
|
},
|
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
|
|
|
},
|
|
|
|
}
|
|
|
|
})
|