diff --git a/package.json b/package.json index 8121d129a73d55c119992336045a52a4ddc98d8e..f18cc60d15646dab0b2ac19d7a3bf0b1ac3875ec 100755 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "dependencies": { "@antv/data-set": "^0.8.0", "antd": "^3.7.0", + "antd-pro-merge-less": "^0.0.1", "bizcharts": "^3.1.10", "bizcharts-plugin-slider": "^2.0.3", "classnames": "^2.2.6", diff --git a/scripts/AddlocalIdentName.js b/scripts/AddlocalIdentName.js deleted file mode 100644 index a7764c204220f57a27d874ddca606fa473e7fac6..0000000000000000000000000000000000000000 --- a/scripts/AddlocalIdentName.js +++ /dev/null @@ -1,50 +0,0 @@ -/* eslint-disable */ -const postcss = require('postcss'); -const syntax = require('postcss-less'); - -const LocalIdentNameplugin = postcss.plugin('LocalIdentNameplugin', ({ localIdentName }) => { - return lessAST => { - // loop add localIdentName - const loop = nodes => { - nodes.forEach(item => { - // Not converted :global - if (item.nodes && item.selector !== ':global') { - loop(item.nodes); - } - // 将global的 节点加到 parents - if (item.selector === ':global') { - const parentNodes = item.parent.nodes; - const childrenNodes = item.nodes; - const index = parentNodes.findIndex(node => { - return node.selector === ':global'; - }); - childrenNodes.unshift(index, 1); - Array.prototype.splice.apply(parentNodes, item.nodes); - item.parent.nodes = parentNodes; - return; - } - // 删除 :global(className) 保留 className - if (item.selector) { - if (item.selector.includes(':global(')) { - // converted :global(.className) - const className = item.selector.match(/:global\((\S*)\)/)[1]; - item.selector = className; - return; - } - if (item.selector.includes('(')) { - return; - } - const className = item.selector.replace(/\./g, `.${localIdentName}`); - item.selector = className; - } - }); - }; - loop(lessAST.nodes); - }; -}); - -const AddlocalIdentName = (lessPath, lessText, localIdentName) => { - return postcss([LocalIdentNameplugin({ localIdentName })]).process(lessText, { syntax }); -}; - -module.exports = AddlocalIdentName; diff --git a/scripts/getLocalIdentName.js b/scripts/getLocalIdentName.js deleted file mode 100644 index aa860c7f96df434f03b34e7f484ec9e72add70bb..0000000000000000000000000000000000000000 --- a/scripts/getLocalIdentName.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = path => { - const antdProPath = path.match(/src(.*)/)[1].replace('.less', ''); - const arr = antdProPath - .split('/') - .map(a => a.replace(/([A-Z])/g, '-$1')) - .map(a => a.toLowerCase()); - return `antd-pro${arr.join('-')}-`.replace(/--/g, '-'); -}; diff --git a/scripts/mergeLessPlugin.js b/scripts/mergeLessPlugin.js deleted file mode 100755 index 2e27f372b7f3f8a9b809fb1d1f9c6aa8d8417c5f..0000000000000000000000000000000000000000 --- a/scripts/mergeLessPlugin.js +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env node -/** - * 这个方法用来处理 css-modlue - * 由于没有开源插件,所以自己撸了一个 - */ - -const fs = require('fs'); -const path = require('path'); -const getLocalIdentName = require('./getLocalIdentName'); -const AddlocalIdentName = require('./AddlocalIdentName'); -const replacedefaultLess = require('./replacedefaultLess'); -// read less file list -const lessArray = ['@import "../node_modules/antd/lib/style/themes/default.less";']; - -const loopAllLess = parents => { - const paths = fs.readdirSync(parents); - const promiseList = []; - paths.forEach(itemPath => { - if (itemPath === 'style' || itemPath === 'demo') { - return; - } - // file status - const fileStatus = fs.lstatSync(path.join(parents, itemPath)); - // is file - // is Directory - if (fileStatus.isDirectory()) { - return loopAllLess(path.join(parents, itemPath)); - } - // is less file - if (itemPath.indexOf('.less') > -1) { - const relaPath = path.join(parents, itemPath); - // post css add localIdentNameplugin - const fileContent = replacedefaultLess(relaPath); - // push less file - promiseList.push( - AddlocalIdentName(relaPath, fileContent, getLocalIdentName(relaPath)).then(result => { - lessArray.push(result); - }) - ); - } - }); - return Promise.all(promiseList); -}; - -class mergeLessPlugin { - constructor(options) { - const defaulOptions = { - stylesDir: path.join(__dirname, './src/'), - outFile: path.join(__dirname, './tmp/ant.design.pro.less'), - }; - this.options = Object.assign(defaulOptions, options); - this.generated = false; - } - - apply(compiler) { - const { options } = this; - compiler.plugin('emit', (compilation, callback) => { - const { outFile } = options; - // covert less - if (fs.existsSync(outFile)) { - fs.unlinkSync(outFile); - } else if (!fs.existsSync(path.dirname(outFile))) { - fs.mkdirSync(path.dirname(outFile)); - } - loopAllLess(options.stylesDir).then(() => { - fs.writeFileSync(outFile, lessArray.join('\n')); - callback(); - }); - }); - } -} - -module.exports = mergeLessPlugin; diff --git a/scripts/replacedefaultLess.js b/scripts/replacedefaultLess.js deleted file mode 100644 index a36a4af39911786b284586d1924415d45a58679d..0000000000000000000000000000000000000000 --- a/scripts/replacedefaultLess.js +++ /dev/null @@ -1,11 +0,0 @@ -const fs = require('fs-extra'); - -const replacedefaultLess = lessPath => { - const fileContent = fs.readFileSync(lessPath).toString(); - let lessString = fileContent; - if (lessString.includes("@import '~antd/lib/style/themes/default.less'")) { - lessString = lessString.replace("@import '~antd/lib/style/themes/default.less';", ''); - } - return lessString.replace(/@import '.*\/utils.less';/, ''); -}; -module.exports = replacedefaultLess; diff --git a/src/pages/document.ejs b/src/pages/document.ejs index 7b2a57bf35be9f66e78b29bde7ac1c74707601d4..294ae242aac35a6ed2745126e87dfae7aa88f0b3 100644 --- a/src/pages/document.ejs +++ b/src/pages/document.ejs @@ -8,8 +8,7 @@