From 988e5d1e3c1334424f04a6a27bac9c1e95d9cae7 Mon Sep 17 00:00:00 2001 From: Diego Cardoso Date: Mon, 8 Jul 2019 11:37:24 -0300 Subject: [PATCH 1/6] Update resolve-url-loader to v3.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 47ffb33b..5a570e2a 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "optimize-css-assets-webpack-plugin": "^5.0.1", "pkg-up": "^1.0.0", "pretty-error": "^2.1.1", - "resolve-url-loader": "^3.0.1", + "resolve-url-loader": "^3.1.0", "semver": "^5.5.0", "style-loader": "^0.21.0", "terser-webpack-plugin": "^1.1.0", From 906ae9b919b27bb17a5d79bbdde4340f260370f1 Mon Sep 17 00:00:00 2001 From: Diego Cardoso Date: Mon, 8 Jul 2019 13:54:49 -0300 Subject: [PATCH 2/6] Fix "found orphan CR, try removeCR option" Error: resolve-url-loader: CSS error source-map information is not available at url() declaration (found orphan CR, try removeCR option) see: https://github.com/bholloway/resolve-url-loader/issues/107 --- lib/loaders/sass.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/loaders/sass.js b/lib/loaders/sass.js index 3b0e23ae..29d7114b 100644 --- a/lib/loaders/sass.js +++ b/lib/loaders/sass.js @@ -31,7 +31,8 @@ module.exports = { sassLoaders.push({ loader: 'resolve-url-loader', options: { - sourceMap: webpackConfig.useSourceMaps + sourceMap: webpackConfig.useSourceMaps, + removeCR: true } }); } From 01e1da71dae30c5f84c781e134599a5e188071f8 Mon Sep 17 00:00:00 2001 From: Diego Date: Wed, 17 Jul 2019 15:33:46 -0300 Subject: [PATCH 3/6] Add optional resolve-url-loader options --- lib/WebpackConfig.js | 9 ++++++++- lib/loaders/sass.js | 2 +- package.json | 2 +- test/loaders/sass.js | 20 ++++++++++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/WebpackConfig.js b/lib/WebpackConfig.js index 0455718d..9d84a079 100644 --- a/lib/WebpackConfig.js +++ b/lib/WebpackConfig.js @@ -115,7 +115,14 @@ class WebpackConfig { // Features/Loaders options this.copyFilesConfigs = []; this.sassOptions = { - resolveUrlLoader: true + resolveUrlLoader: true, + resolveUrlLoaderOptions: { + engine: 'postcss', + keepQuery: false, + removeCR: false, + debug: false, + silent: false + } }; this.preactOptions = { preactCompat: false diff --git a/lib/loaders/sass.js b/lib/loaders/sass.js index 29d7114b..dd24e1e8 100644 --- a/lib/loaders/sass.js +++ b/lib/loaders/sass.js @@ -32,7 +32,7 @@ module.exports = { loader: 'resolve-url-loader', options: { sourceMap: webpackConfig.useSourceMaps, - removeCR: true + ...webpackConfig.sassOptions.resolveUrlLoaderOptions } }); } diff --git a/package.json b/package.json index 5a570e2a..47ffb33b 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "optimize-css-assets-webpack-plugin": "^5.0.1", "pkg-up": "^1.0.0", "pretty-error": "^2.1.1", - "resolve-url-loader": "^3.1.0", + "resolve-url-loader": "^3.0.1", "semver": "^5.5.0", "style-loader": "^0.21.0", "terser-webpack-plugin": "^1.1.0", 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(() => {}, { From a52bb05522bdb206e926ec2d4f51b1f6c49f0451 Mon Sep 17 00:00:00 2001 From: Diego Cardoso Date: Wed, 17 Jul 2019 15:33:46 -0300 Subject: [PATCH 4/6] Add optional resolve-url-loader options --- lib/WebpackConfig.js | 9 ++++++++- lib/loaders/sass.js | 2 +- package.json | 2 +- test/loaders/sass.js | 20 ++++++++++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/WebpackConfig.js b/lib/WebpackConfig.js index 0455718d..9d84a079 100644 --- a/lib/WebpackConfig.js +++ b/lib/WebpackConfig.js @@ -115,7 +115,14 @@ class WebpackConfig { // Features/Loaders options this.copyFilesConfigs = []; this.sassOptions = { - resolveUrlLoader: true + resolveUrlLoader: true, + resolveUrlLoaderOptions: { + engine: 'postcss', + keepQuery: false, + removeCR: false, + debug: false, + silent: false + } }; this.preactOptions = { preactCompat: false diff --git a/lib/loaders/sass.js b/lib/loaders/sass.js index 29d7114b..dd24e1e8 100644 --- a/lib/loaders/sass.js +++ b/lib/loaders/sass.js @@ -32,7 +32,7 @@ module.exports = { loader: 'resolve-url-loader', options: { sourceMap: webpackConfig.useSourceMaps, - removeCR: true + ...webpackConfig.sassOptions.resolveUrlLoaderOptions } }); } diff --git a/package.json b/package.json index 5a570e2a..47ffb33b 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "optimize-css-assets-webpack-plugin": "^5.0.1", "pkg-up": "^1.0.0", "pretty-error": "^2.1.1", - "resolve-url-loader": "^3.1.0", + "resolve-url-loader": "^3.0.1", "semver": "^5.5.0", "style-loader": "^0.21.0", "terser-webpack-plugin": "^1.1.0", 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(() => {}, { From 4671016abc7072bd258bde7f4979d66d426cc82d Mon Sep 17 00:00:00 2001 From: Diego Date: Fri, 26 Jul 2019 15:04:50 -0300 Subject: [PATCH 5/6] Fix lint job --- lib/WebpackConfig.js | 8 +------- lib/loaders/sass.js | 10 ++++++---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/WebpackConfig.js b/lib/WebpackConfig.js index 9d84a079..cee9c203 100644 --- a/lib/WebpackConfig.js +++ b/lib/WebpackConfig.js @@ -116,13 +116,7 @@ class WebpackConfig { this.copyFilesConfigs = []; this.sassOptions = { resolveUrlLoader: true, - resolveUrlLoaderOptions: { - engine: 'postcss', - keepQuery: false, - removeCR: false, - debug: false, - silent: false - } + resolveUrlLoaderOptions: {} }; this.preactOptions = { preactCompat: false diff --git a/lib/loaders/sass.js b/lib/loaders/sass.js index dd24e1e8..9f9858b2 100644 --- a/lib/loaders/sass.js +++ b/lib/loaders/sass.js @@ -30,10 +30,12 @@ module.exports = { // entry file, not the file that contains the url() sassLoaders.push({ loader: 'resolve-url-loader', - options: { - sourceMap: webpackConfig.useSourceMaps, - ...webpackConfig.sassOptions.resolveUrlLoaderOptions - } + options: Object.assign( + { + sourceMap: webpackConfig.useSourceMaps + }, + webpackConfig.sassOptions.resolveUrlLoaderOptions + ) }); } From b7c7e66feab36f5609c909de5c1c26c0e6f380be Mon Sep 17 00:00:00 2001 From: Diego Date: Fri, 26 Jul 2019 15:05:21 -0300 Subject: [PATCH 6/6] Add documentation for resolveUrlLoaderOptions --- index.js | 3 +++ 1 file changed, 3 insertions(+) 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