Skip to content

Commit 75ea045

Browse files
author
Dewyzee
committed
add dev readme
1 parent b7c3d08 commit 75ea045

File tree

199 files changed

+9649
-4348
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+9649
-4348
lines changed

build/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
3+
> 项目组织与开发
4+
5+
## 项目目录
6+
7+
|—— assets // 项目静态资源
8+
|—— build
9+
| ├── template // 快速创建目录模板
10+
| ├── util // 构建公共方法
11+
| ├── build-dev.js // 构建dev模式
12+
| ├── build-prod.js // 构建产出模式
13+
|—— example // 示例目录
14+
|—— src
15+
| ├── components 组件目录
16+
| ├── index.js // 入口文件
17+
|
18+
|—— ...
19+
20+
## 组件开发说明
21+
22+
* 通过``npm run create xxx``命令创建组件目录,目录模板在build下面。xxx是要创建的组件名
23+
24+
* 组件目录中将vue文件与样式文件分离解偶,方便维护与拓展
25+
26+
* examples目录下是mpvue项目,新开发的组件在这里进行调试验证

build/genTemplate.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
const mkdirp = require('mkdirp')
4+
const argv = process.argv
5+
const cwd = process.cwd()
6+
let componentDirName = ''
7+
let destDir = ''
8+
9+
function walkDir(dirPath) {
10+
fs.readdir(dirPath, (err, files) => {
11+
if (err) {
12+
console.error(err)
13+
return
14+
}
15+
files.forEach(filename => {
16+
const fileDir = path.join(dirPath, filename)
17+
fs.stat(fileDir, (error, stats) => {
18+
if (error) {
19+
console.error(error)
20+
return
21+
}
22+
if (stats.isDirectory()) {
23+
walkDir(fileDir)
24+
return
25+
}
26+
let relativePath = path.relative(path.join(cwd, 'build', 'template'), fileDir)
27+
let content = fs.readFileSync(fileDir, 'utf8')
28+
if (path.extname(relativePath).match(/(\.vue|\.less)$/)) {
29+
relativePath = relativePath.replace(/index/, argv[2])
30+
}
31+
else {
32+
content = content.replace(/index/g, argv[2])
33+
}
34+
const fileDistPath = path.join(destDir, relativePath)
35+
const dirname = path.dirname(fileDistPath)
36+
mkdirp.sync(dirname)
37+
fs.writeFileSync(fileDistPath, content, 'utf8')
38+
})
39+
})
40+
})
41+
}
42+
43+
if (argv && argv.length && argv[2]) {
44+
componentDirName = argv[2]
45+
destDir = path.join(cwd, 'src', 'components', componentDirName)
46+
if (fs.existsSync(destDir)) {
47+
throw Error('组件已经存在')
48+
}
49+
walkDir(path.join(cwd, 'build', 'template'))
50+
}
51+
else {
52+
throw Error('组件名称未定义')
53+
}

build/template/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import index from 'index.vue'
2+
3+
export default index

build/template/index.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<div></div>
3+
</template>

build/template/style/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './index.less'

build/template/style/index.less

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@import '../../common/_base.less';
2+
@import '../../common/_mixins.less';

examples/.babelrc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"presets": [
3+
["env", {
4+
"modules": false,
5+
"targets": {
6+
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
7+
}
8+
}],
9+
"stage-2"
10+
],
11+
"plugins": ["transform-runtime"],
12+
"env": {
13+
"test": {
14+
"presets": ["env", "stage-2"],
15+
"plugins": ["istanbul"]
16+
}
17+
}
18+
}

examples/.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

examples/.postcssrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// https://github.com/michael-ciniawsky/postcss-load-config
2+
3+
module.exports = {
4+
"plugins": {
5+
"postcss-mpvue-wxss": {}
6+
}
7+
}

examples/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# examples
2+
3+
> A Mpvue project
4+
5+
## Build Setup
6+
7+
``` bash
8+
# 初始化项目
9+
vue init mpvue/mpvue-quickstart myproject
10+
cd myproject
11+
12+
# 安装依赖
13+
yarn
14+
15+
# 开发时构建
16+
npm dev
17+
18+
# 打包构建
19+
npm build
20+
21+
# 指定平台的开发时构建(微信、百度、头条、支付宝)
22+
npm dev:wx
23+
npm dev:swan
24+
npm dev:tt
25+
npm dev:my
26+
27+
# 指定平台的打包构建
28+
npm build:wx
29+
npm build:swan
30+
npm build:tt
31+
npm build:my
32+
33+
# 生成 bundle 分析报告
34+
npm run build --report
35+
```
36+
37+
For detailed explanation on how things work, checkout the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).

0 commit comments

Comments
 (0)