Skip to content

Commit bb5f533

Browse files
committed
feature #603 Allow to configure the resolve-url-loader (diegocardoso93, Diego)
This PR was merged into the master branch. Discussion ---------- Allow to configure the resolve-url-loader This PR solve the error below, occuring on some cases: ``` Error: resolve-url-loader: CSS error source-map information is not available at url() declaration (found orphan CR, try removeCR option) ``` See discussion: bholloway/resolve-url-loader#107 Commits ------- b7c7e66 Add documentation for resolveUrlLoaderOptions 4671016 Fix lint job 392d32b Merge branch 'master' of https://github.com/diegocardoso93/webpack-encore a52bb05 Add optional resolve-url-loader options 01e1da7 Add optional resolve-url-loader options 906ae9b Fix "found orphan CR, try removeCR option" 988e5d1 Update resolve-url-loader to v3.1.0
2 parents 70e387b + b7c7e66 commit bb5f533

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,9 @@ class Encore {
754754
* when disabled, all url()'s are resolved relative
755755
* to the original entry file... not whatever file
756756
* the url() appears in.
757+
* * {object} resolveUrlLoaderOptions (default={})
758+
* Options parameters for resolve-url-loader
759+
* // https://www.npmjs.com/package/resolve-url-loader#options
757760
*
758761
* @param {function} sassLoaderOptionsCallback
759762
* @param {object} encoreOptions

lib/WebpackConfig.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ class WebpackConfig {
115115
// Features/Loaders options
116116
this.copyFilesConfigs = [];
117117
this.sassOptions = {
118-
resolveUrlLoader: true
118+
resolveUrlLoader: true,
119+
resolveUrlLoaderOptions: {}
119120
};
120121
this.preactOptions = {
121122
preactCompat: false

lib/loaders/sass.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ module.exports = {
3030
// entry file, not the file that contains the url()
3131
sassLoaders.push({
3232
loader: 'resolve-url-loader',
33-
options: {
34-
sourceMap: webpackConfig.useSourceMaps
35-
}
33+
options: Object.assign(
34+
{
35+
sourceMap: webpackConfig.useSourceMaps
36+
},
37+
webpackConfig.sassOptions.resolveUrlLoaderOptions
38+
)
3639
});
3740
}
3841

test/loaders/sass.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,26 @@ describe('loaders/sass', () => {
6565
cssLoader.getLoaders.restore();
6666
});
6767

68+
it('getLoaders() with resolve-url-loader options', () => {
69+
const config = createConfig();
70+
config.enableSassLoader(() => {}, {
71+
resolveUrlLoaderOptions: {
72+
removeCR: true
73+
}
74+
});
75+
76+
// make the cssLoader return nothing
77+
sinon.stub(cssLoader, 'getLoaders')
78+
.callsFake(() => []);
79+
80+
const actualLoaders = sassLoader.getLoaders(config);
81+
expect(actualLoaders).to.have.lengthOf(2);
82+
expect(actualLoaders[0].loader).to.equal('resolve-url-loader');
83+
expect(actualLoaders[0].options.removeCR).to.be.true;
84+
85+
cssLoader.getLoaders.restore();
86+
});
87+
6888
it('getLoaders() without resolve-url-loader', () => {
6989
const config = createConfig();
7090
config.enableSassLoader(() => {}, {

0 commit comments

Comments
 (0)