Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack behavior with css page loads without style then flashes

Because I'm using Webpack to also bundle my css and that my script tag is at the bottom of my HTML, on initial page load I get the content of the page without any of the styling.

Then all of a sudden the styling comes in when the script kicks in.

Webpack is very useful to help bundle the CSS but this behavior is quite unsettling and not really acceptable.

What are common ways to remedy this problem?

like image 784
user391986 Avatar asked Jul 16 '15 19:07

user391986


People also ask

How do I load a CSS file into webpack?

In the following code block, css-loader and style-loader are used together. Similar to babel-loader , we can load CSS files to style our pages like so: module: { rules: [ { test: /\\. js$/, loader: "babel-loader", exclude: "/node_modules/", }, // CSS rules { test: /\\.

What is style-loader in webpack?

Loaders are the node-based utilities built for webpack to help webpack to compile and/or transform a given type of resource that can be bundled as a javascript module. css-loader is the npm module that would help webpack to collect CSS from all the css files referenced in your application and put it into a string.

How does style-loader work?

style-loader injects the styling through a style element. The way it does this can be customized. It also implements the Hot Module Replacement interface providing for a pleasant development experience. The matched files can be processed through asset modules by using the type field at a loader definition.


1 Answers

You can try using extract-text-webpack-plugin to break out the css in to their own files. That way you can add <link> tags yourself to those pages you wish to have their styles loaded before the JS is loaded. See stylesheets as separate bundle.

like image 59
matpie Avatar answered Oct 04 '22 03:10

matpie