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 ebd1778
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 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
9 changes: 9 additions & 0 deletions 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
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 ebd1778

Please sign in to comment.