[new feature] support es module (#875)
This commit is contained in:
@@ -9,19 +9,19 @@ const dependencyTree = require('dependency-tree');
|
||||
const SEP = path.sep;
|
||||
|
||||
components.forEach(componentName => {
|
||||
const libDir = path.resolve(__dirname, '../../lib');
|
||||
const content = analyzeDependencies(componentName, libDir).map(component => `require('../../vant-css/${component}.css');`);
|
||||
fs.outputFileSync(path.join(libDir, componentName, './style/index.js'), content.join('\n'));
|
||||
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, libDir) {
|
||||
function analyzeDependencies(componentName, esDir) {
|
||||
const checkList = ['base'];
|
||||
const whiteList = ['icon', 'loading', 'cell', 'button'];
|
||||
search(dependencyTree({
|
||||
directory: libDir,
|
||||
filename: path.resolve(libDir, componentName, 'index.js'),
|
||||
filter: path => path.indexOf(`vant${SEP}lib${SEP}`) !== -1
|
||||
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));
|
||||
}
|
||||
@@ -29,7 +29,7 @@ function analyzeDependencies(componentName, libDir) {
|
||||
function search(tree, checkList, whiteList) {
|
||||
tree && Object.keys(tree).forEach(key => {
|
||||
search(tree[key], checkList, whiteList);
|
||||
const component = key.split(`${SEP}vant${SEP}lib${SEP}`)[1].replace(`${SEP}index.js`, '').replace(`mixins${SEP}`, '');
|
||||
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);
|
||||
}
|
||||
@@ -37,5 +37,5 @@ function search(tree, checkList, whiteList) {
|
||||
}
|
||||
|
||||
function checkComponentHasStyle(componentName) {
|
||||
return fs.existsSync(path.join(__dirname, '../../lib/vant-css/', `${componentName}.css`));
|
||||
return fs.existsSync(path.join(__dirname, '../../es/vant-css/', `${componentName}.css`));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user