-
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
How to use resolve-url-loader with gatsby-plugin-sass in v2? #7776
Comments
@borekb Did you figure out a way to make the relative url() work? |
Had to do some digging as we removed resolve-url-loader since but this was our // Note: this is basically a copy of https://github.com/gatsbyjs/gatsby/blob/08d2bcf355550842c196439e58f6dda209963564/packages/gatsby-plugin-sass/src/gatsby-node.js
// with 'resolve-url-loader' added manually. I don't know how to do it in a better way in Gatsby v2.
// I asked here: https://github.com/gatsbyjs/gatsby/issues/7776
exports.onCreateWebpackConfig = (
{ actions, stage, rules, plugins, loaders },
{ postCssPlugins, ...sassOptions }
) => {
const { setWebpackConfig } = actions
const PRODUCTION = stage !== `develop`
const isSSR = stage.includes(`html`)
const sassLoader = {
loader: `sass-loader`,
options: {
sourceMap: true, // this is required for 'resolve-url-loader' to work
precision: 8, // required for Bootstrap
...sassOptions,
},
}
const sassRule = {
test: /\.s(a|c)ss$/,
use: isSSR
? [loaders.null()]
: [
loaders.miniCssExtract(),
loaders.css({ importLoaders: 2 }),
loaders.postcss({ plugins: postCssPlugins }),
'resolve-url-loader', // <-----
sassLoader,
],
}
const sassRuleModules = {
test: /\.module\.s(a|c)ss$/,
use: [
!isSSR && loaders.miniCssExtract(),
loaders.css({ modules: true, importLoaders: 2 }),
loaders.postcss({ plugins: postCssPlugins }),
sassLoader,
].filter(Boolean),
}
let configRules = []
switch (stage) {
case `develop`:
case `build-javascript`:
case `build-html`:
case `develop-html`:
configRules = configRules.concat([
{
oneOf: [sassRuleModules, sassRule],
},
])
break
}
setWebpackConfig({
module: {
rules: configRules,
},
})
} |
Thanks! I ended up inlining my svg but I'm sure your answer will help anybody who comes across this problem in the future, because there's currently no solution on all the issues mentioning Sass |
Old issues will be closed after 30 days of inactivity. This issue has been quiet for 20 days and is being marked as stale. Reply here or add the label "not stale" to keep this issue open! |
Hey again! It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m Thanks again for being part of the Gatsby community! |
In v1, I could do this to make relative
url()
in Sass work:It's ugly but inserts the resolve-url-loader as the previous-to-last item in the list of style loaders.
How to achieve the same in v2?
The text was updated successfully, but these errors were encountered: