简体   繁体   English

我可以在一个 monorepo 中有多个 babel.config.js 吗?

[英]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.所以我的mobiledesktop包的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 ,它可以配置mobiledesktop包,并在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.

相关问题 Babel.config.js 仅用于开玩笑 - Babel.config.js only for jest 让 Nextjs 忽略 babel.config.js - Make Nextjs to ignore babel.config.js 如何将 @babel/preset-react 添加到 babel.config.js 的预设部分 - How do I add @babel/preset-react to the presets section of babel.config.js Lint 解析错误:找不到模块“babel.config.js” - Lint Parsing error: Cannot find module 'babel.config.js' Expo react native 不使用 babel.config.js 中定义的插件 - Expo react native not using plugin defined in babel.config.js api.cache(true)在Expo的babel.config.js中做什么? - What does api.cache(true) do in Expo's babel.config.js? 尝试在 nextjs 应用程序中添加 `babel.config.js` 时出现`Cannot find module '.next\server\pages-manifest.json'` 错误 - Getting `Cannot find module '.next\server\pages-manifest.json'` error when trying to add `babel.config.js` in nextjs app 在 babel.config.js 中包含 node_modules 时,当前未启用对实验语法 'jsx' 的支持 - Support for the experimental syntax 'jsx' isn't currently enabled when including node_modules in babel.config.js Babel 配置文件在 Lerna monorepo 中不起作用 - Babel config file not working in Lerna monorepo 为什么我必须将babel-presets放在.babelrc和webpack.config.js中? - why do I have to put babel-presets inside .babelrc and webpack.config.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM