Webpack 5: raw-loader deprecated, require.context approach no longer working
See original GitHub issueAfter the upgrade to builder-webpack5 and 6.3.12 on storybook, I noticed that the approach suggested in the readme is no longer working. Attempting to load all scss files in a folder no longer provides the sourcecode:
const svgIconsReq = require.context('!!raw-loader!../../../assets/icons', true, /\.svg/);
const svgIconTokenFiles = svgIconsReq
.keys()
.map(filename => ({ filename, content: svgIconsReq(filename).default }));
...
> svgIconTokenFiles
[... { filename: './add.svg', content: undefined }, { filename: './delete.svg', content: undefined } ...]
It looks like the raw-loader
approach is no longer going to be supported moving forward (see: https://webpack.js.org/guides/asset-modules/#replacing-inline-loader-syntax), and using the new method isn’t going to allow inlining without modifications to the existing rules: (see: https://github.com/webpack/webpack/issues/12900). The only files that weren’t dropped from importing were ones that were marked as entrypoints.
Issue Analytics
- State:
- Created 2 years ago
- Comments:14
Top Results From Across the Web
To v5 from v4 - webpack
Webpack 5 requires at least Node.js 10.13.0 (LTS), so make sure you upgrade ... As webpack 5 removes all deprecated features, make sure...
Read more >raw-loader - webpack - JS.ORG
A loader for webpack that allows importing files as a String. Getting Started. To begin, you'll need to install raw-loader : $ npm...
Read more >Resolve | webpack
Create aliases to import or require certain modules more easily. ... null-loader is deprecated in webpack 5. use alias: { xyz$: false }...
Read more >Module Methods - webpack
This section covers all methods available in code compiled with webpack. When using webpack to bundle your application, you can pick from a...
Read more >Loader Interface - webpack
The this context of the function is filled-in by webpack and the loader ... The this.callback method is more flexible as it allows...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey. Just published v2.0.0-beta.0 with some “experimental” changes. It implements a different way of loading source files and simplifies the addon configuration. I hope it gets rid of the issues with webpack 5.
Would be great if you could check it out.
Migration:
v2.0.0-beta.0
.storybook/preview.js
Before:
After:
Hi @Sqrrl, I checked here and it works like a charm!! Thank you, you saved my day!!! ❤️ 😍 ✨