const config = require("./esbuild.config.js")
const svelteConfig = require("./svelte.config")

config.options.sourcemap = "inline"
config.options.minify = false
config.options.platform = "node"
config.options.format = "cjs"
// es2015 will transform async/await to generators, but not working with svelte
// so we need babel to transform async/await to promises
// config.options.target = "es2015"
config.options.entryPoints = ["./frontend/src/ssr.ts"]
config.options.outfile = __dirname + "/_temp/app.server.js"
config.options.plugins = [
    config.sveltePlugin({
        compilerOptions: {
            generate: "server",
            css: "external",
            dev: (process.argv?.length > 2 ? process.argv[2] : "build") !== "build",
        },
        preprocess: svelteConfig.preprocess,
        filterWarnings: (warning) => {
            // filter out a11y
            if (warning.code.match(/^a11y/)) return false
            return true
        },
    }),
    config.resolvePlugin,
]

module.exports = config
