[storybook] Ignore TS-related HMR warnings (#103605)
* [storybook] Ignore TS-related HMR warnings * Fix casing * Remove warnings filter Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
ba5d5cf441
commit
b7ad0c9004
36
packages/kbn-storybook/ignore_not_found_export_plugin.ts
Normal file
36
packages/kbn-storybook/ignore_not_found_export_plugin.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
// derived from https://github.com/TypeStrong/ts-loader/issues/653#issuecomment-390889335
|
||||
//
|
||||
// This plugin suppresses the irritating TS-related warnings in Storybook HMR.
|
||||
|
||||
import { Compiler, Stats } from 'webpack';
|
||||
// @ts-expect-error
|
||||
import ModuleDependencyWarning from 'webpack/lib/ModuleDependencyWarning';
|
||||
|
||||
export class IgnoreNotFoundExportPlugin {
|
||||
apply(compiler: Compiler) {
|
||||
const messageRegExp = /export '.*'( \(reexported as '.*'\))? was not found in/;
|
||||
|
||||
function doneHook(stats: Stats) {
|
||||
stats.compilation.warnings = stats.compilation.warnings.filter(function (warn) {
|
||||
if (warn instanceof ModuleDependencyWarning && messageRegExp.test(warn.message)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
if (compiler.hooks) {
|
||||
compiler.hooks.done.tap('IgnoreNotFoundExportPlugin', doneHook);
|
||||
} else {
|
||||
compiler.plugin('done', doneHook);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,6 +12,7 @@ import { resolve } from 'path';
|
|||
import { Configuration, Stats } from 'webpack';
|
||||
import webpackMerge from 'webpack-merge';
|
||||
import { REPO_ROOT } from './lib/constants';
|
||||
import { IgnoreNotFoundExportPlugin } from './ignore_not_found_export_plugin';
|
||||
|
||||
const stats = {
|
||||
...Stats.presetToOptions('minimal'),
|
||||
|
@ -19,7 +20,6 @@ const stats = {
|
|||
errorDetails: true,
|
||||
errors: true,
|
||||
moduleTrace: true,
|
||||
warningsFilter: /(export .* was not found in)|(entrypoint size limit)/,
|
||||
};
|
||||
|
||||
// Extend the Storybook Webpack config with some customizations
|
||||
|
@ -70,6 +70,7 @@ export default function ({ config: storybookConfig }: { config: Configuration })
|
|||
},
|
||||
],
|
||||
},
|
||||
plugins: [new IgnoreNotFoundExportPlugin()],
|
||||
resolve: {
|
||||
extensions: ['.js', '.ts', '.tsx', '.json'],
|
||||
mainFields: ['browser', 'main'],
|
||||
|
|
Loading…
Reference in a new issue