Repository navigation
Replies: 1 comment
|
For a browser-only Rollup bundle, a small resolver can do the same: // rollup.config.mjs
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
const ignored = new Set(['fs', 'path', 'crypto']);
const prefix = '\0empty-node:';
export default {
input: 'src/main.js',
output: { file: 'dist/bundle.js', format: 'iife', name: 'App' },
plugins: [
{
name: 'browser-empty-node-builtins',
resolveId(id) {
if (ignored.has(id)) return prefix + id + '.cjs';
},
load(id) {
if (id.startsWith(prefix)) return 'module.exports = {};';
}
},
nodeResolve({ browser: true }),
commonjs()
]
};Keep the empty-module resolver before I tested this with That runtime check was in a Node VM with browser-like globals, not a real browser or your full app. This is specifically a browser-build workaround: don't use it for a Node target or code that actually needs References: OpenCV's webpack configuration, node-resolve browser and builtin behavior. |
Uh oh!
There was an error while loading. Please reload this page.
I'm trying to include npm @techstark/opencv-js in my web app.
The github site for this package recommended this webpack config:
module.exports = {
resolve: {
modules: [...],
fallback: {
fs: false,
path: false,
crypto: false
}
}
};
But my app is using rollup and I don't know how to translate this into rollup config.
I have attempted to out at the top of my rollup.config file:
import nodePolyfills from 'rollup-plugin-node-polyfills'; errors during build
and in the plugins array include:
nodePolyfills()
but that errors
Help greatly appreciated.
All reactions