storybookjs / require-context.macro

🖇 A Babel macro needed for some advanced Storybook setups. Used to mock webpack's context function in test environments.
MIT License
48 stars 8 forks source link

[Bug] Webpack loader config can't work in require-context.macro #122

Closed miaolq closed 2 years ago

miaolq commented 2 years ago

Describe the bug

requireContext('!@svgr/webpack!../../../assets/svgs', false, /\.(svg)$/) will treat !@svgr/webpack! as path instead of webpack loader options.

Expected behavior

Treat !@svgr/webpack! as webpack loader options

Environment

kylemh commented 2 years ago

It was difficult for me going through the Webpack documentation to try and find a type signature for require.context(); however, not a single test prefixes any string with a '!'.

https://github.com/webpack/webpack/blob/c181294865dca01b28e6e316636fef5f2aad4eb6/test/cases/parsing/context/index.js

I'm a little worried that perhaps this isn't desired behavior, since it's not a loader.

miaolq commented 2 years ago

Thank you. For now, i will code like this.

const res = IS_TEST
    ? requireContext('../../../assets/svgs', false, /\.(svg)$/)
    : require.context('!@svgr/webpack!assets/svgs', false, /\.(svg)$/);