Closed dd8888 closed 3 years ago
Something changed in react-scripts.
If you copy https://github.com/kkulbae/craco-image-optimizer-plugin/blob/master/index.js
and replace:
const urlLoader = getLoader(config, loaderByName('url-loader'));
const loader = urlLoader.match.loader;
with
const urlLoaderCandidates = getLoaders(config, loaderByName('url-loader'));
const urlLoader = urlLoaderCandidates.matches.find(m =>
m.loader &&
m.loader.test &&
(Array.isArray(m.loader.test)
? m.loader.test.some(r => r.toString().indexOf("jpe?g") >= 0)
: m.loader.test.toString().indexOf("jpe?g") >= 0));
if (!urlLoader) {
throw Error("could not find correct url-loader. did you change react-scripts version?");
}
const loader = urlLoader.loader;
taking care to import getLoaders
instead of getLoader
Then just import the file instead of this package.
@dd8888 I submitted a pull request that addresses this issue in a slightly different way, although end outcome is the same.
Still an issue:
TypeError: Cannot read properties of undefined (reading 'loader')
Hey, I just downloaded the plugin and it doesn't seem to work.
This is my craco.config.js (copy-pasted the example)
But on prod, the images are still the same. Any ideas? Thanks.