Closed brianjenkins94 closed 1 year ago
This looks to have done it:
rollup.config.js
import alias from "@rollup/plugin-alias";
import commonJs from "@rollup/plugin-commonjs";
import inject from "@rollup/plugin-inject";
import nodeResolve from "@rollup/plugin-node-resolve";
import typescript from "rollup-plugin-typescript2";
export default {
"input": "docs/js/main.ts",
"output": {
"file": "docs/js/main.js",
"format": "esm"
},
"external": [],
"plugins": [
alias({
"entries": [
{ "find": "buffer", "replacement": "browserfs/dist/shims/buffer" },
{ "find": "fs", "replacement": "browserfs/dist/shims/fs" },
{ "find": "path", "replacement": "browserfs/dist/shims/path" }
]
}),
nodeResolve({ "preferBuiltins": false }),
commonJs(),
typescript(),
inject({
"BrowserFS": "browserfs"
})
],
"watch": {
"clearScreen": false
}
};
main.ts
declare const BrowserFS;
import * as buffer from "buffer";
import * as fs from "fs";
import * as path from "path";
BrowserFS.configure({ "fs": "IndexedDB", "options": {} }, function(error) {
if (error) {
throw new Error(error.toString());
}
});
Instructions in the README for usage with Rollup would be greatly appreciated. Here's as far as I got:
rollup.config.js:
main.ts:
Can't seem to get past this issue:
Since the commonJs plugin (?) is renaming the BrowserFS import:
Seems similar to: https://github.com/jvilk/BrowserFS/issues/201