Skip to content

Commit

Permalink
css-loader should ignore urls beginning with a / - closes #2743
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreyWay committed Jan 6, 2021
1 parent 4b71219 commit 9f10e00
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/components/CssWebpackConfig.js
Expand Up @@ -108,7 +108,13 @@ class CssWebpackConfig extends AutomaticComponent {
{
loader: 'css-loader',
options: {
url: Config.processCssUrls,
url: (url, resourcePath) => {
if (url.startsWith('/')) {
return false;
}

return Config.processCssUrls;
},
modules: useCssModules
}
},
Expand Down
8 changes: 7 additions & 1 deletion src/components/Preprocessor.js
Expand Up @@ -57,7 +57,13 @@ class Preprocessor {
{
loader: 'css-loader',
options: {
url: processUrls,
url: (url, resourcePath) => {
if (url.startsWith('/')) {
return false;
}

return processUrls;
},
sourceMap: Mix.isUsing('sourcemaps'),
importLoaders: 1
}
Expand Down
11 changes: 10 additions & 1 deletion test/features/preprocessors.js
Expand Up @@ -7,6 +7,15 @@ import webpack from '../helpers/webpack';

import '../helpers/mix';

test('it does not process absolute urls', async t => {
mix.postCss(`test/fixtures/app/src/css/app.css`, 'css');

await t.notThrowsAsync(
webpack.compile(),
'CSS failed to compile due to incorrect URL processing.'
);
});

test('it compiles PostCSS without JS', async t => {
mix.postCss(`test/fixtures/app/src/css/app.css`, 'css');

Expand Down Expand Up @@ -201,7 +210,7 @@ test('Compiling multiple CSS assets places CSS in the correct location', async t

assert.fileMatchesCss(
`test/fixtures/app/dist/css/app.css`,
`body{color:red;}.app{color:red;}`,
`body{color:red;}.app{color:red;background:url('/absolute/image.jpg');}`,
t
);
});
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/app/src/css/app.css
@@ -1,3 +1,4 @@
.app {
color: red;
background: url('/absolute/image.jpg');
}

0 comments on commit 9f10e00

Please sign in to comment.