mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-25 02:41:46 +08:00
commit
b503369889
91
build/bin/build-lib.js
Normal file
91
build/bin/build-lib.js
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
/**
|
||||||
|
* Build npm lib
|
||||||
|
* Steps:
|
||||||
|
* 1. 清理目录
|
||||||
|
* 2. 构建 JS 入口文件
|
||||||
|
* 3. 打包 JS 文件:vant.js && vant.min.js
|
||||||
|
* 4. 构建 CSS 文件:vant-css
|
||||||
|
* 5. 构建每个组件对应的 [component].js
|
||||||
|
* 6. 生成每个组件目录下的 style 入口
|
||||||
|
* 7. 编译 utils
|
||||||
|
*/
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const components = require('../../components.json');
|
||||||
|
const chalk = require('chalk');
|
||||||
|
require('shelljs/global');
|
||||||
|
|
||||||
|
// clean dir
|
||||||
|
log('Starting', 'clean');
|
||||||
|
exec('npm run clean --silent');
|
||||||
|
log('Finished', 'clean');
|
||||||
|
|
||||||
|
// build entry
|
||||||
|
log('Starting', 'build:entry');
|
||||||
|
exec('npm run build:file --silent');
|
||||||
|
log('Finished', 'build:entry');
|
||||||
|
|
||||||
|
// 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
|
||||||
|
log('Starting', 'build:component');
|
||||||
|
exec('npm run build:components --silent');
|
||||||
|
log('Finished', 'build:component');
|
||||||
|
|
||||||
|
// build vant-css
|
||||||
|
log('Starting', 'build:vant-css');
|
||||||
|
exec('npm run build:vant-css --silent');
|
||||||
|
log('Finished', 'build:vant-css');
|
||||||
|
|
||||||
|
// build style entrys
|
||||||
|
log('Starting', 'build:style-entries');
|
||||||
|
Object.keys(components).forEach((componentName) => {
|
||||||
|
const dir = path.join(__dirname, '../../lib/', componentName, '/style');
|
||||||
|
const file = path.join(dir, 'index.js');
|
||||||
|
const cssPath = path.join(__dirname, '../../lib/vant-css/', `${componentName}.css`);
|
||||||
|
const content = [`require('../../vant-css/base.css');`];
|
||||||
|
if (fs.existsSync(cssPath)) {
|
||||||
|
content.push(`require('../../vant-css/${componentName}.css');`);
|
||||||
|
}
|
||||||
|
mkdir(dir);
|
||||||
|
writeFile(file, content.join('\n'));
|
||||||
|
});
|
||||||
|
log('Finished', 'build:style-entries');
|
||||||
|
|
||||||
|
// build utils
|
||||||
|
log('Starting', 'build:utils');
|
||||||
|
exec('npm run build:utils --silent');
|
||||||
|
log('Finished', 'build:utils');
|
||||||
|
|
||||||
|
// helpers
|
||||||
|
function log(status, action, breakLine) {
|
||||||
|
const now = new Date();
|
||||||
|
const clock = `${breakLine ? '\n' : ''}[${padZero(now.getHours())}:${padZero(now.getMinutes())}:${padZero(now.getSeconds())}]`;
|
||||||
|
console.log(`${chalk.gray(clock)} ${status} '${action ? chalk.cyan.bold(action ) : ''}'`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function padZero(num) {
|
||||||
|
return (num < 10 ? '0' : '') + num;
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeFile(pathname, content) {
|
||||||
|
if (!fs.existsSync(pathname)) {
|
||||||
|
fs.closeSync(fs.openSync(pathname, 'w'));
|
||||||
|
}
|
||||||
|
fs.writeFileSync(pathname, content, { encoding: 'utf8' });
|
||||||
|
}
|
||||||
|
|
||||||
|
function mkdir(pathname) {
|
||||||
|
if (!fs.existsSync(pathname)) {
|
||||||
|
fs.mkdirSync(pathname);
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,12 @@ const webpack = require('webpack');
|
|||||||
|
|
||||||
delete config.devtool;
|
delete config.devtool;
|
||||||
|
|
||||||
config.entry = Components;
|
const entry = {};
|
||||||
|
Object.keys(Components).forEach(key => {
|
||||||
|
entry[key + '/index'] = Components[key];
|
||||||
|
});
|
||||||
|
|
||||||
|
config.entry = entry;
|
||||||
|
|
||||||
config.externals = {
|
config.externals = {
|
||||||
vue: {
|
vue: {
|
||||||
@ -19,8 +24,8 @@ config.externals = {
|
|||||||
config.output = {
|
config.output = {
|
||||||
path: path.join(__dirname, '../lib'),
|
path: path.join(__dirname, '../lib'),
|
||||||
filename: '[name].js',
|
filename: '[name].js',
|
||||||
libraryTarget: 'umd',
|
libraryExport: "default",
|
||||||
umdNamedDefine: true
|
libraryTarget: 'umd'
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = config;
|
module.exports = config;
|
||||||
|
14
package.json
14
package.json
@ -15,13 +15,13 @@
|
|||||||
"dev": "npm run build:file && webpack-dev-server --inline --config build/webpack.config.dev.js --content-base ./",
|
"dev": "npm run build:file && webpack-dev-server --inline --config build/webpack.config.dev.js --content-base ./",
|
||||||
"build:file": "node build/bin/build-entry.js",
|
"build:file": "node build/bin/build-entry.js",
|
||||||
"build:utils": "cross-env BABEL_ENV=utils babel src --out-dir lib --ignore src/index.js",
|
"build:utils": "cross-env BABEL_ENV=utils babel src --out-dir lib --ignore src/index.js",
|
||||||
"build:vant-css": "gulp build --gulpfile packages/vant-css/gulpfile.js && cp -R packages/vant-css/lib/ lib/vant-css",
|
"build:components": "cross-env NODE_ENV=production webpack --progress --hide-modules --config build/webpack.components.js --color",
|
||||||
"build:components": "cross-env NODE_ENV=production webpack --progress --hide-modules --config build/webpack.components.js",
|
"build:vant-css": "gulp build --gulpfile packages/vant-css/gulpfile.js --color && cp -R packages/vant-css/lib/ lib/vant-css",
|
||||||
"build:vant": "cross-env NODE_ENV=production webpack --progress --hide-modules --config build/webpack.build.js && cross-env NODE_ENV=production webpack -p --progress --hide-modules --config build/webpack.build.js",
|
"build:vant": "cross-env NODE_ENV=production webpack --progress --hide-modules --color --config build/webpack.build.js && cross-env NODE_ENV=production webpack -p --progress --hide-modules --color --config build/webpack.build.js",
|
||||||
"deploy": "npm run deploy:docs && npm run deploy:cdn && gh-pages -d docs/dist --remote youzan && rimraf docs/dist",
|
"deploy": "npm run deploy:docs && npm run deploy:cdn && gh-pages -d docs/dist --remote youzan && rimraf docs/dist",
|
||||||
"deploy:cdn": "superman cdn /zanui/vue docs/dist/*.js docs/dist/*.css",
|
"deploy:cdn": "superman cdn /zanui/vue docs/dist/*.js docs/dist/*.css",
|
||||||
"deploy:docs": "rimraf docs/dist && cross-env NODE_ENV=production webpack --progress --hide-modules --config build/webpack.config.prod.js",
|
"deploy:docs": "rimraf docs/dist && cross-env NODE_ENV=production webpack --progress --hide-modules --config build/webpack.config.prod.js",
|
||||||
"dist": "npm run clean && npm run build:file && npm run lint && npm run build:vant && npm run build:components && npm run build:utils && npm run build:vant-css",
|
"dist": "node build/bin/build-lib.js",
|
||||||
"clean": "rimraf lib && rimraf packages/*/lib",
|
"clean": "rimraf lib && rimraf packages/*/lib",
|
||||||
"lint": "felint lint src/**/*.js packages/**/*.{js,vue} build/**/*.js",
|
"lint": "felint lint src/**/*.js packages/**/*.{js,vue} build/**/*.js",
|
||||||
"test": "karma start test/unit/karma.conf.js --single-run",
|
"test": "karma start test/unit/karma.conf.js --single-run",
|
||||||
@ -45,7 +45,7 @@
|
|||||||
"vue-lazyload": "^1.0.6"
|
"vue-lazyload": "^1.0.6"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"vue": "2.3.4"
|
"vue": "2.4.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"autoprefixer": "^7.1.2",
|
"autoprefixer": "^7.1.2",
|
||||||
@ -107,7 +107,7 @@
|
|||||||
"vue-hot-reload-api": "^2.1.0",
|
"vue-hot-reload-api": "^2.1.0",
|
||||||
"vue-html-loader": "^1.2.4",
|
"vue-html-loader": "^1.2.4",
|
||||||
"vue-loader": "^13.0.2",
|
"vue-loader": "^13.0.2",
|
||||||
"vue-markdown-loader": "^1.0.0",
|
"vue-markdown-loader": "^2.0.0",
|
||||||
"vue-router": "^2.7.0",
|
"vue-router": "^2.7.0",
|
||||||
"vue-style-loader": "^3.0.0",
|
"vue-style-loader": "^3.0.0",
|
||||||
"vue-template-compiler": "^2.4.2",
|
"vue-template-compiler": "^2.4.2",
|
||||||
@ -115,6 +115,6 @@
|
|||||||
"webpack": "^3.4.1",
|
"webpack": "^3.4.1",
|
||||||
"webpack-dev-server": "^2.6.1",
|
"webpack-dev-server": "^2.6.1",
|
||||||
"webpack-merge": "^4.1.0",
|
"webpack-merge": "^4.1.0",
|
||||||
"zan-doc": "^0.1.0"
|
"zan-doc": "^0.1.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
packages/vant-css/src/base.css
Normal file
5
packages/vant-css/src/base.css
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
/**
|
||||||
|
* 基本样式入口
|
||||||
|
*/
|
||||||
|
|
||||||
|
@import './reset.css';
|
@ -23,7 +23,7 @@
|
|||||||
@import './tab.css';
|
@import './tab.css';
|
||||||
@import './col.css';
|
@import './col.css';
|
||||||
@import './row.css';
|
@import './row.css';
|
||||||
@import './image_preview.css';
|
@import './image-preview.css';
|
||||||
@import './actionsheet.css';
|
@import './actionsheet.css';
|
||||||
@import './quantity.css';
|
@import './quantity.css';
|
||||||
@import './progress.css';
|
@import './progress.css';
|
||||||
|
12
yarn.lock
12
yarn.lock
@ -7707,9 +7707,9 @@ vue-loader@^13.0.2:
|
|||||||
vue-style-loader "^3.0.0"
|
vue-style-loader "^3.0.0"
|
||||||
vue-template-es2015-compiler "^1.5.3"
|
vue-template-es2015-compiler "^1.5.3"
|
||||||
|
|
||||||
vue-markdown-loader@^1.0.0:
|
vue-markdown-loader@^2.0.0:
|
||||||
version "1.0.0"
|
version "2.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/vue-markdown-loader/-/vue-markdown-loader-1.0.0.tgz#255a2608e388991faa354618e4f4b642ebb7e0db"
|
resolved "https://registry.yarnpkg.com/vue-markdown-loader/-/vue-markdown-loader-2.0.0.tgz#d3cadbf9c8976a81f2d5e39496d505fd4f31bc96"
|
||||||
dependencies:
|
dependencies:
|
||||||
cheerio "^0.20.0"
|
cheerio "^0.20.0"
|
||||||
highlight.js "^9.4.0"
|
highlight.js "^9.4.0"
|
||||||
@ -8043,9 +8043,9 @@ yeast@0.1.2:
|
|||||||
version "0.1.2"
|
version "0.1.2"
|
||||||
resolved "https://registry.yarnpkg.com/yeast/-/yeast-0.1.2.tgz#008e06d8094320c372dbc2f8ed76a0ca6c8ac419"
|
resolved "https://registry.yarnpkg.com/yeast/-/yeast-0.1.2.tgz#008e06d8094320c372dbc2f8ed76a0ca6c8ac419"
|
||||||
|
|
||||||
zan-doc@^0.1.0:
|
zan-doc@^0.1.4:
|
||||||
version "0.1.0"
|
version "0.1.4"
|
||||||
resolved "https://registry.yarnpkg.com/zan-doc/-/zan-doc-0.1.0.tgz#6ea2aba808c39b35b9730899f000dbf05806cbad"
|
resolved "https://registry.yarnpkg.com/zan-doc/-/zan-doc-0.1.4.tgz#e226a438b07ffe1a08706f6349536438fec25f36"
|
||||||
dependencies:
|
dependencies:
|
||||||
cheerio "0.22.0"
|
cheerio "0.22.0"
|
||||||
decamelize "^1.2.0"
|
decamelize "^1.2.0"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user