You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been trying this plugin, and have the following questions:
1. Using MediaQueryPlugin with file-loader:
I'm using file-loader to resolve references to images in my CSS files, so that they can be emitted to the output directory after Webpack runs.
Before using media query plugin, Webpack would recognize the references to images inside media queries in the main.css file, and place the images in the public directory correctly.
After adding media query plugin to my webpack config, Webpack separated media queries into its own CSS files correctly, but the references to images inside those media queries don't seem to be recognized anymore, so the image output folder is not created in my "/public" directory.
I managed to solve this by importing images using:
But would have expected them to be resolved automatically.
2. Screen resizing:
The behavior I was looking for is that the page would request a different CSS when reaching a new breakpoint.
This can be done by using something like:
In that case, the file will be loaded in a non-blocking way, and with lower priority, when the screen has a different size, but be available when the screen changes so it can be used.
Following the instructions for using extracted files, the page does load the right CSS at page load time, according to the viewport of the requesting device, but doesn't request a different stylesheet dynamically when the viewport changes.
Wondering if there's any better way of doing this, without using the link rel tag shared before.
I have to check this myself... thinking about url loader as a solution but needs to be tested
viewport specific loading
If you wanna load dynamically the extracted CSS once the viewport has changed you can add an event listener. Here's a quick example (probably needs some polishing but you should get the idea):
letexampleDesktop=false;// ensure calling import only oncefunctioncheckViewport(){if(exampleDesktop===false&&window.innerWidth>=960){exampleDesktop=true;import(/* webpackChunkName: 'example-desktop' */'./example-desktop.scss');}}window.onresize=checkViewport;// check on resizecheckViewport();// initial check
The file-loaader problem is definitely a bug.
I've found out now loaders get applied to the media chunks. Not sure how easily this can be fixed... needs more research.
Hi,
I'm having the same issue.
Extracted files (media-query once) are not processed by file_loader, and path is not changed (names not hashed etc.)
So +1 from me
Hi,
I've been trying this plugin, and have the following questions:
1. Using MediaQueryPlugin with file-loader:
I'm using file-loader to resolve references to images in my CSS files, so that they can be emitted to the output directory after Webpack runs.
Before using media query plugin, Webpack would recognize the references to images inside media queries in the main.css file, and place the images in the public directory correctly.
After adding media query plugin to my webpack config, Webpack separated media queries into its own CSS files correctly, but the references to images inside those media queries don't seem to be recognized anymore, so the image output folder is not created in my "/public" directory.
I managed to solve this by importing images using:
require.context("./img/", true, /\.(png|svg|jpg|gif)$/);
But would have expected them to be resolved automatically.
2. Screen resizing:
The behavior I was looking for is that the page would request a different CSS when reaching a new breakpoint.
This can be done by using something like:
<link rel="stylesheet" media="(max-width:480px)" href="main-mobile.css">
In that case, the file will be loaded in a non-blocking way, and with lower priority, when the screen has a different size, but be available when the screen changes so it can be used.
Following the instructions for using extracted files, the page does load the right CSS at page load time, according to the viewport of the requesting device, but doesn't request a different stylesheet dynamically when the viewport changes.
Wondering if there's any better way of doing this, without using the link rel tag shared before.
Here's the content of webpack.config.js:
And this is the main css file:
Thanks in advance.
The text was updated successfully, but these errors were encountered: