diff --git a/index.js b/index.js index ee6232f7..26e8afbd 100644 --- a/index.js +++ b/index.js @@ -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 diff --git a/lib/WebpackConfig.js b/lib/WebpackConfig.js index 0455718d..cee9c203 100644 --- a/lib/WebpackConfig.js +++ b/lib/WebpackConfig.js @@ -115,7 +115,8 @@ class WebpackConfig { // Features/Loaders options this.copyFilesConfigs = []; this.sassOptions = { - resolveUrlLoader: true + resolveUrlLoader: true, + resolveUrlLoaderOptions: {} }; this.preactOptions = { preactCompat: false diff --git a/lib/loaders/sass.js b/lib/loaders/sass.js index 3b0e23ae..9f9858b2 100644 --- a/lib/loaders/sass.js +++ b/lib/loaders/sass.js @@ -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 + ) }); } diff --git a/test/loaders/sass.js b/test/loaders/sass.js index 4dbadcfe..e3fe1b98 100644 --- a/test/loaders/sass.js +++ b/test/loaders/sass.js @@ -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(() => {}, {