Open frugan-dev opened 9 months ago
Hi @frugan-it. Hmm, this is an odd one. I can't recreate the issue when I create an example repo with webpack
and postcss-loader
.
This is my webpack.config.js
file:
module.exports = {
// ...
module: {
rules: [
{
test: /\.css$/i,
include: path.resolve(__dirname, 'src'),
use: ['style-loader', 'css-loader', 'postcss-loader'],
},
],
},
}
Can you provide a repo so I can test?
As far as I know, the plugin shouldn't be doing anything to the property aspect-ratio
. So I wonder if something else is tripping it up, and the error about attr(width) / attr(height)
is just a red herring.
Hi @gavinmcfarland, thanks for the support!
I created this test repository https://github.com/frugan-it/flex-gap-polyfill-issue-85. If you try to comment these lines https://github.com/frugan-it/flex-gap-polyfill-issue-85/blob/master/webpack.config.js#L187-L192 everything works correctly. I tried to isolate the problem as much as possible, but I don't understand what it could depend on..
Thank you! I'll check it out and do some investigating.
So, I've looked into it a bit more.
There is a conflict between sass-loader
and a dependency my plugin uses called postcss-values-parser
.
sass-loader
is removing the spaces between attr(width) / attr(height)
, which then postcss-values-parser
trips over because it's expecting a space before and after the /
. I don't know which is correct in this case, but that's what's causing the issue.
You can try the following to work around it.
Tell flex-gap-polyfill
to ignore processing the rule:
img[width][height]{
/* added by fgp */
height: auto;
aspect-ratio: attr(width) / attr(height);
}
Or you can manually apply the polyfill:
img[width][height]{
/* added by fgp */
--fgp-height: var(--element-has-fgp) calc(auto + var(--fgp-gap-row, 0%));
height: var(--fgp-height, auto);
aspect-ratio: attr(width, 1) / attr(height, 1);
}
I tried to disable the modification that Sass applies but it seems a little unpredictable. I found some others have had difficulty with it too. https://github.com/webpack-contrib/sass-loader/issues/763
Let me know how you get on.
I can probably also release a fix by adding some logic to avoid reading the values like the ones in the aspect-ratio
prop as it doesn't need to.
Thanks @gavinmcfarland, sorry for the late reply..
I didn't know you could tell flex-gap-polyfill
to ignore some lines, maybe that should be specified in the README
?
Anyway thank you, now with this comment it seems to work!
No worries. I initially never saw the need to ignore certain rules, but I remembered the plugin ignores rules it's already processed, which have a comment of * added by fgp */
in them. I'll add more official support for this when I get chance.
Hi there,
I'm having this error with Webpack 5:
These are the main parts of my setup:
package.json
webpack.config.js
main.scss
The error appears only when I enable your plugin, and with the plugin enabled it disappears only by commenting the line
aspect-ratio: attr(width) / attr(height);
of the scss file.What could it depend on?