diff --git a/lib/index.js b/lib/index.js index eb135a75..6e433f6d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -47,43 +47,43 @@ module.exports = function loader (css, map) { validateOptions(require('./options.json'), options, 'PostCSS Loader') - const rc = { - path: path.dirname(file), - ctx: { - file: { - extname: path.extname(file), - dirname: path.dirname(file), - basename: path.basename(file) - }, - options: {} - } - } + const sourceMap = options.sourceMap - if (options.config) { - if (options.config.path) { - rc.path = path.resolve(options.config.path) - } + Promise.resolve().then(() => { + const length = Object.keys(options) + .filter((option) => { + // if (option === 'exec') return + if (option === 'config') return + if (option === 'sourceMap') return - if (options.config.ctx) { - rc.ctx.options = options.config.ctx + return option + }) + .length + + if (length) { + return parseOptions.call(this, options) } - } - const sourceMap = options.sourceMap + const rc = { + path: path.dirname(file), + ctx: { + file: { + extname: path.extname(file), + dirname: path.dirname(file), + basename: path.basename(file) + }, + options: {} + } + } - Promise.resolve().then(() => { - const length = Object.keys(options).length + if (options.config) { + if (options.config.path) { + rc.path = path.resolve(options.config.path) + } - // TODO - // Refactor - if (!options.config && !sourceMap && length) { - return parseOptions.call(this, options) - } else if (options.config && !sourceMap && length > 1) { - return parseOptions.call(this, options) - } else if (!options.config && sourceMap && length > 1) { - return parseOptions.call(this, options) - } else if (options.config && sourceMap && length > 2) { - return parseOptions.call(this, options) + if (options.config.ctx) { + rc.ctx.options = options.config.ctx + } } return postcssrc(rc.ctx, rc.path, { argv: false })