-
-
Notifications
You must be signed in to change notification settings - Fork 383
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
Disable Async Chunking #41
Comments
@dtothefp maybe put up a basic example repository? Hard to advise without seeing the entry points, what splitChunks you've tried etc |
Alright, I put this together https://github.com/dtothefp/webpack-4-chunks-demo. It is basically a copy of https://github.com/dtothefp/webpack-4-chunks-demo but I updated to Webpack 4 and mini-css-extract-plugin. On branch Now if you go to the Webpack v3 branch Therefore, I'd like to be able to create only 1 single CSS bundle containing all the CSS for my app. In this example SCSS is imported in the In another repo I've tried messing around with the optimization: {
splitChunks: {
cacheGroups: {
commons: {
name: 'commons',
test: /\.css$/,
chunks: 'all',
minChunks: 2,
enforce: true
}
}
}
}, |
That's a lot of information. Might be worth trimming down your example to the bare minimum (and maybe even removing postcss / sass etc and just work with a basic css, entries and import examples). In the other thread you said you use Anyway, looks like you just want to turn off the default chunking, should be able to just do: optimization: {
splitChunks: {
cacheGroups: {
default: false
}
}
}
}, |
hey @garygreen sorry if the example was too in depth...didn't want to spend time setting up my own repo. the essentials are the entry point is a synchronous chunk of css https://github.com/dtothefp/webpack-4-chunks-demo/blob/mini-css-extract-plugin/src/index.js#L8 and then there is an async chunk in the route using a dynamic my problem is the documentation for
|
You can try something like this:
This will give you a single css file, BUT it will be an asynchronously loaded file(and html webpack plugin wont inject it into your index.html via link tag). That is because it contains styles imported from async chunks. I am not sure if this will work for your case and if there is any kind of workaround to extract all styles as a sync chunk. |
@pshurygin this is great and so close to exactly what I want. The only problem is the asynchronously loaded file, not because of the html plugin (generally generate stats and create the link tag in HTML myself) but just because I want to load the link in the head and not make an extra call for that. Do you know if there is anyway to change this behavior? UpdateI was actually incorrect. The HTML plugin is actually creating a (window["webpackJsonp"] = window["webpackJsonp"] || []).push([[0],{
/***/ 167:
/***/ (function(module, exports, __webpack_require__) {
// extracted by mini-css-extract-plugin
/***/ }), If this file is not loaded above <html lang="en">
<head>
<link href="styles.css" rel="stylesheet"></head>
<body>
<div id="root" style="height: 100%"></div>
<script type="text/javascript" src="styles.faba426d1146447cb52a.js"></script>
<script type="text/javascript" src="main.js"></script>
</body>
</html> In my other app using |
You can also inline styles.js into html with something like this plugin https://github.com/numical/script-ext-html-webpack-plugin to avoid extra server call. |
@pshurygin I realized from your configuration above it results in the wrong order of css in the bundle. For example there is css import in the following order:
// src/index.js
import './index.scss' // src/index.scss
@import '~normalize.css/normalize';
@import '~bulma/bulma';
// src/routes/Home/Home.js
import Spinner from 'react-spinkit'
import './style.scss' // react-spinkit
require('loaders.css');
require('../css/base.css');
require('../css/loaders-css.css');
require('../css/fade-in.css');
require('../css/chasing-dots.css');
require('../css/circle.css');
require('../css/cube-grid.css');
require('../css/double-bounce.css');
require('../css/folding-cube.css');
require('../css/pulse.css');
require('../css/rotating-plane.css');
require('../css/three-bounce.css');
require('../css/wandering-cubes.css');
require('../css/wave.css');
require('../css/wordpress.css'); // src/routes/Home/styles.css
@import "~bulma/sass/utilities/initial-variables";
@import "~bulma/sass/utilities/derived-variables";
.home {
&__spinner {
color: $light;
}
} with the configuration options optimization: {
splitChunks: {
chunks: 'all',//split both async chunks and initial chunks(entrypoints)
cacheGroups: {
default: false,//disable default 'commons' chunk behavior
vendors: false, //disable vendor splitting(not sure if you want it)
styles: {
name: 'styles',
test: /\.s?css$/,
minChunks: 1
}
}
}
} the resulting single bundle for CSS is in the order of // react-spinkit and deps in correct order
// src/routes/Home/styles.css
// normalize.css/normalize
// bulma/bulma whereas from the order of imports the desired bundle would be // normalize.css/normalize
// bulma/bulma
// react-spinkit and deps in correct order
// src/routes/Home/styles.css |
Do you have a single entrypoint? Couldnt that normalize styles come from it? You could try removing @import to test it or replace it with js import. If not, i guess it could be an issue with the plugin. |
I also need a way of synchronous loading of CSS, put all the style package to a CSS file, because I need to do theme switching function, by switching different CSS theme of switching, but now the style of the pack out contains asynchronous CSS function, whether there is an option to disable the function of the asynchronous CSS? thank you |
I had a similar problem so I wrote a solution at #57. Tobias might do something more official at some point but this does the trick for now. Essentially I defined a small architecture that allows you to determine which CSS files to capture for an emitting stage. I think this bridges ETWP with MCEP while giving more flexibility. |
I've given up on this effort and resorted to adding an extra To figure out what async components load on the page and their associated CSS chunk names I use This is great but when the async JS loads, it will load the async CSS in a I'm wondering what best practice is around this and if there is a way to disable the async |
@dtothefp did you see #57 (comment) If the |
Looks like there is a blurb in the README right now on how to address this issue: https://github.com/webpack-contrib/mini-css-extract-plugin#extracting-all-css-in-a-single-file I haven't tried it out though because I've moved to embracing chunking CSS and using |
@dtothefp can we close issue? |
What if I have multi entries and would like to lift up the component (async loaded via |
@evilebottnawi I'm fine with closing...seems duplicated here #52 (comment). As I said previously I resorted to add chunks in extra |
If someone found an answer please post it here. |
In case you try to add lazy loaded modules / dynamic imports to the main bundle: webpack/webpack#11431 |
This may be an anti-pattern to what
mini-css-extract-plugin
is trying to accomplish but I'm migrating from Webpack v2 to Webpack v4 in a large React application with many async routes containing CSS modules andextract-text-plugin
is not working correctly.mini-css-extract-plugin
works well but async chunking causes some page load animations, etc. to break because previously all of the CSS was loaded in a single bundle.I'm wondering if there is an option for the plugin that I can disable CSS chunking until my team has time to address considerations associated with CSS chunking?
The text was updated successfully, but these errors were encountered: