mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-23 06:59:15 +08:00
[bugfix] missing style entry in dist lib
This commit is contained in:
parent
6d9b3a744c
commit
4179bc45ec
@ -8,34 +8,40 @@ const components = require('./get-components')();
|
||||
const dependencyTree = require('dependency-tree');
|
||||
const SEP = path.sep;
|
||||
|
||||
components.forEach(componentName => {
|
||||
const esDir = path.resolve(__dirname, '../../es');
|
||||
const content = analyzeDependencies(componentName, esDir).map(component => `import '../../vant-css/${component}.css';`);
|
||||
fs.outputFileSync(path.join(esDir, componentName, './style/index.js'), content.join('\n'));
|
||||
});
|
||||
|
||||
// Analyze component dependencies
|
||||
function analyzeDependencies(componentName, esDir) {
|
||||
const checkList = ['base'];
|
||||
const whiteList = ['icon', 'loading', 'cell', 'button'];
|
||||
search(dependencyTree({
|
||||
directory: esDir,
|
||||
filename: path.resolve(esDir, componentName, 'index.js'),
|
||||
filter: path => path.indexOf(`vant${SEP}es${SEP}`) !== -1
|
||||
}), checkList, whiteList);
|
||||
return checkList.filter(component => checkComponentHasStyle(component));
|
||||
}
|
||||
|
||||
function search(tree, checkList, whiteList) {
|
||||
tree && Object.keys(tree).forEach(key => {
|
||||
search(tree[key], checkList, whiteList);
|
||||
const component = key.split(`${SEP}vant${SEP}es${SEP}`)[1].replace(`${SEP}index.js`, '').replace(`mixins${SEP}`, '');
|
||||
if (checkList.indexOf(component) === -1 && whiteList.indexOf(component) === -1) {
|
||||
checkList.push(component);
|
||||
}
|
||||
function build(folder, isESModule) {
|
||||
const dir = path.resolve(__dirname, '../../', folder);
|
||||
components.forEach(componentName => {
|
||||
const content = analyzeDependencies(componentName, dir)
|
||||
.map(component => isESModule ? `import '../../vant-css/${component}.css';` : `require('../../vant-css/${component}.css');`);
|
||||
fs.outputFileSync(path.join(dir, componentName, './style/index.js'), content.join('\n'));
|
||||
});
|
||||
|
||||
// Analyze component dependencies
|
||||
function analyzeDependencies(componentName, dir) {
|
||||
const checkList = ['base'];
|
||||
const whiteList = ['icon', 'loading', 'cell', 'button'];
|
||||
search(dependencyTree({
|
||||
directory: dir,
|
||||
filename: path.resolve(dir, componentName, 'index.js'),
|
||||
filter: path => path.indexOf(`vant${SEP}${folder}${SEP}`) !== -1
|
||||
}), checkList, whiteList);
|
||||
return checkList.filter(component => checkComponentHasStyle(component));
|
||||
}
|
||||
|
||||
function search(tree, checkList, whiteList) {
|
||||
tree && Object.keys(tree).forEach(key => {
|
||||
search(tree[key], checkList, whiteList);
|
||||
const component = key.split(`${SEP}vant${SEP}${folder}${SEP}`)[1].replace(`${SEP}index.js`, '').replace(`mixins${SEP}`, '');
|
||||
if (checkList.indexOf(component) === -1 && whiteList.indexOf(component) === -1) {
|
||||
checkList.push(component);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function checkComponentHasStyle(componentName) {
|
||||
return fs.existsSync(path.join(__dirname, `../../${folder}/vant-css/`, `${componentName}.css`));
|
||||
}
|
||||
}
|
||||
|
||||
function checkComponentHasStyle(componentName) {
|
||||
return fs.existsSync(path.join(__dirname, '../../es/vant-css/', `${componentName}.css`));
|
||||
}
|
||||
build('es', true);
|
||||
build('lib');
|
||||
|
@ -25,6 +25,7 @@ gulp.task('compile', () => {
|
||||
gulp.task('lib', ['compile'], () => {
|
||||
const ttf = glob.sync(resolve('./src/*.ttf'));
|
||||
ttf.forEach(ttf => fs.copy(ttf, './lib/' + path.parse(ttf).base));
|
||||
fs.copy('./lib', '../../lib/vant-css');
|
||||
fs.copy('./lib', '../../es/vant-css');
|
||||
});
|
||||
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user