Skip to content

Commit a79a58a

Browse files
atlantehabhiisheek
authored andcommitted
Add support for absolute paths when using url() in CSS (facebook#7937)
* Support scss absolute path resolution for url() Adding resolve-url-loader broke all apps using scss with centralized assets folder and all url(./assets/*.png) broke (facebook#7023). This change allows apps to use url(/assets/*.png) and it would map to src/assets/*.png * test: Add global scss assets test
1 parent ce6f347 commit a79a58a

File tree

7 files changed

+41
-0
lines changed

7 files changed

+41
-0
lines changed

packages/react-scripts/config/webpack.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ module.exports = function (webpackEnv) {
133133
loader: require.resolve('resolve-url-loader'),
134134
options: {
135135
sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
136+
root: paths.appSrc,
136137
},
137138
},
138139
{

test/fixtures/global-scss-asset-resolution/.disable-pnp

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const testSetup = require('../__shared__/test-setup');
2+
3+
if (testSetup.isLocal) {
4+
// TODO: make this work locally
5+
test('skipped locally', () => {});
6+
} else {
7+
test('builds in development', async () => {
8+
const { fulfilled } = await testSetup.scripts.start({ smoke: true });
9+
expect(fulfilled).toBe(true);
10+
});
11+
12+
test('builds in production', async () => {
13+
const { fulfilled } = await testSetup.scripts.build();
14+
expect(fulfilled).toBe(true);
15+
});
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"dependencies": {
3+
"node-sass": "4.x",
4+
"react": "latest",
5+
"react-dom": "latest"
6+
}
7+
}
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import './index.scss';
4+
5+
ReactDOM.render(<div />, document.getElementById('root'));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#root {
2+
width: 300px;
3+
height: 300px;
4+
background: url(/images/logo.svg) center/cover no-repeat;
5+
}

0 commit comments

Comments
 (0)