esbuild不捆绑文件 [英] esbuild not bundling files

查看:105
本文介绍了esbuild不捆绑文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用esbuild捆绑并缩小npm项目中的文件.它可以最大程度地减少我传递的每个文件,但不会捆绑在一起.它给我一个错误,当有多个文件时,我必须使用"outdir".但是,这使我将所有这些文件(最小化)放回到一个文件夹中.这不是我想要的行为,并且不捆绑.我只希望它接收所有这些文件并将它们合并为一个文件.

I am trying to use esbuild to bundle and minify my files in an npm project. It is minimizing every file that I pass in, but it is not bundling. It gives me the error that I must use 'outdir' when there are multiple files. However, this gives me back all of those files, minimized, in a folder. This is not the behavior that I want and is not bundling. I just want it to take all of those files and merge them into one.

let {build} = require("esbuild");
let files = ["file1.js", "file2.js"];

build({
    entryPoints: files,
    outdir: "./views/dashboardPage/bundle",
    minify: true,
    bundle: true
}).catch(() => process.exit(1));

我已将bundle设置为true,但仍然要求我使用outdir,它只会将这些文件返回给我,并最小化.他们对此基本上有0个文档,并且每个与此有关的在线帖子都只是从GitHub复制/粘贴自述文件.我该如何捆绑它?

I have bundle set to true, but it still demands that I use outdir and it just returns those files to me, minimized. They have basically 0 documentation on this and every post online about it has just copy/pasted the README from the GitHub. How can I make it bundle?

推荐答案

每个入口点文件将成为一个单独的包.每个捆绑软件都包括入口点文件及其导入的所有文件.传递两个入口点将创建两个单独的捆绑包.捆绑过程与文件串联不同.

Each entry point file will become a separate bundle. Each bundle includes the entry point file and all files it imports. Passing two entry points will create two separate bundles. The bundling process is not the same thing as file concatenation.

如果要将所有文件放在一个捆绑包中,则可以从单个文件中引用所有文件,并将该文件用作入口点:

If you want all of the files in a single bundle, you can reference them all from a single file and use that file as the entry point:

import "./file1.js"
import "./file2.js"

使用esbuild进行操作可能如下所示:

Doing that with esbuild could look something like this:

let {build} = require("esbuild");
let files = ["./file1.js", "./file2.js"];

build({
    stdin: { contents: files.map(f => `import "${f}"`).join('\n') },
    outfile: "./views/dashboardPage/bundle.js",
    minify: true,
    bundle: true
}).catch(() => process.exit(1));

这篇关于esbuild不捆绑文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆