UNPKG

@wgoo/cli

Version:

Wgoo Cli 是一个 React 组件库构建工具,通过 Wgoo Cli 可以快速搭建一套功能完备的 React 组件库。

53 lines (41 loc) 1.18 kB
const get = require('lodash.get'); const { existsSync } = require('fs'); const { join, isAbsolute } = require('path'); const { getWgooConfig } = require('../common'); const { STYLE_DIR, SRC_DIR } = require('./constant'); /** * @returns 'css' | 'less' | 'scss' */ function getCssLang() { const wgooConfig = getWgooConfig(); const preprocessor = get(wgooConfig, 'build.css.preprocessor', 'less'); if (preprocessor === 'sass') { return 'scss'; } return preprocessor; } const CSS_LANG = getCssLang(); function getCssBaseFile() { const wgooConfig = getWgooConfig(); let path = join(STYLE_DIR, `base.${CSS_LANG}`); const baseFile = get(wgooConfig, 'build.css.base', ''); if (baseFile) { path = isAbsolute(baseFile) ? baseFile : join(SRC_DIR, baseFile); } if (existsSync(path)) { return path; } return null; } const IMPORT_STYLE_RE = /import\s+?(?:(?:".*?")|(?:'.*?'))[\s]*?(?:;|$|)/g; // "import 'a.less';" => "import 'a.css';" function replaceCSSImportExt(code) { return code.replace(IMPORT_STYLE_RE, (str) => str.replace(`.${CSS_LANG}`, '.css') ); } module.exports = { CSS_LANG, getCssBaseFile, replaceCSSImportExt }