css 页面的 Webpack 行为没有样式加载然后闪烁

Webpack behavior with css page loads without style then flashes

因为我使用 Webpack 也捆绑了我的 css 并且我的脚本标签位于我的 HTML 的底部,所以在初始页面加载时我得到的页面内容没有任何造型。

当脚本启动时,样式突然出现了。

Webpack 在帮助捆绑 CSS 方面非常有用,但这种行为非常令人不安,不能真正接受。

解决此问题的常用方法是什么?

您可以尝试使用 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

对于 webpack v4,mini-css-extract-plugin should be used instead of extract-text-webpack-plugin (source). There are usage examples on their README