UNPKG

gatsby-plugin-purgecss

Version:

Gatsby plugin for purgecss. Removes unused css/sass/less/stylus from files and modules. Supports Tailwindcss, Bootstrap, Bulma etc.

71 lines (70 loc) 2.28 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.normalizePath = exports.color = exports.insertLoader = exports.findLoader = void 0; const path_1 = __importDefault(require("path")); /** * Returns the index of regex matched loaders. null if not found */ const findLoader = (useArray, loaderNamesRegex) => { const index = useArray.findIndex((loaderObject) => { let loaderName = ''; if (typeof loaderObject === 'string') { loaderName = loaderObject; } else if ('loader' in loaderObject && typeof loaderObject.loader === 'string') { loaderName = loaderObject.loader; } return loaderNamesRegex.exec(loaderName) !== null; }); return index === -1 ? undefined : index; }; exports.findLoader = findLoader; /** * Insert given loader at the specified index */ const insertLoader = (useArray, index, loader) => { if (index === undefined) { return; } useArray.splice(index, 0, loader); }; exports.insertLoader = insertLoader; /** * Return Relative Normalized path with forward slash */ const normalizePath = (resourcePath, rootContext) => { const relativePath = resourcePath.replace(path_1.default.normalize(rootContext), ''); const normalizedPath = relativePath.split(path_1.default.sep).join('/'); return normalizedPath; }; exports.normalizePath = normalizePath; const color = { Reset: '\u001B[0m', Bright: '\u001B[1m', Dim: '\u001B[2m', Underscore: '\u001B[4m', Blink: '\u001B[5m', Reverse: '\u001B[7m', Hidden: '\u001B[8m', FgBlack: '\u001B[30m', FgRed: '\u001B[31m', FgGreen: '\u001B[32m', FgYellow: '\u001B[33m', FgBlue: '\u001B[34m', FgMagenta: '\u001B[35m', FgCyan: '\u001B[36m', FgWhite: '\u001B[37m', BgBlack: '\u001B[40m', BgRed: '\u001B[41m', BgGreen: '\u001B[42m', BgYellow: '\u001B[43m', BgBlue: '\u001B[44m', BgMagenta: '\u001B[45m', BgCyan: '\u001B[46m', BgWhite: '\u001B[47m', }; exports.color = color;