[英]Can I have multiple babel.config.js in a monorepo?
I have a monorepo with the structure like below我有一个结构如下的 monorepo
babel.config.js
packages/
|---mobile/
|----package.json
|----src/index.js
|---desktop/
|----package.json
|----src/index.js
|---server/
|----package.json
|----src/index.js
So my babel
configuration for mobile
and desktop
packages are same, whereas configuration for server
package is different.所以我的
mobile
和desktop
包的babel
配置是相同的,而server
包的配置是不同的。
Now, how can I have that configuration done?现在,我该如何完成该配置? One solution, that I can think of is that to have a
babel.config.js
at the root of monorepo which would have configurations for mobile
and desktop
packages and a separate configuration for server
package in a babel.config.js
at server
package level.我能想到的一种解决方案是,在
babel.config.js
的根目录下有一个babel.config.js
,它可以配置mobile
和desktop
包,并在server
包级别的babel.config.js
中为server
包单独配置. I am not sure, can we even have multiple babel.config.js
.我不确定,我们甚至可以有多个
babel.config.js
。
Yes, you can achieve what you asked by having multiple config files.是的,您可以通过拥有多个配置文件来实现您的要求。 It is mentioned as File-relative configuration in babel documentation.
它在 babel 文档中被称为文件相关配置。
Create a .babelrc or .babelrc.js file in each of your directories (mobile, desktop, server)在您的每个目录(移动、桌面、服务器)中创建一个 .babelrc 或 .babelrc.js 文件
For more details look at https://babeljs.io/docs/en/next/config-files有关更多详细信息,请查看https://babeljs.io/docs/en/next/config-files
Personally, I think using separate files would lead to confusion.就个人而言,我认为使用单独的文件会导致混淆。 Assuming you've set up your system in a way that works already and you're just asking how to specify different configs for different locations, you can use the
"overrides"
option.假设您已经以一种已经可以工作的方式设置了系统,并且您只是询问如何为不同的位置指定不同的配置,您可以使用
"overrides"
选项。 For example, your config can do例如,你的配置可以做
module.exports = {
overrides: [{
test: [
'./desktop',
'./mobile',
],
// put all your normal babel options for these folders here
}, {
test: [
'./server',
],
// put all your normal babel options for the server here
}],
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.