2017-08-26 14:36:40 -05:00
|
|
|
import fs from 'fs'
|
|
|
|
|
import postcss from 'postcss'
|
2017-08-28 15:02:50 -05:00
|
|
|
import tailwind from '..'
|
2017-10-19 12:00:14 -04:00
|
|
|
import CleanCSS from 'clean-css'
|
2017-08-26 14:36:40 -05:00
|
|
|
|
2017-11-02 13:26:27 -04:00
|
|
|
function buildDistFile(filename) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2018-03-13 09:49:48 -04:00
|
|
|
console.log(`Processing ./${filename}.css...`)
|
2017-08-26 14:36:40 -05:00
|
|
|
|
2018-03-13 09:49:48 -04:00
|
|
|
fs.readFile(`./${filename}.css`, (err, css) => {
|
2017-11-04 01:32:25 -05:00
|
|
|
if (err) throw err
|
|
|
|
|
|
2019-12-23 19:19:13 -05:00
|
|
|
return postcss([tailwind(), require('autoprefixer')])
|
2017-11-02 13:26:27 -04:00
|
|
|
.process(css, {
|
2018-03-13 09:49:48 -04:00
|
|
|
from: `./${filename}.css`,
|
2017-11-02 13:26:27 -04:00
|
|
|
to: `./dist/${filename}.css`,
|
2017-11-05 13:32:02 -06:00
|
|
|
map: { inline: false },
|
2017-11-02 13:26:27 -04:00
|
|
|
})
|
|
|
|
|
.then(result => {
|
|
|
|
|
fs.writeFileSync(`./dist/${filename}.css`, result.css)
|
|
|
|
|
if (result.map) {
|
|
|
|
|
fs.writeFileSync(`./dist/${filename}.css.map`, result.map)
|
|
|
|
|
}
|
|
|
|
|
return result
|
|
|
|
|
})
|
|
|
|
|
.then(result => {
|
|
|
|
|
const minified = new CleanCSS().minify(result.css)
|
|
|
|
|
fs.writeFileSync(`./dist/${filename}.min.css`, minified.styles)
|
|
|
|
|
})
|
|
|
|
|
.then(resolve)
|
|
|
|
|
.catch(error => {
|
|
|
|
|
console.log(error)
|
|
|
|
|
reject()
|
|
|
|
|
})
|
2017-08-26 14:36:40 -05:00
|
|
|
})
|
2017-11-02 13:26:27 -04:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.info('Building Tailwind!')
|
|
|
|
|
|
|
|
|
|
Promise.all([
|
2019-02-11 12:46:19 -05:00
|
|
|
buildDistFile('base'),
|
2018-03-13 09:41:23 -04:00
|
|
|
buildDistFile('components'),
|
2017-11-02 13:26:27 -04:00
|
|
|
buildDistFile('utilities'),
|
2017-11-05 13:32:02 -06:00
|
|
|
buildDistFile('tailwind'),
|
2017-11-02 13:26:27 -04:00
|
|
|
]).then(() => {
|
|
|
|
|
console.log('Finished Building Tailwind!')
|
2017-08-26 14:36:40 -05:00
|
|
|
})
|