Skip to content

Commit 92ffe40

Browse files
authored
Merge pull request #1861 from OwenMelbz/master
Allows users to use "tailwind build" without requiring an input file
2 parents 9b21133 + 3febffd commit 92ffe40

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

__tests__/cli.test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,20 @@ describe('cli', () => {
4343
})
4444

4545
describe('build', () => {
46-
it('compiles CSS file', () => {
46+
it('compiles CSS file using an input css file', () => {
4747
return cli(['build', inputCssPath]).then(() => {
4848
expect(process.stdout.write.mock.calls[0][0]).toContain('.example')
4949
})
5050
})
5151

52+
it('compiles CSS file without an input css file', () => {
53+
return cli(['build']).then(() => {
54+
expect(process.stdout.write.mock.calls[0][0]).toContain('normalize.css') // base
55+
expect(process.stdout.write.mock.calls[0][0]).toContain('.container') // components
56+
expect(process.stdout.write.mock.calls[0][0]).toContain('.mx-auto') // utilities
57+
})
58+
})
59+
5260
it('compiles CSS file using custom configuration', () => {
5361
return cli(['build', inputCssPath, '--config', customConfigPath]).then(() => {
5462
expect(process.stdout.write.mock.calls[0][0]).toContain('400px')

src/cli/commands/build.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ function buildToFile(compileOptions, startTime) {
8080

8181
utils.header()
8282
utils.log()
83-
utils.log(emoji.go, 'Building...', colors.file(inputFileSimplePath))
83+
utils.log(
84+
emoji.go,
85+
'Building...',
86+
colors.file(inputFileSimplePath || 'defaults: @base, @components and @utilities.')
87+
)
8488

8589
return compile(compileOptions).then(result => {
8690
utils.writeFile(compileOptions.outputFile, result.css)
@@ -112,8 +116,9 @@ export function run(cliParams, cliOptions) {
112116
const inputFileSimplePath = utils.getSimplePath(inputFile)
113117
const configFileSimplePath = utils.getSimplePath(configFile)
114118

115-
!inputFile && stopWithHelp('CSS file is required.')
116-
!utils.exists(inputFile) && stop(colors.file(inputFileSimplePath), 'does not exist.')
119+
if (inputFile) {
120+
!utils.exists(inputFile) && stop(colors.file(inputFileSimplePath), 'does not exist.')
121+
}
117122

118123
configFile &&
119124
!utils.exists(configFile) &&

src/cli/compile.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ const defaultOptions = {
2525
*/
2626
export default function compile(options = {}) {
2727
const config = { ...defaultOptions, ...options }
28-
const css = utils.readFile(config.inputFile)
28+
29+
const css = config.inputFile
30+
? utils.readFile(config.inputFile)
31+
: `
32+
@tailwind base;
33+
@tailwind components;
34+
@tailwind utilities;
35+
`
2936

3037
return new Promise((resolve, reject) => {
3138
postcss(config.plugins)

0 commit comments

Comments
 (0)