| import path from 'path'; |
| export function NodeGlobalsPolyfillPlugin({ buffer = false, |
| // define = {}, |
| process = true, } = {}) { |
| return { |
| name: 'node-globals-polyfill', |
| setup({ initialOptions, onResolve, onLoad }) { |
| onResolve({ filter: /_node-buffer-polyfill_\.js/ }, (arg) => { |
| return { |
| path: path.resolve(__dirname, '../Buffer.js'), |
| }; |
| }); |
| onResolve({ filter: /_node-process-polyfill_\.js/ }, (arg) => { |
| return { |
| path: path.resolve(__dirname, '../process.js'), |
| }; |
| }); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| onResolve({ filter: /_virtual-process-polyfill_\.js/ }, () => { |
| return { |
| path: path.resolve(__dirname, '../process.js'), |
| }; |
| }); |
| onResolve({ filter: /_virtual-buffer-polyfill_\.js/ }, () => { |
| return { |
| path: path.resolve(__dirname, '../_buffer.js'), |
| }; |
| }); |
| const polyfills = []; |
| if (process) { |
| polyfills.push(path.resolve(__dirname, '../_virtual-process-polyfill_.js')); |
| } |
| if (buffer) { |
| polyfills.push(path.resolve(__dirname, '../_virtual-buffer-polyfill_.js')); |
| } |
| if (initialOptions.inject) { |
| initialOptions.inject.push(...polyfills); |
| |
| initialOptions.inject = [...new Set(initialOptions.inject)]; |
| } |
| else { |
| initialOptions.inject = [...polyfills]; |
| } |
| }, |
| }; |
| } |
| export default NodeGlobalsPolyfillPlugin; |
| |