diff --git a/__tests__/mergeConfig.test.js b/__tests__/mergeConfig.test.js deleted file mode 100644 index 3592129d7..000000000 --- a/__tests__/mergeConfig.test.js +++ /dev/null @@ -1,83 +0,0 @@ -import mergeConfig from '../src/util/mergeConfig' - -/** - * Tests - */ -it('replaces simple top level keys', () => { - const defaultConfig = { - colors: { - 'red': '#f25451', - 'green-light': '#b1f3be', - 'blue-dark': '#3687c8', - 'indigo': '#6574cd', - } - } - const userConfig = { - colors: { - 'orange': '#ffb82b', - 'green': '#57d06f', - 'blue': '#4aa2ea', - 'indigo-dark': '#4957a5', - } - } - expect(mergeConfig(defaultConfig, userConfig)).toMatchObject(userConfig) -}) - -it('merges keys found in the "extend" section', () => { - const defaultConfig = { - colors: { - 'red': '#f25451', - }, - text: { - sizes: { - 'base': '1rem', - 'lg': '1.25rem', - } - }, - spacing: { - padding: { - '0': '0', - '1': '0.25rem', - '2': '0.5rem', - } - } - } - const userConfig = { - extend: { - colors: { - 'blue': '#4aa2ea', - }, - text: { - sizes: { - 'xl': '1.5rem' - } - }, - spacing: { - padding: { - '10': '2.5rem' - } - } - } - } - expect(mergeConfig(defaultConfig, userConfig)).toMatchObject({ - colors: { - 'red': '#f25451', - 'blue': '#4aa2ea', - }, - text: { - sizes: { - 'base': '1rem', - 'lg': '1.25rem', - 'xl': '1.5rem', - } - }, - spacing: { - padding: { - '0': '0', - '1': '0.25rem', - '2': '0.5rem', - '10': '2.5rem', - } - } - }) -}) diff --git a/src/build.js b/src/build.js index 1d0d8f5e9..f6723070b 100644 --- a/src/build.js +++ b/src/build.js @@ -1,13 +1,12 @@ import fs from 'fs' import postcss from 'postcss' import tailwind from '..' -import defaultConfig from '../defaultConfig' import CleanCSS from 'clean-css' console.info('Building Tailwind!') fs.readFile('./css/tailwind.css', (err, css) => { - postcss([tailwind(defaultConfig)]) + postcss([tailwind()]) .process(css, { from: './css/tailwind.css', to: './dist/tailwind.css', diff --git a/src/index.js b/src/index.js index 22a3e6081..55881e16c 100644 --- a/src/index.js +++ b/src/index.js @@ -6,7 +6,6 @@ import postcss from 'postcss' import stylefmt from 'stylefmt' import defaultConfig from '../defaultConfig' -import mergeConfig from './util/mergeConfig' import substituteResetAtRule from './lib/substituteResetAtRule' import evaluateTailwindFunctions from './lib/evaluateTailwindFunctions' @@ -17,13 +16,11 @@ import substituteResponsiveAtRules from './lib/substituteResponsiveAtRules' import substituteScreenAtRules from './lib/substituteScreenAtRules' import substituteClassApplyAtRules from './lib/substituteClassApplyAtRules' -const plugin = postcss.plugin('tailwind', (options = {}) => { - if (_.isString(options)) { - options = require(path.resolve(options)) +const plugin = postcss.plugin('tailwind', (config = defaultConfig) => { + if (_.isString(config)) { + config = require(path.resolve(config)) } - const config = mergeConfig(defaultConfig, options) - return postcss([ substituteResetAtRule(config), evaluateTailwindFunctions(config), diff --git a/src/util/mergeConfig.js b/src/util/mergeConfig.js deleted file mode 100644 index e83ea5310..000000000 --- a/src/util/mergeConfig.js +++ /dev/null @@ -1,65 +0,0 @@ -import _ from 'lodash' - -const configTemplate = { - screens: null, - colors: null, - text: { - fonts: null, - sizes: null, - weights: null, - leading: null, - tracking: null, - colors: null, - }, - backgrounds: { - colors: null, - }, - borders: { - widths: null, - colors: null, - }, - radiuses: null, - sizing: { - width: null, - height: null, - minHeight: null, - maxHeight: null, - minWidth: null, - maxWidth: null, - }, - spacing: { - padding: null, - margin: null, - negativeMargin: null, - }, - shadows: null, - zIndex: null, - opacity: null, -} - -function replaceDefaults(template, defaults, replacements) { - return Object.keys(template).reduce((merged, key) => { - const value = template[key] - - if (_.isPlainObject(value)) { - merged[key] = replaceDefaults(value, _.get(defaults, key), _.get(replacements, key)) - } else { - merged[key] = _.get(replacements, key, _.get(defaults, key)) - } - - return merged - }, {}) -} - -function appendConfig(base, appends) { - return _.mergeWith({}, base, appends, (baseValue, appendsValue) => { - if (_.isArray(baseValue)) { - return baseValue.concat(appendsValue); - } - }) -} - -export default function mergeConfig(base, other) { - const replaced = replaceDefaults(configTemplate, base, other) - return appendConfig(replaced, _.get(other, 'extend', {})) -}