Yarn Workspaces,工作区不发出错误或警告
Yarn Workspaces, workspace does not emit errors or warnings
为了使用 yarn workspaces 和 craco 创建一个 monorepo,我遵循了以下 post。
它工作得很好,除了一件事:公共(组件)库的 errors/warnings 不会发送到控制台。
结构很简单:
monorepo
|-packages
|-components
|-fe
Fe 是使用组件库的主要 webApp。
FE 正确发出所有警告,组件没有。
如何让共享组件发出warnings/errors?
更新:
在此 repo 中重现的步骤:
https://github.com/sofoklisM/my-monorepo.git
您需要更改的是Create React App 使用的context
option of the underlying ESLint Webpack plugin。
在这种情况下,我将 ESLint 的上下文更改为 monorepo 的根目录(yarn 工作区根目录)。
这是更新后的 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;
}
}
};
我还在此处对您的复制存储库进行了更新:https://github.com/ofhouse/Whosebug-65447779
为了使用 yarn workspaces 和 craco 创建一个 monorepo,我遵循了以下 post。 它工作得很好,除了一件事:公共(组件)库的 errors/warnings 不会发送到控制台。 结构很简单:
monorepo
|-packages
|-components
|-fe
Fe 是使用组件库的主要 webApp。 FE 正确发出所有警告,组件没有。
如何让共享组件发出warnings/errors?
更新:
在此 repo 中重现的步骤: https://github.com/sofoklisM/my-monorepo.git
您需要更改的是Create React App 使用的context
option of the underlying ESLint Webpack plugin。
在这种情况下,我将 ESLint 的上下文更改为 monorepo 的根目录(yarn 工作区根目录)。
这是更新后的 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;
}
}
};
我还在此处对您的复制存储库进行了更新:https://github.com/ofhouse/Whosebug-65447779