简体   繁体   English

Yarn Workspaces,工作区不发出错误或警告

[英]Yarn Workspaces, workspace does not emit errors or warnings

I have followed the following post in order to create a monorepo using yarn workspaces and craco.为了使用 yarn workspaces 和 craco 创建一个 monorepo,我遵循了以下帖子 It works really well except one thing: the errors/warnings of the common (components )library are not emitted to the console.它工作得很好,除了一件事:公共(组件)库的错误/警告不会发送到控制台。 The structure is very simple:结构非常简单:

monorepo
|-packages
  |-components
  |-fe

Fe is the main webApp that uses the components library. Fe 是使用组件库的主要 webApp。 The FE emits all warnings correctly, components does not. FE 正确发出所有警告,组件没有。

How to make the shared component emit warnings/errors?如何让共享组件发出警告/错误?

Updated:更新:

Steps to reproduce in this repo: https://github.com/sofoklisM/my-monorepo.git在此 repo 中重现的步骤: https://github.com/sofoklisM/my-monorepo.git

What you need to change is the context option of the underlying ESLint Webpack plugin that is used by Create React App.您需要更改的是 Create React App 使用的底层 ESLint Webpack 插件context选项 In this case I changed the context of ESLint to the root of the monorepo (yarn workspace root).在这种情况下,我将 ESLint 的上下文更改为 monorepo 的根(纱线工作区根)。

Here is an updated craco.config.js that should do the trick:这是一个更新的craco.config.js应该可以解决问题:

// craco.config.js
const path = require("path");
const { getLoader, loaderByName } = require("@craco/craco");
const { getPlugin, pluginByName } = require("@craco/craco/lib/webpack-plugins")
const absolutePath = path.join(__dirname, "../components");
module.exports = {
  webpack: {
    alias: {},
    plugins: [],
    configure: (webpackConfig, { env, paths }) => {
      const { isFound, match } = getLoader(
        webpackConfig,
        loaderByName("babel-loader")
      );
      if (isFound) {
        const include = Array.isArray(match.loader.include)
          ? match.loader.include
          : [match.loader.include];
        match.loader.include = include.concat([absolutePath]);
      }

      // Change context of ESLint Webpack Plugin
      const { match: eslintPlugin } = getPlugin(webpackConfig, pluginByName("ESLintWebpackPlugin"));
      eslintPlugin.options['context'] = path.join(__dirname, "../..");

      return webpackConfig;
    }
  }
};

I've also made an updated fork of your reproduction repo here: https://github.com/ofhouse/stackoverflow-65447779我还在此处更新了您的复制回购协议的分支: https://github.com/ofhouse/stackoverflow-65447779

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM