Skip to content

Commit

Permalink
WIP2
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Jan 1, 2021
1 parent f333bd9 commit 70a8bf9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 36 deletions.
50 changes: 30 additions & 20 deletions build/build-css.js
Expand Up @@ -2,48 +2,58 @@

'use strict'

const fs = require('fs')
const fs = require('fs/promises')
const path = require('path')
const postcss = require('postcss')
const glob = require('glob')
const sass = require('sass')
const autoprefixer = require('autoprefixer')
const fiber = require('fibers')
const Cleancss = require('clean-css')

const postcssPlugins = [
autoprefixer({ cascade: false })
]

const files = [
const FILES = [
'bootstrap',
'bootstrap-grid',
'bootstrap-reboot',
'bootstrap-utilities'
]

files.forEach(filename => {
sass.render({
async function processFile(filename) {
const sassOptions = {
file: path.resolve(`./scss/${filename}.scss`),
fiber,
outputStyle: 'expanded',
sourceMap: true,
sourceMapContents: true,
outFile: `./dist/css/${filename}.css`
}, (error, css) => {
// Fix postcss to use and output sourcemaps
postcss(postcssPlugins)
.process(css.css, {
from: `./dist/css/${filename}.css`,
map: `./dist/css/${filename}.css.map`
})
.then(result => {
fs.writeFile(`./dist/css/${filename}.css`, result.css, () => true)
fs.writeFile(`./dist/css/${filename}.css.map`, result.map.toString(), () => true)
fs.writeFile(`./dist/css/${filename}.min.css`, new Cleancss().minify(result.css).styles, () => true)
})
})
})
}

const css = await sass.renderSync(sassOptions)

// Fix postcss to use and output sourcemaps
const processedCss = await postcss(postcssPlugins)
.process(css.css, {
from: `./dist/css/${filename}.css`,
map: `./dist/css/${filename}.css.map`
})

const minifiedCss = await new Cleancss().minify(processedCss.css).styles

await fs.writeFile(`./dist/css/${filename}.css`, processedCss.css)
await fs.writeFile(`./dist/css/${filename}.css.map`, processedCss.map.toString())
await fs.writeFile(`./dist/css/${filename}.min.css`, minifiedCss)
}

(async () => {
try {
await Promise.all(FILES.map(file => processFile(file)))
} catch (error) {
console.error(error)
process.exit(1)
}
})()

// Prefix examples
glob('./site/content/**/*.css', {}, (error, files) => {
Expand Down
15 changes: 0 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Expand Up @@ -107,7 +107,6 @@
"eslint-config-xo": "^0.33.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-unicorn": "^25.0.0",
"fibers": "^5.0.0",
"find-unused-sass-variables": "^3.0.0",
"glob": "^7.1.6",
"hammer-simulator": "0.0.1",
Expand Down

0 comments on commit 70a8bf9

Please sign in to comment.