首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >esbuild构建不绑定公共目录。

esbuild构建不绑定公共目录。
EN

Stack Overflow用户
提问于 2022-09-20 10:59:29
回答 1查看 399关注 0票数 2

我决定使用esbuild捆绑我的快递API。到目前为止,除了包含public UI的swagger目录没有绑定到应用程序的其余部分之外,一切都很好。我有一个端点定义为服务于该文件夹的静态路由。

代码语言:javascript
复制
app.use(express.static(`${root}/public`));

为了克服这个问题,我尝试了多种方法,例如手动将public directory复制到build dir位置。这似乎行不通。我也尝试过插件esbuild-plugin-public-directory,它也没有工作。

然后,我将public/index.html添加到entryPoints配置中,这也不起作用。

我现在的问题是,我做错了什么?在互联网上,我似乎没有发现任何特别有用的东西来帮助我克服这个问题。

这是我目前正在使用的esbuild。

代码语言:javascript
复制
const publicDir = require("esbuild-plugin-public-directory");

const OUTDIR = "build";

const envPlugin = {
    name: "env",
    setup(build) {
        // Intercept import paths called "env" so esbuild doesn't attempt
        // to map them to a file system location. Tag them with the "env-ns"
        // namespace to reserve them for this plugin.
        build.onResolve({ filter: /^env$/ }, (args) => ({
            path: args.path,
            namespace: "env-ns",
        }));

        // Load paths tagged with the "env-ns" namespace and behave as if
        // they point to a JSON file containing the environment variables.
        build.onLoad({ filter: /.*/, namespace: "env-ns" }, () => ({
            contents: JSON.stringify(process.env),
            loader: "json",
        }));
    },
};

require("esbuild")
    .build({
        entryPoints: ["server/start.ts", "public/index.html"],
        platform: "node",
        bundle: true,
        minify: false,
        platform: "node",
        logLevel: "info",
        sourcemap: false,
        target: "node12",
        loader: {
            '.html': 'text',
        },
        outdir: "build",
        plugins: [envPlugin, publicDir()],
    })
    .then(() => {
        fs.copyFileSync("server/common/api.yml", `${OUTDIR}/api.yml`);
        console.log(`Successfully built, output directed to the ${OUTDIR} directory`);
    })
    .catch(() => process.exit(1));
EN

回答 1

Stack Overflow用户

发布于 2022-09-23 14:00:49

如果使用@fastify/swagger的话,我试过了。只需将@fastify/swagger放在esbuild build.external中即可。

代码语言:javascript
复制
buid({external: ["esnext", "@fastify/swagger"],})

否则的话,你可能会摆出一副自以为是的样子。参考资料:https://docs.devland.is/repository/openapi#configuring-swaggerui-dependencies-for-esbuild

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73785604

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档