-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resizing images usage #63
Comments
@cyrilwanner could you shed some light on this? 🙏 |
Hi @fandy Now, it would help if you can tell me what your So, to help you more, it would be nice to have a bit more information: What does the |
Wow, thanks for the quick reply and explanation @cyrilwanner! I'm mapping over my data which looks like this:
I guess this is a known bug that
Now I get an error So I've tried just doing
|
I think there are actually two problems. Now, there are two solutions to solve this: you could just change the paths to relative ones (but you may end up with a lot webpack(config, options) {
config.resolve.alias['static'] = path.join(__dirname, 'static')
return config
} This should solve the first problem. Then, the second one is, as you also wrote in your last comment, the same as in issue #16. Although, this is also a webpack restriction, next-optimized-images can't avoid this. And when you also want to use a query string (?resize) together with a dynamic path, it gets even more complicated and you have to use a require context (#16 (comment)). So, I think something like this could work: const listings = [
{
src: "./1/preview.jpg",
},
{
src: "./2/preview.jpg",
},
{
src: "./3/preview.jpg",
},
{
src: "./4/preview.jpg",
}
];
// v this requires you to define the path alias in webpack, otherwise, you can also use a relative path here
const requireResizedImage = require.context('static/images/listings/?resize&size=300', false, /\.jpg$/);
const listingsMarkup = listings.map(({ src, breed, gender, id }) => (
<Preview
src={requireResizedImage(src)}
key={src}
/>
)); There is just one downside: Because webpack doesn't know which images you need at runtime, it resizes all images in the directory you pass in to the I hope that this helps solving your issue :) |
Thanks @cyrilwanner! I'm trying to add the absolute imports webpack config using
Here's my config:
Removing the webpack config in the |
Okay, I think this error now comes from defining the two To solve it, you can move the webpack configs out of the plugin configs into the global config object (2. param): module.exports = withPlugins([
[withFonts, {}],
[withTypescript],
[
optimizedImages,
{
optimizeImagesInDev: true,
}
]
], {
webpack(config, options) {
// only add plugin in development to client webpack config .
if (env === "development" && !options.isServer) {
config.plugins.push(new ForkTsCheckerWebpackPlugin());
}
// add a resolve alias for the static folder
config.resolve.alias["static"] = path.join(__dirname, "static");
return config;
}
}); I'll try to change the plugin to also work with your definition of the plugins in the future, I like that way of overwriting the webpack config so they are next to the relevant plugin :) |
Expectation
I should be able to resize images in development after installing
responsive-loader
andsharp
, with no additional configuration innext.config.js
.Result
Images are not optimized in dev when I do:
or using
require
gives meCannot find module
error:The text was updated successfully, but these errors were encountered: