diff --git a/build/bin/build-style-entry.js b/build/bin/build-style-entry.js index f3f695e39..ddf9e5ae2 100644 --- a/build/bin/build-style-entry.js +++ b/build/bin/build-style-entry.js @@ -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'); diff --git a/packages/vant-css/gulpfile.js b/packages/vant-css/gulpfile.js index 030f048a1..2c4f6bfda 100644 --- a/packages/vant-css/gulpfile.js +++ b/packages/vant-css/gulpfile.js @@ -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'); }); diff --git a/packages/vant-css/src/vant-icon-743c0e.ttf b/packages/vant-css/src/vant-icon-743c0e.ttf deleted file mode 100644 index efcd83914..000000000 Binary files a/packages/vant-css/src/vant-icon-743c0e.ttf and /dev/null differ