fix: change utils && mixins alias

This commit is contained in:
陈嘉涵
2017-08-15 17:27:02 +08:00
parent 711352ae12
commit 72d590d890
31 changed files with 76 additions and 92 deletions

View File

@@ -1,25 +0,0 @@
'use strict';
const components = require('../../components.json');
const execSync = require('child_process').execSync;
const existsSync = require('fs').existsSync;
const path = require('path');
const componentPaths = [];
delete components.font;
Object.keys(components).forEach(key => {
const filePath = path.join(__dirname, `../../packages/${key}/webpack.conf.js`);
if (existsSync(filePath)) {
componentPaths.push(`packages/${key}/webpack.conf.js`);
}
});
const paths = componentPaths.join(',');
const cli = `node_modules/.bin/webpack build -c ${paths} -p`;
execSync(cli, {
stdio: 'inherit'
});

View File

@@ -3,11 +3,12 @@
* Steps:
* 1. 清理目录
* 2. 构建 JS 入口文件
* 3. 打包 JS 文件vant.js && vant.min.js
* 4. 构建 CSS 文件vant-css
* 5. 构建每个组件对应的 [component].js
* 3. 代码格式校验
* 4. 构建每个组件对应的 [component].js
* 5. 构建 vant-css
* 6. 生成每个组件目录下的 style 入口
* 7. 编译 utils
* 8. 打包 JS 文件vant.js && vant.min.js
*/
const fs = require('fs');
@@ -16,37 +17,32 @@ const components = require('../../components.json');
const chalk = require('chalk');
require('shelljs/global');
// clean dir
// 1. clean dir
log('Starting', 'clean');
exec('npm run clean --silent');
log('Finished', 'clean');
// build entry
// 2. build entry
log('Starting', 'build:entry');
exec('npm run build:file --silent');
log('Finished', 'build:entry');
// lint
// 3. lint
log('Starting', 'lint');
exec('npm run lint --silent');
log('Finished', 'lint');
// build vant.js
log('Starting', 'build:vant');
exec('npm run build:vant --silent');
log('Finished', 'build:vant');
// build [component].js
// 4. build [component].js
log('Starting', 'build:component');
exec('npm run build:components --silent');
log('Finished', 'build:component');
// build vant-css
// 5. build vant-css
log('Starting', 'build:vant-css');
exec('npm run build:vant-css --silent');
log('Finished', 'build:vant-css');
// build style entrys
// 6. build style entrys
log('Starting', 'build:style-entries');
Object.keys(components).forEach((componentName) => {
const dir = path.join(__dirname, '../../lib/', componentName, '/style');
@@ -61,11 +57,18 @@ Object.keys(components).forEach((componentName) => {
});
log('Finished', 'build:style-entries');
// build utils
// 7. build utils
log('Starting', 'build:utils');
exec('npm run build:utils --silent');
exec('cross-env BABEL_ENV=utils babel packages/utils --out-dir lib/utils');
exec('cross-env BABEL_ENV=utils babel packages/mixins --out-dir lib/mixins');
log('Finished', 'build:utils');
// 8. build vant.js
log('Starting', 'build:vant');
exec('npm run build:vant --silent');
log('Finished', 'build:vant');
// helpers
function log(status, action, breakLine) {
const now = new Date();

View File

@@ -11,8 +11,8 @@ import componentsConfig from '../components.json';
const extensions = ['.js', '.vue'];
// 打包时排除 mixins、utils、其他组件
const utilsPath = path.resolve(__dirname, '../packages/common/utils/');
const mixinsPath = path.resolve(__dirname, '../packages/common/mixins/');
const utilsPath = path.resolve(__dirname, '../packages/utils/');
const mixinsPath = path.resolve(__dirname, '../packages/mixins/');
const external = [
...fs.readdirSync(utilsPath).map(item => path.resolve(utilsPath, item)),
...fs.readdirSync(mixinsPath).map(item => path.resolve(mixinsPath, item)),
@@ -22,7 +22,7 @@ const external = [
];
export default Object.keys(componentsConfig).map(component => {
return {
const config = {
entry: componentsConfig[component],
targets: [
{
@@ -33,29 +33,33 @@ export default Object.keys(componentsConfig).map(component => {
external: [
'vue',
'vue-lazyload',
path.resolve(__dirname, '../packages/common/mixins/popup/index.js'),
path.resolve(__dirname, '../packages/mixins/popup/index.js'),
...external
],
plugins: [
vue(),
filesize(),
babel({
externalHelpers: true
commonjs({
extensions
}),
resolve({
main: true,
jsnext: true,
extensions
}),
commonjs({
extensions
}),
alias({
resolve: extensions,
'src/mixins': path.resolve(__dirname, '../packages/common/mixins'),
'src/utils': path.resolve(__dirname, '../packages/common/utils'),
packages: path.resolve(__dirname, '../packages')
})
]
};
// button 使用 jsx需要借助 babel
if (component === 'button') {
config.plugins.unshift(babel({
runtimeHelpers: true
}));
}
return config;
});

View File

@@ -38,8 +38,6 @@ module.exports = {
extensions: ['.js', '.vue', '.css'],
alias: {
vue: 'vue/dist/vue.runtime.esm.js',
'src/mixins': path.resolve(__dirname, '../packages/common/mixins'),
'src/utils': path.resolve(__dirname, '../packages/common/utils'),
packages: path.join(__dirname, '../packages'),
lib: path.join(__dirname, '../lib'),
components: path.join(__dirname, '../docs/src/components')