Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to configure the resolve-url-loader #603

Merged
merged 7 commits into from Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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