I'm writing a storage adapter for Ghost using the @aws-sdk/client-s3
. I want the adapter to be self-contained, so I'm trying to use esbuild to bundle it all into a single file. To build a storage adapter, you have to extend the BaseStorageAdapter
class, which is available in Ghost, so I don't want to bundle that. However, esbuild
outputs a different file depending on the syntax I use to import it, and I can't get it to generate the output I want.
The command I'm using is npx esbuild src/index.ts --external:ghost-storage-base --bundle --platform=node
. Depending on the way I import ghost-storage-base
, it generates the following output:
import StorageBase from "ghost-storage-base"
generates a 1.2KB file which seems to contain only some boilerplate and the statement "var import_ghost_storage_base = __toESM(require("ghost-storage-base"))
"var StorageBase = require("ghost-storage-base")
outputs the statement "var StorageBase = require("ghost-storage-base")
and nothing else.My tsconfig.json
is currently quite basic:
{
"include": [
"src/**/*"
],
}
Am I calling esbuild wrong? Is there a TypeScript configuration option I'm missing? Or is it something else?
The problem was that I forgot to export the class I declared. I just added
module.exports = MyClass
to the bottom of the file, and it worked perfectly.
export MyClass
also worked.