-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite-plugin-node-stdlib-browser.cjs
61 lines (56 loc) · 1.52 KB
/
vite-plugin-node-stdlib-browser.cjs
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
// https://github.com/sodatea/vite-plugin-node-stdlib-browser
import { createRequire } from 'module'
import inject from '@rollup/plugin-inject'
import stdLibBrowser from 'node-stdlib-browser'
import esbuildPlugin from 'node-stdlib-browser/helpers/esbuild/plugin'
import {
handleCircularDependancyWarning
} from 'node-stdlib-browser/helpers/rollup/plugin'
const require = createRequire(import.meta.url)
const plugin = () => ({
name: 'vite-plugin-node-stdlib-browser',
config: () => ({
resolve: {
alias: stdLibBrowser
},
optimizeDeps: {
include: ['buffer', 'process'],
esbuildOptions: {
inject: [require.resolve('node-stdlib-browser/helpers/esbuild/shim')],
define: {
global: 'global',
process: 'process',
Buffer: 'Buffer'
},
plugins: [esbuildPlugin(stdLibBrowser)]
}
},
plugins: [
{
...inject({
global: [
require.resolve('node-stdlib-browser/helpers/esbuild/shim'),
'global'
],
process: [
require.resolve('node-stdlib-browser/helpers/esbuild/shim'),
'process'
],
Buffer: [
require.resolve('node-stdlib-browser/helpers/esbuild/shim'),
'Buffer'
]
}),
enforce: 'post'
}
],
build: {
rollupOptions: {
onwarn: (warning, rollupWarn) => {
handleCircularDependancyWarning(warning, rollupWarn)
}
}
}
})
})
export default plugin