Skip to content

Commit

Permalink
feature #603 Allow to configure the resolve-url-loader (diegocardoso9…
Browse files Browse the repository at this point in the history
…3, 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
  • Loading branch information
weaverryan committed Aug 9, 2019
2 parents 70e387b + b7c7e66 commit bb5f533
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
3 changes: 3 additions & 0 deletions index.js
Expand Up @@ -754,6 +754,9 @@ class Encore {
* when disabled, all url()'s are resolved relative
* to the original entry file... not whatever file
* the url() appears in.
* * {object} resolveUrlLoaderOptions (default={})
* Options parameters for resolve-url-loader
* // https://www.npmjs.com/package/resolve-url-loader#options
*
* @param {function} sassLoaderOptionsCallback
* @param {object} encoreOptions
Expand Down
3 changes: 2 additions & 1 deletion lib/WebpackConfig.js
Expand Up @@ -115,7 +115,8 @@ class WebpackConfig {
// Features/Loaders options
this.copyFilesConfigs = [];
this.sassOptions = {
resolveUrlLoader: true
resolveUrlLoader: true,
resolveUrlLoaderOptions: {}
};
this.preactOptions = {
preactCompat: false
Expand Down
9 changes: 6 additions & 3 deletions lib/loaders/sass.js
Expand Up @@ -30,9 +30,12 @@ module.exports = {
// entry file, not the file that contains the url()
sassLoaders.push({
loader: 'resolve-url-loader',
options: {
sourceMap: webpackConfig.useSourceMaps
}
options: Object.assign(
{
sourceMap: webpackConfig.useSourceMaps
},
webpackConfig.sassOptions.resolveUrlLoaderOptions
)
});
}

Expand Down
20 changes: 20 additions & 0 deletions test/loaders/sass.js
Expand Up @@ -65,6 +65,26 @@ describe('loaders/sass', () => {
cssLoader.getLoaders.restore();
});

it('getLoaders() with resolve-url-loader options', () => {
const config = createConfig();
config.enableSassLoader(() => {}, {
resolveUrlLoaderOptions: {
removeCR: true
}
});

// make the cssLoader return nothing
sinon.stub(cssLoader, 'getLoaders')
.callsFake(() => []);

const actualLoaders = sassLoader.getLoaders(config);
expect(actualLoaders).to.have.lengthOf(2);
expect(actualLoaders[0].loader).to.equal('resolve-url-loader');
expect(actualLoaders[0].options.removeCR).to.be.true;

cssLoader.getLoaders.restore();
});

it('getLoaders() without resolve-url-loader', () => {
const config = createConfig();
config.enableSassLoader(() => {}, {
Expand Down

0 comments on commit bb5f533

Please sign in to comment.