Skip to content

Commit b267f08

Browse files
committed
update doc
1 parent 302ed4b commit b267f08

File tree

28 files changed

+924
-15
lines changed

28 files changed

+924
-15
lines changed

docs/book.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
],
88
"pluginsConfig": {
99
"github": {
10-
"url": "https://github.com/MMF-FE/vue-typescript/tree/develop"
10+
"url": "https://github.com/MMF-FE/vue-typescript"
1111
}
1212
},
1313
"links": {

docs/en/Api.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Use APIs
2+
Use [axios](https://github.com/mzabriskie/axios) as default http client
3+
4+
## http.ts
5+
6+
**src/api/http.ts** already sealed axios. Right now it only sealed get and post methods inside. Other http request methods can be extended by yourself.
7+
8+
### get
9+
10+
```typescript
11+
function get<T>(url, data?: Types.PlainObject): Promise<T> {
12+
}
13+
```
14+
**T** is the type response data
15+
16+
```typescript
17+
// The /list response data type is {status: number,list: any[]}
18+
{
19+
getList (params: any) {
20+
return get<{
21+
status: number
22+
list: any[]
23+
}>('/list', params)
24+
}
25+
}
26+
```
27+
28+
### post
29+
```typescript
30+
function post<T>(url, data?: Types.PlainObject): Promise<T> {
31+
}
32+
33+
```
34+
35+
## index.ts
36+
**src/api/index.ts** is server-side api configuration. It seperates different modules into several files.
37+
## Use Api in Components
38+
Each Components has **api** property by default, which comes from src/api/index.ts
39+
40+
```typescript
41+
export default class Home extends Vue {
42+
async created () {
43+
// api example
44+
let res = await this.api.getList({})
45+
console.log(res.list)
46+
}
47+
}
48+
49+
```

docs/en/Command.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Commands
2+
```bash
3+
# Start Dev
4+
npm run dev
5+
6+
# Build developing environment
7+
npm run build:dev
8+
9+
# Build sit environment
10+
npm run build:sit
11+
12+
# Build deploy environment
13+
npm run deploy
14+
15+
# Generate svg icons
16+
npm run svg
17+
18+
```
19+
20+
## Add compoents by just one command
21+
Use the script in **./tools/cli.js** to add components. Components templates are under tools/tpl. You can change based on your needs.
22+
23+
```text
24+
Options:
25+
--version, -v show version [boolean]
26+
--help, -h show help manual [boolean]
27+
--type, -t The component type
28+
--root, -r The component root path [default: "src/components"]
29+
```
30+
Default path is **src/components**
31+
```bash
32+
# Add a component,
33+
./tools/cli add [componentPath] -t [componentType]
34+
35+
# use npm script
36+
npm run cli add [componentPath] -- -t [componentType]
37+
38+
# use yarn
39+
yarn cli add [componentPath] -- -t [componentType]
40+
```
41+
### -t
42+
**-t** is used for marking the type of the component. You can add different components by using different -t parameters. Default type is based on the name of folders under componentPath. For example:
43+
44+
```
45+
# component type: view
46+
yarn cli add views/home
47+
48+
# component type: tag
49+
yarn cli add tags/hello
50+
51+
# component type: tag
52+
yarn cli add views/home/list -- -t tag
53+
```
54+
55+
### -r
56+
**-r** the parameter following is for setting the root path. If the components that you want to make is not under **src/components**, you can set the parameter to set the component's path.
57+
58+
```bash
59+
yarn cli add tags/hello -- -r demo/components
60+
```
61+
the command above creates a tag component under demo/components/tags/hello

docs/en/Component.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Components
2+
This template does not use single file component. Each component consists of 4 files. The reason to do like this is because the editor does not support *.vue files well enough.
3+
4+
## Components structrue
5+
6+
```
7+
// for example, we have a components called 'hello'.
8+
├── hello.scss
9+
├── hello.ts
10+
├── hello.vue
11+
└── index.ts
12+
```
13+
14+
## vue file
15+
As you can see, component template is using .vue file rather than .html file. That is because we can use vue-loader to take advantage of vue single file.
16+
17+
```html
18+
<!-- vue file -->
19+
<template>
20+
<div>
21+
<h1>Hello {{name}}</h1>
22+
</div>
23+
</template>
24+
<style src="./hello.scss" lang="scss" scoped></style>
25+
```
26+
27+
## ts file
28+
we use [vue-property-decorator](https://github.com/kaorun343/vue-property-decorator) to write typescript component. For the usage, you can read their document.
29+
30+
```typescript
31+
import Vue from 'components/base'
32+
import { Component, Prop } from 'vue-property-decorator'
33+
import template from './hello.vue'
34+
35+
@Component({
36+
name: 'tag-hello',
37+
mixins: [template] // use mixins to mix vue file functions
38+
})
39+
export default class Hello extends Vue {
40+
// define prop
41+
@Prop({ default: 'World' })
42+
name: string
43+
44+
// computed
45+
get fullname () {
46+
return `hello, ${this.name}`
47+
}
48+
49+
// method
50+
say () {
51+
console.log(this.fullname)
52+
}
53+
}
54+
55+
56+
```
57+
> Attention:[vue-property-decorator](https://github.com/kaorun343/vue-property-decorator) Component decorator is from [vue-class-component](https://github.com/vuejs/vue-class-component), please read the document.
58+
59+
## Styling
60+
Please go to chapter [Styling](./Style.md).
61+
62+
## index.ts
63+
This is component entry file, so that it will be easy for other components to import this component.
64+
65+
```typescript
66+
export * from './hello.ts'
67+
```
68+
69+
The reason we don't name hello.ts as index.ts is considering editor is always showing file name, thus you will never know which component it belongs to.
70+
71+
## Import other components or modules
72+
Import root path is src by default.
73+
74+
```js
75+
// import 'src/components/tags/hello'
76+
import Hello from 'components/tags/hello'
77+
```
78+
If you are using vscode,please consider the following configuration:
79+
```json
80+
{
81+
"editor.quickSuggestions": {
82+
"other": true,
83+
"comments": false,
84+
"strings": true
85+
}
86+
}
87+
```
88+
so when you import module, editor will hint the path.

docs/en/Issues.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Issues
2+
Have quite a few compatible issues When update to vue-loader 13.x 和 webpack3.x. The existing issues are as follow:
3+
4+
### change vue file or style will trigger browser refreshing
5+
This refresh operation is under build/dev-server.js
6+
```js
7+
// force page reload when html-webpack-plugin template changes
8+
compiler.plugin('compilation', function (compilation) {
9+
compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
10+
hotMiddleware.publish({ action: 'reload' })
11+
cb()
12+
})
13+
})
14+
```
15+
Right now we comment this piece of code, so if anything is changed on html under build/tpl, you need to refresh manually.
16+
17+
### production mode does not extract styles into css file
18+
When build production, if you use `require.ensure` to split code, styles in dynamic components are not extracted into css files. Now there is no solution for that.
19+
20+
> You can set `allChunks: true` for `extract-text-webpack-plugin` in `build/webpack.prod.conf.js`, it will extract all styles into one css file.
21+
22+
> refs: https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/120
23+
24+
> If you have any solutions or ideas, please submit [issue](https://github.com/MMF-FE/vue-typescript/issues) or [PR](https://github.com/MMF-FE/vue-typescript/pulls)

docs/en/README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
1-
# Introduction
1+
# Introduction
2+
3+
vue-typescript is base on [vuejs-templates/webpack](https://github.com/vuejs-templates/webpack). Before using `vue-typescript`, it is recommended to look at the [this document](http://vuejs-templates.github.io/webpack/) first.
4+
5+
## Versions
6+
```
7+
vue: 2.x
8+
vue-loader: 13.x
9+
webpack: 3.x
10+
typescript: 2.4+
11+
```
12+
13+
## Quick Start
14+
15+
To use this template, scaffold a project with [vue-cli](https://github.com/vuejs/vue-cli). It is recommended to use npm 3+ for a more efficient dependency tree.
16+
17+
```bash
18+
npm install vue-cli -g
19+
vue init MMF-FE/vue-typescript my-project
20+
cd my-project
21+
npm install
22+
npm run dev
23+
```

docs/en/SUMMARY.MD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
# Summary
22

33
* [Introduction](README.md)
4+
* [Project Structure](Structure.md)
5+
* [Commands](Command.md)
6+
* [Type Definition](Types.md)
7+
* [Component](Component.md)
8+
* [Use Back End Api](Api.md)
9+
* [Styling](Style.md)
10+
* [Vuex](Vuex.md)
11+
* [Test](Test.md)
12+
* [Issues](Issues.md)
413

docs/en/Structure.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Project Structure
2+
```text
3+
.
4+
├── build # Webpack build configuration directroy
5+
│   ├── config # development and production mode config
6+
│   │   ├── index.js
7+
│   ├── tpl # html template
8+
│   │   └── index.html
9+
│   └── ...
10+
├── src
11+
│   ├── api # Backend APIs
12+
│   │   ├── http.ts
13+
│   │   ├── index.ts
14+
│   │   └── modules # API modules
15+
│   │   └── ...
16+
│   ├── assets # module assets (processed by webpack)
17+
│   │   └── svg # svg icons source file
18+
│   │   └── ...
19+
│   ├── components # components
20+
│   │   ├── base.ts # components base. Every component inherits it
21+
│   │   ├── icons # Produced vue svg icons
22+
│   │   ├── pages # Page level components
23+
│   │   ├── tags # Global components (or customized tags)
24+
│   │   └── views # view components
25+
│   ├── env # environment config
26+
│   ├── main.ts # entry file
27+
│   ├── router # router
28+
│   ├── store # vuex store
29+
│   │   ├── modules # vuex modules
30+
│   │   └── utils # vuex utils
31+
│   └── style # styles
32+
├── static # pure static assets (directly copied)
33+
├── tools # Tool, such as cli tools
34+
└── typings # Type definitions
35+
│   ├── globals.d.ts # global types
36+
│   └── interface # interface
37+
├── tsconfig.json # typescript config
38+
├── tslint.json # tslint config
39+
├── .editorconfig # editor config
40+
├── .npmrc # npm config
41+
├── .postcssrc.js # postcss config
42+
├── .stylelintrc.js # stylint config
43+
```

docs/en/Style.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Styling
2+
Use sass(scss) by default. Configuration is under build/utils.js shown as follow:
3+
4+
```js
5+
scss: generateLoaders('sass', {
6+
includePaths: [
7+
path.join(__dirname, '../src/style'),
8+
path.join(__dirname, '../node_modules')
9+
]
10+
})
11+
```
12+
import sass by default is start from src/style or node_modules, so even you have very deep directory structure, it would be easy to import style.
13+
> Attention:If import style from node_modules, please prefix **~**
14+
15+
```scss
16+
@import "base/base"; // import src/style/base/_base.scss
17+
18+
@import "~normalize.css"; // import node_modules/normalize.css
19+
```
20+
21+
## base.scss
22+
src/style/base/_base.scss can only import modules doesn't generate code, such as, variables, mixins, etc.
23+
24+
## Resouce path(assets)
25+
sass import(assets)use [postcss-assets](https://github.com/borodean/postcss-assets) reslove method. By default, root path is src/assets/images. You can modify .postcssrc.js to change or add path.
26+
27+
```js
28+
// .postcssrc.js
29+
module.exports = {
30+
"plugins": {
31+
// to edit target browsers: use "browserlist" field in package.json
32+
// Browser config is in package.json
33+
"autoprefixer": {},
34+
"postcss-assets": {
35+
relative: true,
36+
loadPaths: ['./src/assets/images']
37+
}
38+
}
39+
}
40+
```
41+
42+
```scss
43+
.logo {
44+
// url("src/assets/images/logo.png")
45+
// The address in actually page is produced by webpack
46+
background-image: resolve("logo.png");
47+
}
48+
```
49+
50+
## scoped css
51+
When add components, the default style already enabled css scoped
52+
53+
```html
54+
<style src="./home.scss" lang="scss" scoped></style>
55+
```
56+
The advantage of css scoped is that components styles will not affect other components styles or vice versa, and does not need to change html template like css module. If you want to override child components styles, you can use ** /deep/ **. Here is the example [scoped example](https://github.com/MMF-FE/vue-typescript/blob/master/template/src/components/views/scoped/scoped.scss)
57+
58+
```scss
59+
.parent {
60+
color: red;
61+
62+
/deep/ {
63+
.child {
64+
color: green;
65+
}
66+
}
67+
}
68+
```
69+
> If you don't use sass, you can use **>>>** instead of **/deep/**
70+
> Because using scoped css, please don't use too many nested selector or don't use nested.

docs/en/Test.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Unit Test
2+
Right now we don't add unit test. If you need unit test, please go to [vuejs-webpack](https://github.com/vuejs-templates/webpack).

0 commit comments

Comments
 (0)