英文:
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 <file> 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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论