diff --git a/index.js b/index.js index 18c81a57..d27b2f1a 100644 --- a/index.js +++ b/index.js @@ -429,11 +429,11 @@ const publicApi = { * // options.includePaths = [...] * }, { * // set optional Encore-specific options - * // resolve_url_loader: true + * // resolveUrlLoader: true * }); * * Supported options: - * * {bool} resolve_url_loader (default=true) + * * {bool} resolveUrlLoader (default=true) * Whether or not to use the resolve-url-loader. * Setting to false can increase performance in some * cases, especially when using bootstrap_sass. But, diff --git a/lib/WebpackConfig.js b/lib/WebpackConfig.js index 3fc12285..3e89a013 100644 --- a/lib/WebpackConfig.js +++ b/lib/WebpackConfig.js @@ -57,16 +57,16 @@ class WebpackConfig { this.useSassLoader = false; this.useReact = false; this.usePreact = false; - this.preactOptions = { - preactCompat: false - }; this.useVueLoader = false; this.useTypeScriptLoader = false; this.useForkedTypeScriptTypeChecking = false; // Features/Loaders options this.sassOptions = { - resolve_url_loader: true + resolveUrlLoader: true + }; + this.preactOptions = { + preactCompat: false }; // Features/Loaders options callbacks @@ -311,11 +311,17 @@ class WebpackConfig { this.sassLoaderOptionsCallback = sassLoaderOptionsCallback; for (const optionKey of Object.keys(options)) { - if (!(optionKey in this.sassOptions)) { - throw new Error(`Invalid option "${optionKey}" passed to enableSassLoader(). Valid keys are ${Object.keys(this.sassOptions).join(', ')}`); + let normalizedOptionKey = optionKey; + if (optionKey === 'resolve_url_loader') { + logger.deprecation('enableSassLoader: "resolve_url_loader" is deprecated. Please use "resolveUrlLoader" instead.'); + normalizedOptionKey = 'resolveUrlLoader'; + } + + if (!(normalizedOptionKey in this.sassOptions)) { + throw new Error(`Invalid option "${normalizedOptionKey}" passed to enableSassLoader(). Valid keys are ${Object.keys(this.sassOptions).join(', ')}`); } - this.sassOptions[optionKey] = options[optionKey]; + this.sassOptions[normalizedOptionKey] = options[optionKey]; } } diff --git a/lib/loaders/sass.js b/lib/loaders/sass.js index 9d157298..ad2ffec1 100644 --- a/lib/loaders/sass.js +++ b/lib/loaders/sass.js @@ -23,7 +23,7 @@ module.exports = { loaderFeatures.ensurePackagesExist('sass'); const sassLoaders = [...cssLoader.getLoaders(webpackConfig, ignorePostCssLoader)]; - if (true === webpackConfig.sassOptions.resolve_url_loader) { + if (true === webpackConfig.sassOptions.resolveUrlLoader) { // responsible for resolving SASS url() paths // without this, all url() paths must be relative to the // entry file, not the file that contains the url() @@ -37,7 +37,7 @@ module.exports = { let config = Object.assign({}, sassOptions, { // needed by the resolve-url-loader - sourceMap: (true === webpackConfig.sassOptions.resolve_url_loader) || webpackConfig.useSourceMaps + sourceMap: (true === webpackConfig.sassOptions.resolveUrlLoader) || webpackConfig.useSourceMaps }); // allow options to be configured diff --git a/lib/logger.js b/lib/logger.js index 5ad9836f..14877dfe 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -15,6 +15,7 @@ const messagesKeys = [ 'debug', 'recommendation', 'warning', + 'deprecation', ]; const defaultConfig = { isVerbose: false, @@ -62,6 +63,12 @@ module.exports = { log(`${chalk.bgYellow.black(' WARNING ')} ${chalk.yellow(message)}`); }, + deprecation(message) { + messages.deprecation.push(message); + + log(`${chalk.bgYellow.black('DEPRECATION')} ${chalk.yellow(message)}`); + }, + getMessages() { return messages; }, diff --git a/test/WebpackConfig.js b/test/WebpackConfig.js index eb117b67..3f49fd68 100644 --- a/test/WebpackConfig.js +++ b/test/WebpackConfig.js @@ -471,10 +471,10 @@ describe('WebpackConfig object', () => { it('Pass valid config', () => { const config = createConfig(); - config.enableSassLoader(() => {}, { resolve_url_loader: false }); + config.enableSassLoader(() => {}, { resolveUrlLoader: false }); expect(config.useSassLoader).to.be.true; - expect(config.sassOptions.resolve_url_loader).to.be.false; + expect(config.sassOptions.resolveUrlLoader).to.be.false; }); it('Pass invalid config', () => { diff --git a/test/loaders/sass.js b/test/loaders/sass.js index 970e49f6..72c63a57 100644 --- a/test/loaders/sass.js +++ b/test/loaders/sass.js @@ -67,7 +67,7 @@ describe('loaders/sass', () => { it('getLoaders() without resolve-url-loader', () => { const config = createConfig(); config.enableSassLoader(() => {}, { - resolve_url_loader: false, + resolveUrlLoader: false, }); config.enableSourceMaps(false); diff --git a/test/logger.js b/test/logger.js index 0a18e5a5..20146c01 100644 --- a/test/logger.js +++ b/test/logger.js @@ -28,12 +28,14 @@ describe('logger', () => { 'debug', 'recommendation', 'warning', + 'deprecation', ]; const testString = 'TEST MESSAGE'; const expectedMessages = { debug: [testString], recommendation: [testString], warning: [testString], + deprecation: [testString], }; logger.quiet();