From 70a8bf98c5c654c003bbf229badbd24f165f2d72 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Fri, 1 Jan 2021 13:09:39 +0200 Subject: [PATCH] WIP2 --- build/build-css.js | 50 +++++++++++++++++++++++++++------------------- package-lock.json | 15 -------------- package.json | 1 - 3 files changed, 30 insertions(+), 36 deletions(-) diff --git a/build/build-css.js b/build/build-css.js index 8345af2db..738b553a9 100644 --- a/build/build-css.js +++ b/build/build-css.js @@ -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) => { diff --git a/package-lock.json b/package-lock.json index 491ca2979..44f82765a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3217,12 +3217,6 @@ "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=", "dev": true }, - "detect-libc": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", - "integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=", - "dev": true - }, "di": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/di/-/di-0.0.1.tgz", @@ -4421,15 +4415,6 @@ "pend": "~1.2.0" } }, - "fibers": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/fibers/-/fibers-5.0.0.tgz", - "integrity": "sha512-UpGv/YAZp7mhKHxDvC1tColrroGRX90sSvh8RMZV9leo+e5+EkRVgCEZPlmXeo3BUNQTZxUaVdLskq1Q2FyCPg==", - "dev": true, - "requires": { - "detect-libc": "^1.0.3" - } - }, "figures": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", diff --git a/package.json b/package.json index 51a24a6bd..3bf674d63 100644 --- a/package.json +++ b/package.json @@ -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",