Skip to content

Commit 649fb8f

Browse files
committed
Support passing config path via object
1 parent 7877ffa commit 649fb8f

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

__tests__/customConfig.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,33 @@ test('custom config can be passed as an object', () => {
6868
})
6969
})
7070

71+
test('custom config path can be passed using `config` property in an object', () => {
72+
return postcss([tailwind({ config: path.resolve(`${__dirname}/fixtures/custom-config.js`) })])
73+
.process(
74+
`
75+
@responsive {
76+
.foo {
77+
color: blue;
78+
}
79+
}
80+
`,
81+
{ from: undefined }
82+
)
83+
.then(result => {
84+
const expected = `
85+
.foo {
86+
color: blue;
87+
}
88+
@media (min-width: 400px) {
89+
.mobile\\:foo {
90+
color: blue;
91+
}
92+
}
93+
`
94+
expect(result.css).toMatchCss(expected)
95+
})
96+
})
97+
7198
test('tailwind.config.js is picked up by default', () => {
7299
return inTempDirectory(() => {
73100
fs.writeFileSync(

src/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ import { defaultConfigFile } from './constants'
1313
import defaultConfig from '../stubs/defaultConfig.stub.js'
1414

1515
function resolveConfigPath(filePath) {
16-
if (_.isObject(filePath)) {
16+
if (_.isObject(filePath) && !_.has(filePath, 'config')) {
1717
return undefined
1818
}
1919

20+
if (_.isObject(filePath) && _.has(filePath, 'config')) {
21+
return path.resolve(filePath.config)
22+
}
23+
2024
if (!_.isUndefined(filePath)) {
2125
return path.resolve(filePath)
2226
}

0 commit comments

Comments
 (0)