diff --git a/vite.common-config.js b/vite.common-config.js index b253d1fe..bfade3e2 100644 --- a/vite.common-config.js +++ b/vite.common-config.js @@ -11,6 +11,15 @@ const commonOptions = { server: { hmr: false }, + resolve: { + alias: { + // these should only be imported by the base-x package in any runtime code + // and works in the browser with a Uint8Array shim, + // rather than including a ton of polyfill code + "safe-buffer": "./scripts/package-overrides/safe-buffer/index.js", + "buffer": "./scripts/package-overrides/buffer/index.js", + } + }, build: { emptyOutDir: true, assetsInlineLimit: 0, diff --git a/vite.config.js b/vite.config.js index e11c61d8..b6ec597d 100644 --- a/vite.config.js +++ b/vite.config.js @@ -9,15 +9,6 @@ export default defineConfig(({mode}) => { return mergeOptions(commonOptions, { root: "src/platform/web", base: "./", - resolve: { - alias: { - // these should only be imported by the base-x package in any runtime code - // and works in the browser with a Uint8Array shim, - // rather than including a ton of polyfill code - "safe-buffer": "./scripts/package-overrides/safe-buffer/index.js", - "buffer": "./scripts/package-overrides/buffer/index.js", - } - }, build: { outDir: "../../../target", minify: true, diff --git a/vite.sdk-lib-config.js b/vite.sdk-lib-config.js index bd2250af..c1678d8b 100644 --- a/vite.sdk-lib-config.js +++ b/vite.sdk-lib-config.js @@ -1,16 +1,16 @@ const path = require("path"); const mergeOptions = require('merge-options'); const commonOptions = require("./vite.common-config.js"); -const manifest = require("./package.json") - -// const srcDir = path.join(__dirname, "src/"); -// const modulesDir = path.join(srcDir, "node_modules/"); -// const mocksDir = path.join(srcDir, "mocks/"); -// const fixturesDir = path.join(srcDir, "fixtures/"); +const manifest = require("./package.json"); const externalDependencies = Object.keys(manifest.dependencies) + // just in case for safety in case fake-indexeddb wouldn't be + // treeshake'd out of the bundle .concat(Object.keys(manifest.devDependencies)) - .map(d => path.join(__dirname, "node_modules", d)); + // bundle bs58 because it uses buffer indirectly, which is a pain to bundle, + // so we don't annoy our library users with it. + .filter(d => d !== "bs58"); +const moduleDir = path.join(__dirname, "node_modules"); export default mergeOptions(commonOptions, { root: "src/", @@ -25,15 +25,8 @@ export default mergeOptions(commonOptions, { outDir: "../target/lib-build", // don't bundle any dependencies, they should be imported/required rollupOptions: { - external(id, parentId) { - const isRelativePath = id.startsWith("./") || id.startsWith("../"); - const isModuleIdentifier = !isRelativePath && !id.startsWith("/"); - const resolveId = isRelativePath ? path.join(path.dirname(parentId), id) : id; - const external = isModuleIdentifier || - externalDependencies.some(d => resolveId.startsWith(d)); - // resolveId.startsWith(fixturesDir) || - // resolveId.startsWith(mocksDir); - return external; + external(id) { + return externalDependencies.some(d => id === d || id.startsWith(d + "/")); }, /* don't bundle, so we can override imports per file at build time to replace components */ // output: {