-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
feat(gatsby-plugin-sass): Allow miniCssExtract to accept options #18889
feat(gatsby-plugin-sass): Allow miniCssExtract to accept options #18889
Conversation
What is the use case for this? If there is issue that require changing the |
Friendly ping @tmilewski |
@LekoArts @pieh I'll defer to you two as to whether this should go into core or not. I wanted to make sure people had the option one way or the other. This solves the case where miniCssExtract is warning on the ordering of styles. There are cases where this isn't an issue (see: self-contained styles with each component) but it's still throwing out warnings left-and-right. webpack-contrib/mini-css-extract-plugin#250 (comment)
webpack-contrib/mini-css-extract-plugin#250 (comment)
|
Just to understand what |
@pieh That's correct. |
It would be really great if this could be merged in, currently having issues regarding order warnings. |
I've opened #23170 to rebase the changes and get this merged. |
@tmilewski could you rebase this PR to current master, and add some documentation around it? I'm not entirely sure how to document it and otherwise I might have to close this. It looks good otherwise. Cheers! |
Hey @tmilewski, first of all, sorry to keep you waiting. I've looked at your changes and they're not fixing the problem. Your PR changes the options for the "mini-css-extract-plugin loader". The loader only has the following options:
IgnoreOrder is defined on the plugin itself. gatsby/packages/gatsby/src/utils/webpack-utils.ts Lines 627 to 631 in e095119
Sadly, we currently do not have a proper API to change these values from a plugin. What you can do is use the replaceWebpackConfig action, in your gatsby-node.js file. With exports.onCreateWebpackConfig = ({ actions, stage, getConfig, loaders }) => {
if (stage === "build-javascript") {
const config = getConfig()
const index = config.plugins.findIndex(plugin => {
return plugin.constructor.name === "MiniCssExtractPlugin"
})
//remove extract plugin from current plugin list
config.plugins.splice(index, 1)
// add our own miniCssExtract plugin
config.plugins.push(loaders.miniCssExtract({ ignoreOrder: true }))
actions.replaceWebpackConfig(config)
}
} |
@wardpeet I'm getting this issue when I try to run your code:
|
This is what worked for me.
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
exports.onCreateWebpackConfig = ({ actions, stage, getConfig, loaders }) => {
if (stage === "build-javascript") {
const config = getConfig();
const index = config.plugins.findIndex((plugin) => {
return plugin.constructor.name === "MiniCssExtractPlugin";
});
config.plugins[index] = new MiniCssExtractPlugin({ ignoreOrder: true });
actions.replaceWebpackConfig(config);
}
};
|
For anyone else finding this issue, this is what worked for me: exports.onCreateWebpackConfig = ({ actions, stage, getConfig, loaders }) => {
if (stage === "build-javascript" || stage === "develop") {
const config = getConfig()
const index = config.plugins.findIndex(
(plugin) => plugin.constructor.name === "MiniCssExtractPlugin"
)
if (index) config.plugins[index].options.ignoreOrder = true
actions.replaceWebpackConfig(config)
}
} Instead of replacing the plugin I just change the option |
Description
This PR allows for
miniCssExtract
to accept options fromgatsby-plugin-sass
.Related Issues
None