如何使用Vite构建多个bundle,类似于Webpack中的多编译器模式(多配置)?

huangapple go评论76阅读模式
英文:

How to build multiple bundles using Vite similar to Multi Compiler mode(multi config) in Webpack

问题

I have an app which has a main index.html with main.js. But there are also external scripts(libraries) that are injected into index.html programatically from inside main.js. All those scripts(libraries) are built differently because they need different aliases, plugins, loaders, and folder structure.

In webpack we have Multi-compiler-mode where we can export multiple webpack configs in an array and webpack will build all those different entry points accordingly as specified in respective configs.
Is there a way to do this in Vite? (Library mode doesn't seem to be a solution in this case as I need more than just different module types)

英文:

I have an app which has a main index.html with main.js . But there are also external scripts(libraries) that are injected into index.html programatically from inside main.js . All those scripts(libraries) are built differently because they need different aliases ,plugins ,loaders and folder structure .

In webpack we have Multi-compiler-mode where we can export multiple webpack configs in an array and webpack will build all those different entry points accordingly as specified in respective configs .
Is there a way to do this in Vite? (Library mode doesnt seem to be a solution in this case as i need more than just different module types)

答案1

得分: 1

以下是翻译好的部分:

"My guess you can make any number of build configs you like and then just run them in parallel with gnu parallel/xargs/gulp:"
我猜你可以创建任意数量的构建配置,然后使用gnu parallel/xargs/gulp并行运行它们:

"-c, --config <file> Use specified config file (string)"
"-c, --config <file> 使用指定的配置文件(字符串)"

"The command line could look like that:"
命令行可能如下所示:

"In this case you can have several configs like:"
在这种情况下,你可以有多个配置文件,比如:

"There's also option to parameterize 1 vite config file like described here:"
还有一种选项,可以像这里描述的那样参数化一个 vite 配置文件:

以上是翻译好的部分。

英文:

My guess you can make any number of build configs you like and then just run them in parallel with gnu parallel/xargs/gulp:

-c, --config &lt;file&gt;	Use specified config file (string)

https://vitejs.dev/guide/cli.html

The command line could look like that:

find -maxdepth 1 -name vite*.config.*js | xargs -P0 -n1 npx vite build -c

In this case you can have several configs like:

vite.config.mjs
vite.lib.config.js
vite.vendor.config.js

There's also option to parameterize 1 vite config file like described here: https://stackoverflow.com/questions/76517758/how-do-i-completely-disable-chunking-in-vite-and-rollup/76517896#76517896

huangapple
  • 本文由 发表于 2023年5月17日 21:36:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76272727.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定