-
Notifications
You must be signed in to change notification settings - Fork 27
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
File-loader and screen resizing questions #17
Comments
thanks for your issue!
I have to check this myself... thinking about url loader as a solution but needs to be tested
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): let exampleDesktop = false; // ensure calling import only once
function checkViewport() {
if (exampleDesktop === false && window.innerWidth >= 960) {
exampleDesktop = true;
import(/* webpackChunkName: 'example-desktop' */ './example-desktop.scss');
}
}
window.onresize = checkViewport; // check on resize
checkViewport(); // initial check |
The file-loaader problem is definitely a bug. I'll postpone this to 2.0.0 |
Thanks for confirming! |
Hi, |
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: