Skip to content

Commit

Permalink
[storybook] Ignore TS-related HMR warnings (elastic#103605)
Browse files Browse the repository at this point in the history
* [storybook] Ignore TS-related HMR warnings

* Fix casing

* Remove warnings filter

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
clintandrewhall and kibanamachine committed Jul 6, 2021
1 parent 639918e commit 743e3e6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
36 changes: 36 additions & 0 deletions packages/kbn-storybook/ignore_not_found_export_plugin.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
3 changes: 2 additions & 1 deletion packages/kbn-storybook/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ 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'),
colors: true,
errorDetails: true,
errors: true,
moduleTrace: true,
warningsFilter: /(export .* was not found in)|(entrypoint size limit)/,
};

// Extend the Storybook Webpack config with some customizations
Expand Down Expand Up @@ -70,6 +70,7 @@ export default function ({ config: storybookConfig }: { config: Configuration })
},
],
},
plugins: [new IgnoreNotFoundExportPlugin()],
resolve: {
extensions: ['.js', '.ts', '.tsx', '.json'],
mainFields: ['browser', 'main'],
Expand Down

0 comments on commit 743e3e6

Please sign in to comment.