-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.cjs
69 lines (64 loc) · 1.82 KB
/
index.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
62
63
64
65
66
67
68
69
const inject = require('@rollup/plugin-inject')
const stdLibBrowser = require('node-stdlib-browser')
const esbuildPlugin = require('node-stdlib-browser/helpers/esbuild/plugin')
const {
handleCircularDependancyWarning
} = require('node-stdlib-browser/helpers/rollup/plugin')
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),
// https://github.com/remorses/esbuild-plugins/issues/24#issuecomment-1369928859
{
name: 'fix-node-stdlib-browser-shim',
setup (build) {
build.onResolve(
{ filter: /node-stdlib-browser\/helpers\/esbuild\/shim/ },
({ path }) => ({ path })
)
}
}
]
}
},
build: {
rollupOptions: {
onwarn: (warning, rollupWarn) => {
handleCircularDependancyWarning(warning, rollupWarn)
},
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'
]
})
}
]
}
}
})
})
module.exports = plugin