├── .editorconfig
├── .gitattributes
├── .github
├── FUNDING.yml
└── workflows
│ └── deploy.yml
├── .gitignore
├── LICENSE
├── README.md
├── build
└── deploy.js
├── chapter1
├── 1.html
├── 2.html
├── 3.html
└── 4.html
├── chapter2
├── 1
│ ├── .gitignore
│ ├── build.js
│ ├── index.html
│ ├── package.json
│ ├── src
│ │ ├── app.js
│ │ ├── app.scss
│ │ └── logo.jpg
│ └── webpack.config.js
├── 2
│ ├── .babelrc
│ ├── .gitignore
│ ├── build.js
│ ├── index.html
│ ├── package.json
│ ├── src
│ │ ├── app.js
│ │ ├── hello1.vue
│ │ ├── hello2.vue
│ │ └── styles
│ │ │ └── _var.scss
│ └── webpack.config.js
├── 3
│ ├── .babelrc
│ ├── .gitignore
│ ├── build.js
│ ├── index.html
│ ├── package.json
│ ├── src
│ │ ├── app.js
│ │ ├── hello1.vue
│ │ ├── hello2.vue
│ │ ├── info.js
│ │ ├── styles
│ │ │ ├── _var.scss
│ │ │ └── app.scss
│ │ └── utils.js
│ └── webpack.config.js
└── 4
│ ├── .babelrc
│ ├── .eslintrc.js
│ ├── .gitignore
│ ├── index.html
│ ├── package.json
│ ├── src
│ ├── app.js
│ ├── hello1.vue
│ ├── hello2.vue
│ ├── info.js
│ ├── styles
│ │ ├── _var.scss
│ │ └── app.scss
│ └── utils.js
│ └── webpack.config.js
├── chapter3
├── vue-router
│ ├── hash
│ │ ├── .babelrc
│ │ ├── .editorconfig
│ │ ├── .eslintignore
│ │ ├── .eslintrc.js
│ │ ├── .gitignore
│ │ ├── .postcssrc.js
│ │ ├── README.md
│ │ ├── build
│ │ │ ├── build.js
│ │ │ ├── check-versions.js
│ │ │ ├── logo.png
│ │ │ ├── utils.js
│ │ │ ├── vue-loader.conf.js
│ │ │ ├── webpack.base.conf.js
│ │ │ ├── webpack.dev.conf.js
│ │ │ └── webpack.prod.conf.js
│ │ ├── config
│ │ │ ├── dev.env.js
│ │ │ ├── index.js
│ │ │ └── prod.env.js
│ │ ├── index.html
│ │ ├── package.json
│ │ ├── src
│ │ │ ├── assets
│ │ │ │ └── logo.png
│ │ │ ├── components
│ │ │ │ └── router-link.vue
│ │ │ ├── layout
│ │ │ │ └── index.vue
│ │ │ ├── main.js
│ │ │ ├── pages
│ │ │ │ ├── 404.vue
│ │ │ │ ├── HelloWorld.vue
│ │ │ │ └── Home.vue
│ │ │ └── routes.js
│ │ ├── static
│ │ │ └── .gitkeep
│ │ └── yarn.lock
│ ├── history
│ │ ├── .babelrc
│ │ ├── .editorconfig
│ │ ├── .eslintignore
│ │ ├── .eslintrc.js
│ │ ├── .gitignore
│ │ ├── .postcssrc.js
│ │ ├── README.md
│ │ ├── build
│ │ │ ├── build.js
│ │ │ ├── check-versions.js
│ │ │ ├── logo.png
│ │ │ ├── utils.js
│ │ │ ├── vue-loader.conf.js
│ │ │ ├── webpack.base.conf.js
│ │ │ ├── webpack.dev.conf.js
│ │ │ └── webpack.prod.conf.js
│ │ ├── config
│ │ │ ├── dev.env.js
│ │ │ ├── index.js
│ │ │ └── prod.env.js
│ │ ├── index.html
│ │ ├── package.json
│ │ ├── src
│ │ │ ├── assets
│ │ │ │ └── logo.png
│ │ │ ├── components
│ │ │ │ └── router-link.vue
│ │ │ ├── layout
│ │ │ │ └── index.vue
│ │ │ ├── main.js
│ │ │ ├── pages
│ │ │ │ ├── 404.vue
│ │ │ │ ├── HelloWorld.vue
│ │ │ │ └── Home.vue
│ │ │ └── routes.js
│ │ ├── static
│ │ │ └── .gitkeep
│ │ └── yarn.lock
│ └── simple
│ │ ├── .babelrc
│ │ ├── .editorconfig
│ │ ├── .eslintignore
│ │ ├── .eslintrc.js
│ │ ├── .gitignore
│ │ ├── .postcssrc.js
│ │ ├── README.md
│ │ ├── build
│ │ ├── build.js
│ │ ├── check-versions.js
│ │ ├── logo.png
│ │ ├── utils.js
│ │ ├── vue-loader.conf.js
│ │ ├── webpack.base.conf.js
│ │ ├── webpack.dev.conf.js
│ │ └── webpack.prod.conf.js
│ │ ├── config
│ │ ├── dev.env.js
│ │ ├── index.js
│ │ └── prod.env.js
│ │ ├── index.html
│ │ ├── package.json
│ │ ├── src
│ │ ├── assets
│ │ │ └── logo.png
│ │ ├── layout
│ │ │ └── index.vue
│ │ ├── main.js
│ │ └── pages
│ │ │ ├── 404.vue
│ │ │ ├── HelloWorld.vue
│ │ │ └── Home.vue
│ │ ├── static
│ │ └── .gitkeep
│ │ └── yarn.lock
└── vue-state
│ ├── 1
│ ├── .babelrc
│ ├── .editorconfig
│ ├── .eslintignore
│ ├── .eslintrc.js
│ ├── .gitignore
│ ├── .postcssrc.js
│ ├── README.md
│ ├── build
│ │ ├── build.js
│ │ ├── check-versions.js
│ │ ├── logo.png
│ │ ├── utils.js
│ │ ├── vue-loader.conf.js
│ │ ├── webpack.base.conf.js
│ │ ├── webpack.dev.conf.js
│ │ └── webpack.prod.conf.js
│ ├── config
│ │ ├── dev.env.js
│ │ ├── index.js
│ │ └── prod.env.js
│ ├── index.html
│ ├── package.json
│ ├── src
│ │ ├── App.vue
│ │ ├── components
│ │ │ ├── comp1.vue
│ │ │ └── comp2.vue
│ │ ├── main.js
│ │ └── state.js
│ ├── static
│ │ └── .gitkeep
│ └── yarn.lock
│ ├── 2
│ ├── .babelrc
│ ├── .editorconfig
│ ├── .eslintignore
│ ├── .eslintrc.js
│ ├── .gitignore
│ ├── .postcssrc.js
│ ├── README.md
│ ├── build
│ │ ├── build.js
│ │ ├── check-versions.js
│ │ ├── logo.png
│ │ ├── utils.js
│ │ ├── vue-loader.conf.js
│ │ ├── webpack.base.conf.js
│ │ ├── webpack.dev.conf.js
│ │ └── webpack.prod.conf.js
│ ├── config
│ │ ├── dev.env.js
│ │ ├── index.js
│ │ └── prod.env.js
│ ├── index.html
│ ├── package.json
│ ├── src
│ │ ├── App.vue
│ │ ├── components
│ │ │ ├── comp1.vue
│ │ │ └── comp2.vue
│ │ ├── main.js
│ │ └── state.js
│ ├── static
│ │ └── .gitkeep
│ └── yarn.lock
│ └── 3
│ ├── .babelrc
│ ├── .editorconfig
│ ├── .eslintignore
│ ├── .eslintrc.js
│ ├── .gitignore
│ ├── .postcssrc.js
│ ├── README.md
│ ├── build
│ ├── build.js
│ ├── check-versions.js
│ ├── logo.png
│ ├── utils.js
│ ├── vue-loader.conf.js
│ ├── webpack.base.conf.js
│ ├── webpack.dev.conf.js
│ └── webpack.prod.conf.js
│ ├── config
│ ├── dev.env.js
│ ├── index.js
│ └── prod.env.js
│ ├── index.html
│ ├── package.json
│ ├── src
│ ├── App.vue
│ ├── components
│ │ ├── comp1.vue
│ │ └── comp2.vue
│ ├── main.js
│ └── state.js
│ ├── static
│ └── .gitkeep
│ └── yarn.lock
├── chapter4
├── 1
│ ├── .babelrc
│ ├── .editorconfig
│ ├── .eslintignore
│ ├── .eslintrc.js
│ ├── .gitignore
│ ├── .postcssrc.js
│ ├── README.md
│ ├── build
│ │ ├── build.js
│ │ ├── check-versions.js
│ │ ├── logo.png
│ │ ├── utils.js
│ │ ├── vue-loader.conf.js
│ │ ├── webpack.base.conf.js
│ │ ├── webpack.dev.conf.js
│ │ └── webpack.prod.conf.js
│ ├── config
│ │ ├── dev.env.js
│ │ ├── index.js
│ │ └── prod.env.js
│ ├── index.html
│ ├── package.json
│ ├── src
│ │ ├── App.vue
│ │ ├── components
│ │ │ ├── comp1.vue
│ │ │ ├── comp2.vue
│ │ │ └── comp3.vue
│ │ ├── main.js
│ │ ├── router
│ │ │ └── index.js
│ │ ├── store
│ │ │ └── index.js
│ │ └── views
│ │ │ └── index.vue
│ ├── static
│ │ └── .gitkeep
│ └── yarn.lock
├── 2
│ ├── .babelrc
│ ├── .editorconfig
│ ├── .eslintignore
│ ├── .eslintrc.js
│ ├── .gitignore
│ ├── .postcssrc.js
│ ├── README.md
│ ├── build
│ │ ├── build.js
│ │ ├── check-versions.js
│ │ ├── logo.png
│ │ ├── utils.js
│ │ ├── vue-loader.conf.js
│ │ ├── webpack.base.conf.js
│ │ ├── webpack.dev.conf.js
│ │ └── webpack.prod.conf.js
│ ├── config
│ │ ├── dev.env.js
│ │ ├── index.js
│ │ └── prod.env.js
│ ├── index.html
│ ├── package.json
│ ├── src
│ │ ├── App.vue
│ │ ├── components
│ │ │ ├── comp1.vue
│ │ │ ├── comp2.vue
│ │ │ └── comp3.vue
│ │ ├── main.js
│ │ ├── mixins
│ │ │ ├── func.js
│ │ │ └── log.js
│ │ ├── router
│ │ │ └── index.js
│ │ ├── store
│ │ │ └── index.js
│ │ └── views
│ │ │ └── index.vue
│ ├── static
│ │ └── .gitkeep
│ └── yarn.lock
└── 3
│ ├── .babelrc
│ ├── .editorconfig
│ ├── .eslintignore
│ ├── .eslintrc.js
│ ├── .gitignore
│ ├── .postcssrc.js
│ ├── README.md
│ ├── build
│ ├── build.js
│ ├── check-versions.js
│ ├── logo.png
│ ├── utils.js
│ ├── vue-loader.conf.js
│ ├── webpack.base.conf.js
│ ├── webpack.dev.conf.js
│ └── webpack.prod.conf.js
│ ├── config
│ ├── dev.env.js
│ ├── index.js
│ └── prod.env.js
│ ├── index.html
│ ├── package.json
│ ├── src
│ ├── App.vue
│ ├── lang
│ │ ├── index.js
│ │ └── modules
│ │ │ ├── index.js
│ │ │ ├── login.js
│ │ │ └── order.js
│ ├── main.js
│ ├── router
│ │ └── index.js
│ └── views
│ │ └── index.vue
│ ├── static
│ └── .gitkeep
│ └── yarn.lock
├── docs
├── .vuepress
│ ├── components
│ │ └── AboutLayout.vue
│ ├── config.js
│ ├── override.styl
│ ├── public
│ │ ├── alipay.jpg
│ │ ├── logo.jpg
│ │ ├── logo.png
│ │ ├── wechat.jpg
│ │ └── you-may-not-know-vuejs.png
│ └── theme
│ │ └── Layout.vue
├── README.md
├── about
│ └── README.md
├── art
│ ├── README.md
│ ├── you-may-not-know-vuejs-1.md
│ ├── you-may-not-know-vuejs-10.md
│ ├── you-may-not-know-vuejs-11.md
│ ├── you-may-not-know-vuejs-12.md
│ ├── you-may-not-know-vuejs-13.md
│ ├── you-may-not-know-vuejs-14.md
│ ├── you-may-not-know-vuejs-15.md
│ ├── you-may-not-know-vuejs-2.md
│ ├── you-may-not-know-vuejs-3.md
│ ├── you-may-not-know-vuejs-4.md
│ ├── you-may-not-know-vuejs-5.md
│ ├── you-may-not-know-vuejs-6.md
│ ├── you-may-not-know-vuejs-7.md
│ ├── you-may-not-know-vuejs-8.md
│ └── you-may-not-know-vuejs-9.md
└── donate
│ └── README.md
├── package.json
└── yarn.lock
/.editorconfig:
--------------------------------------------------------------------------------
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
10 |
11 | [*.md]
12 | trim_trailing_whitespace = false
13 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.sh linguist-language=js
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
13 | custom: ['https://github.com/yugasun/buy-me-a-coffee']
14 |
--------------------------------------------------------------------------------
/.github/workflows/deploy.yml:
--------------------------------------------------------------------------------
1 | name: Deploy
2 |
3 | on:
4 | push:
5 | branches: [master]
6 |
7 | jobs:
8 | deploy:
9 | name: Deploy
10 | runs-on: ubuntu-latest
11 | env:
12 | GH_TOKEN: ${{ secrets.GH_TOKEN }}
13 | steps:
14 | - name: Checkout repository
15 | uses: actions/checkout@v2
16 | with:
17 | persist-credentials: false
18 |
19 | - name: Install Node.js and npm
20 | uses: actions/setup-node@v1
21 | with:
22 | node-version: 14.x
23 | registry-url: https://registry.npmjs.org
24 |
25 | - name: Retrieve dependencies from cache
26 | id: cacheNpm
27 | uses: actions/cache@v2
28 | with:
29 | path: |
30 | ~/.npm
31 | node_modules
32 | key: npm-v14-${{ runner.os }}-refs/heads/master-${{ hashFiles('package.json') }}
33 | restore-keys: npm-v14-${{ runner.os }}-refs/heads/master-
34 |
35 | - name: Install dependencies
36 | if: steps.cacheNpm.outputs.cache-hit != 'true'
37 | run: |
38 | npm update --no-save
39 | npm update --save-dev --no-save
40 | - name: Releasing
41 | run: |
42 | npm run deploy
43 | env:
44 | GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
45 | GIT_AUTHOR_NAME: yugasun
46 | GIT_AUTHOR_EMAIL: yuga_sun@163.com
47 | GIT_COMMITTER_NAME: yugasun
48 | GIT_COMMITTER_EMAIL: yuga_sun@163.com
49 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | *.log
3 | dist
4 | docx
5 | .history
6 | .DS_Store
7 | .vscode
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Yuga Sun
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 你也许不知道的 Vuejs
2 |
3 | 
4 |
5 | 《你可能不知道的Vuejs》系列文章是本人在过去时间里,从完全不知道 Vuejs 到熟练地使用 Vuejs 开发各种复杂的大型项目,从不同项目开发实践中总结的一些经验和技巧类文章。重点带你一步步熟悉如何使用Vuejs来开发基本的项目,包括周边生态中,一些较热门工具的使用和技巧,同时也会分享当面对较复杂功能需求时候,如何去分析和处理的过程。
6 |
7 | ## 我为什么要写这个系列
8 |
9 | 虽然网上各种有关Vuejs实践的文章和书籍琳琅满目,[Vuejs官网教程](https://cn.vuejs.org/v2/guide/) (Vuejs官方教程是我见过的最好的文档了,没有之一,建议大家在使用Vuejs之前,还是先去通读一遍。) 也非常详细,但是还是偶尔有很多朋友问我一些Vuejs相关的问题,我感到很奇怪,有那么多的文章来知道如何使用,为什么还是会有这样那样的问题呢?仔细想想也不意外了,发现他们有些人,一开始就直接使用官方 [webpack模板](https://github.com/vuejs-templates/webpack)来开发项目,[webpack](https://github.com/webpack/webpack) 都还没熟悉呢,遇到问题,就直直接蒙了,不知道从何下手,当然搜索引擎几乎可以帮你解决一切问题,但还是会花费你很多时间去弥补你对未知知识的缺失。
10 |
11 | 所以我还是决定写这个系列文章,本人不是大神,只是希望通过写这个系列文章,能够帮助到刚入门Vuejs的朋友,同时也对自己的知识进行梳理和总结。
12 |
13 | ## 序言
14 |
15 | 本系列文章将从像使用 `jquery` 那样使用 `Vuejs` 开始,然后通过循序渐进的学习,之后再慢慢引入 `webpack`,当然文章中也会顺带讲解一些ES6语法。最后会拿出一个项目实例来剖析和讲解一些使用技巧。
16 |
17 | 内容包括什么?
18 |
19 | 1. Vuejs的基本特性介绍及用法
20 | 2. Vuejs的高级用法
21 | 3. Vuejs结合webpack进行开发
22 | 4. 使用ES6语法快乐的玩耍Vuejs
23 | 5. Vuejs最佳实践
24 | 6. Vuejs项目实战
25 |
26 | 因为本文是开篇,所以在写作过程中,有可能内容会有所变动,也会根据读者的反馈和指正进行相应修改,但是大体内容还是按照上面的思路进行的。
27 |
28 | 本系列所有文章相关源码都github上找到:[You May Not Know Vuejs](https://github.com/yugasun/You-May-Not-Know-Vuejs)
29 |
30 | ## 最后
31 |
32 | 因为个人经验有限,文章难免会有所纰漏,欢迎大侠批评指正。
33 |
34 | ## 在线阅读
35 |
36 | * [专题站](https://yugasun.github.io/You-May-Not-Know-Vuejs/)
37 | * [掘金专栏](https://juejin.im/user/583b9227ac502e006c25d1a7/posts)
38 |
--------------------------------------------------------------------------------
/build/deploy.js:
--------------------------------------------------------------------------------
1 | const path = require("path");
2 | const ghpages = require("gh-pages");
3 |
4 | const ghDir = path.join(__dirname, "..", "docs/.vuepress/dist");
5 | ghpages.publish(ghDir, function(err) {
6 | if (err) {
7 | console.log(err);
8 | }
9 | });
10 |
--------------------------------------------------------------------------------
/chapter1/1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | You Don't Know Vuejs - Chapter 1
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/chapter2/1/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | yarn.lock
3 | package-lock.json
4 |
--------------------------------------------------------------------------------
/chapter2/1/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Vue webpack demo
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/chapter2/1/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-webpack-demo",
3 | "version": "0.0.1",
4 | "description": "vue+webpack project demo",
5 | "main": "index.js",
6 | "scripts": {
7 | "dev": "webpack-dev-server",
8 | "build": "webpack --progress --colors"
9 | },
10 | "keywords": [
11 | "vue",
12 | "webpack"
13 | ],
14 | "author": "yugasun",
15 | "license": "MIT",
16 | "dependencies": {
17 | "vue": "^2.5.13"
18 | },
19 | "devDependencies": {
20 | "css-loader": "^0.28.9",
21 | "node-sass": "^4.7.2",
22 | "sass-loader": "^6.0.6",
23 | "style-loader": "^0.20.1",
24 | "url-loader": "^0.6.2",
25 | "webpack": "^3.10.0",
26 | "webpack-dev-server": "^2.11.1"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/chapter2/1/src/app.js:
--------------------------------------------------------------------------------
1 | require('./app.scss');
2 |
3 | var Vue = require('vue');
4 | var logoSrc = require('./logo.jpg')
5 |
6 | new Vue({
7 | el: "#app",
8 | data () {
9 | return {
10 | msg: 'Hello Vue.js'
11 | }
12 | },
13 | render (h) {
14 | return (
15 | h('div', [
16 | h('img', {
17 | domProps: {
18 | src: logoSrc,
19 | alt: 'logo',
20 | className: 'logo'
21 | }
22 | }),
23 | h('h1', this.msg)
24 | ])
25 | )
26 | }
27 | });
28 |
--------------------------------------------------------------------------------
/chapter2/1/src/app.scss:
--------------------------------------------------------------------------------
1 | $red: rgb(218, 42, 42);
2 |
3 | html,body {
4 | text-align: center;
5 | }
6 |
7 | h1 {
8 | color: $red;
9 | }
10 |
11 | .logo {
12 | margin-top: 40px;
13 | width: 60px;
14 | height: 60px;
15 | }
16 |
--------------------------------------------------------------------------------
/chapter2/1/src/logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/chapter2/1/src/logo.jpg
--------------------------------------------------------------------------------
/chapter2/1/webpack.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | // 入口文件
3 | entry: './src/app.js',
4 | // 编译输出文件
5 | output: {
6 | filename: 'build.js'
7 | },
8 | resolve: {
9 | alias: {
10 | // 因为我们这里用的是 require 引入方式,所以应该使用vue.common.js/vue.js/vue.min.js
11 | 'vue$': 'vue/dist/vue.common.js'
12 | }
13 | },
14 | devServer: {
15 | // 这里定义 webpack-dev-server 开启的web服务的根目录
16 | contentBase: './'
17 | },
18 | module: {
19 | // 这里用来配置处理不同后缀文件所使用的loader
20 | rules: [
21 | {
22 | test: /\.scss$/,
23 | use: [
24 | {
25 | loader: 'style-loader'
26 | },
27 | {
28 | loader: 'css-loader'
29 | },
30 | {
31 | loader: 'sass-loader'
32 | }
33 | ]
34 | },
35 | {
36 | test: /\.(jpe?g|gif|png)$/,
37 | use: 'url-loader'
38 | }
39 | ]
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/chapter2/2/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [ "env" ]
3 | }
4 |
--------------------------------------------------------------------------------
/chapter2/2/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | yarn.lock
3 | package-lock.json
4 |
--------------------------------------------------------------------------------
/chapter2/2/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Vue webpack demo
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/chapter2/2/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-webpack-demo",
3 | "version": "0.0.1",
4 | "description": "vue+webpack project demo",
5 | "main": "index.js",
6 | "scripts": {
7 | "dev": "webpack-dev-server --inline --progress",
8 | "build": "webpack --progress --colors"
9 | },
10 | "keywords": [
11 | "vue",
12 | "webpack"
13 | ],
14 | "author": "yugasun",
15 | "license": "MIT",
16 | "dependencies": {
17 | "vue": "^2.5.13"
18 | },
19 | "devDependencies": {
20 | "babel-core": "^6.26.0",
21 | "babel-loader": "^7.1.2",
22 | "babel-preset-env": "^1.6.1",
23 | "css-loader": "^0.28.9",
24 | "extract-text-webpack-plugin": "^3.0.2",
25 | "node-sass": "^4.7.2",
26 | "raw-loader": "^0.5.1",
27 | "sass-loader": "^6.0.6",
28 | "sass-resources-loader": "^1.3.2",
29 | "url-loader": "^0.6.2",
30 | "vue-loader": "^14.1.1",
31 | "vue-template-compiler": "^2.5.13",
32 | "webpack": "^3.10.0",
33 | "webpack-dev-server": "^2.11.1"
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/chapter2/2/src/app.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import hello1 from './hello1.vue';
3 | import hello2 from './hello2.vue';
4 |
5 | new Vue({
6 | el: "#app",
7 | template: '
',
8 | components: {
9 | hello1,
10 | hello2
11 | }
12 | });
13 |
--------------------------------------------------------------------------------
/chapter2/2/src/hello1.vue:
--------------------------------------------------------------------------------
1 |
2 | # 标题
3 | 这是标题内容,[仓库地址](https://github.com/yugasun/You-May-Not-Know-Vuejs)
4 | ## 子标题
5 | 这是子标题内容
6 |
7 |
8 | {{ msg }}
9 |
10 |
20 |
25 |
--------------------------------------------------------------------------------
/chapter2/2/src/hello2.vue:
--------------------------------------------------------------------------------
1 |
2 | # 标题2
3 | 这是标题内容,[仓库地址](https://github.com/yugasun/You-May-Not-Know-Vuejs)
4 | ## 子标题2
5 | 这是子标题内容
6 |
7 |
8 | {{ msg }}
9 |
10 |
20 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/chapter2/2/src/styles/_var.scss:
--------------------------------------------------------------------------------
1 | $green: rgb(41, 209, 41);
2 | $red: rgb(177, 28, 28);
3 |
--------------------------------------------------------------------------------
/chapter2/2/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const ExtractTextPlugin = require('extract-text-webpack-plugin');
3 |
4 | function resolve(dir) {
5 | return path.resolve(__dirname, dir);
6 | }
7 |
8 | module.exports = {
9 | // 入口文件
10 | entry: './src/app.js',
11 | // 编译输出文件
12 | output: {
13 | path: resolve('./'),
14 | filename: 'build.js'
15 | },
16 | resolve: {
17 | alias: {
18 | // 因为我们这里用的是 require 引入方式,所以应该使用vue.common.js/vue.js/vue.min.js
19 | 'vue$': 'vue/dist/vue.common.js'
20 | }
21 | },
22 | devServer: {
23 | // 这里定义 webpack-dev-server 开启的web服务的根目录
24 | contentBase: resolve('./')
25 | },
26 | module: {
27 | // 这里用来配置处理不同后缀文件所使用的loader
28 | rules: [
29 | {
30 | test: /.vue$/,
31 | loader: 'vue-loader',
32 | options: {
33 | loaders: {
34 | scss: [
35 | {
36 | loader: 'vue-style-loader'
37 | },
38 | {
39 | loader: 'css-loader'
40 | },
41 | {
42 | loader: 'sass-loader'
43 | },
44 | {
45 | loader: 'sass-resources-loader',
46 | options: {
47 | resources: [resolve('./src/styles/_var.scss')]
48 | }
49 | }
50 | ],
51 | docs: ExtractTextPlugin.extract('raw-loader')
52 | }
53 | }
54 | },
55 | {
56 | test: /.js$/,
57 | loader: 'babel-loader'
58 | }
59 | ]
60 | },
61 | plugins: [
62 | new ExtractTextPlugin('docs.md')
63 | ]
64 | }
65 |
--------------------------------------------------------------------------------
/chapter2/3/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [ "env", "stage-2" ],
3 | "plugins": [
4 | "transform-runtime"
5 | ]
6 | }
7 |
--------------------------------------------------------------------------------
/chapter2/3/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | yarn.lock
3 | package-lock.json
4 |
--------------------------------------------------------------------------------
/chapter2/3/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Vue webpack demo
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/chapter2/3/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-webpack-demo",
3 | "version": "0.0.1",
4 | "description": "vue+webpack project demo",
5 | "main": "index.js",
6 | "scripts": {
7 | "dev": "webpack-dev-server --inline --progress",
8 | "build": "webpack --progress --colors"
9 | },
10 | "keywords": [
11 | "vue",
12 | "webpack"
13 | ],
14 | "author": "yugasun",
15 | "license": "MIT",
16 | "dependencies": {
17 | "normalize.css": "^8.0.0",
18 | "vue": "^2.5.13",
19 | "vue-axios-plugin": "^1.2.3"
20 | },
21 | "devDependencies": {
22 | "babel-core": "^6.26.0",
23 | "babel-loader": "^7.1.2",
24 | "babel-plugin-transform-runtime": "^6.23.0",
25 | "babel-preset-env": "^1.6.1",
26 | "babel-preset-stage-2": "^6.24.1",
27 | "css-loader": "^0.28.9",
28 | "extract-text-webpack-plugin": "^3.0.2",
29 | "node-sass": "^4.7.2",
30 | "raw-loader": "^0.5.1",
31 | "sass-loader": "^6.0.6",
32 | "sass-resources-loader": "^1.3.2",
33 | "style-loader": "^0.20.1",
34 | "url-loader": "^0.6.2",
35 | "vue-loader": "^14.1.1",
36 | "vue-template-compiler": "^2.5.13",
37 | "webpack": "^3.10.0",
38 | "webpack-dev-server": "^2.11.1"
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/chapter2/3/src/app.js:
--------------------------------------------------------------------------------
1 | import './styles/app.scss';
2 | import Vue from 'vue';
3 | import userinfo from './info';
4 | import { deepClone } from './utils';
5 | import * as utils from './utils';
6 | import hello1 from './hello1.vue';
7 | import hello2 from './hello2.vue';
8 |
9 | // 引入插件
10 | import VueAxiosPlugin from 'vue-axios-plugin';
11 | // 使用插件
12 | Vue.use(VueAxiosPlugin)
13 |
14 | new Vue({
15 | el: "#app",
16 | template: '
',
17 | data () {
18 | return {
19 | userinfo: deepClone(userinfo)
20 | }
21 | },
22 | components: {
23 | hello1,
24 | hello2
25 | },
26 | created () {
27 | // 你会发现这里也同时改变了源原数据 info ,
28 | // 所以需要用到深拷贝源数据赋值给 data 中的 info
29 | utils.log('App created')
30 | }
31 | });
32 |
--------------------------------------------------------------------------------
/chapter2/3/src/hello1.vue:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
48 |
53 |
--------------------------------------------------------------------------------
/chapter2/3/src/hello2.vue:
--------------------------------------------------------------------------------
1 |
2 | {{ msg }}
3 |
4 |
14 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/chapter2/3/src/info.js:
--------------------------------------------------------------------------------
1 | let info = {
2 | name: 'yugasun',
3 | site: 'https://yugasun.com'
4 | }
5 |
6 | export default info;
7 |
--------------------------------------------------------------------------------
/chapter2/3/src/styles/_var.scss:
--------------------------------------------------------------------------------
1 | $green: rgb(41, 209, 41);
2 | $red: rgb(177, 28, 28);
3 |
--------------------------------------------------------------------------------
/chapter2/3/src/styles/app.scss:
--------------------------------------------------------------------------------
1 | * {
2 | margin: 0;
3 | padding: 0;
4 | }
5 |
6 | html,body {
7 | width: 100%;
8 | height: 100%;
9 | background: #eeeeee;
10 | }
11 |
12 | .app {
13 | padding: 20px;
14 | text-align: center;
15 | }
16 |
--------------------------------------------------------------------------------
/chapter2/3/src/utils.js:
--------------------------------------------------------------------------------
1 | /**
2 | * 简单的深拷贝实现,个人经常这么使用
3 | * 这里obj中不能包含特殊类型值:undefined,NaN,function类型值
4 | * @param {object} obj
5 | */
6 | export function deepClone(obj) {
7 | return JSON.parse(JSON.stringify(obj));
8 | }
9 |
10 | /**
11 | * log 函数的二次封装,这里只是为了演示
12 | * @param {any} content
13 | */
14 | export function log(content) {
15 | console.log(`[ Logger ]: ${JSON.stringify(content)}`);
16 | }
17 |
--------------------------------------------------------------------------------
/chapter2/3/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 |
3 | function resolve(dir) {
4 | return path.resolve(__dirname, dir);
5 | }
6 |
7 | module.exports = {
8 | // 入口文件
9 | entry: './src/app.js',
10 | // 编译输出文件
11 | output: {
12 | path: resolve('./'),
13 | filename: 'build.js'
14 | },
15 | resolve: {
16 | alias: {
17 | // 因为我们这里用的是 require 引入方式,所以应该使用vue.common.js/vue.js/vue.min.js
18 | 'vue$': 'vue/dist/vue.common.js'
19 | }
20 | },
21 | devServer: {
22 | // 这里定义 webpack-dev-server 开启的web服务的根目录
23 | contentBase: resolve('./')
24 | },
25 | module: {
26 | // 这里用来配置处理不同后缀文件所使用的loader
27 | rules: [
28 | {
29 | test: /.scss$/,
30 | use: [
31 | {
32 | loader: 'style-loader'
33 | },
34 | {
35 | loader: 'css-loader'
36 | },
37 | {
38 | loader: 'sass-loader'
39 | }
40 | ],
41 | },
42 | {
43 | test: /.vue$/,
44 | loader: 'vue-loader',
45 | options: {
46 | loaders: {
47 | scss: [
48 | {
49 | loader: 'vue-style-loader'
50 | },
51 | {
52 | loader: 'css-loader'
53 | },
54 | {
55 | loader: 'sass-loader'
56 | },
57 | {
58 | loader: 'sass-resources-loader',
59 | options: {
60 | resources: [resolve('./src/styles/_var.scss')]
61 | }
62 | }
63 | ]
64 | }
65 | }
66 | },
67 | {
68 | test: /.js$/,
69 | loader: 'babel-loader',
70 | include: [resolve('./src')]
71 | }
72 | ]
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/chapter2/4/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [ "env", "stage-2" ],
3 | "plugins": [
4 | "transform-runtime"
5 | ]
6 | }
7 |
--------------------------------------------------------------------------------
/chapter2/4/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | extends: [ 'plugin:vue/essential', 'airbnb-base' ],
3 | rules: {
4 | 'no-console': 'off',
5 | }
6 | };
7 |
--------------------------------------------------------------------------------
/chapter2/4/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | yarn.lock
3 | package-lock.json
4 |
--------------------------------------------------------------------------------
/chapter2/4/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Vue webpack demo
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/chapter2/4/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-webpack-demo",
3 | "version": "0.0.1",
4 | "description": "vue+webpack project demo",
5 | "main": "index.js",
6 | "scripts": {
7 | "dev": "webpack-dev-server --inline --progress",
8 | "build": "webpack --progress --colors",
9 | "lint": "eslint --ext .js,.vue src"
10 | },
11 | "keywords": [
12 | "vue",
13 | "webpack"
14 | ],
15 | "author": "yugasun",
16 | "license": "MIT",
17 | "dependencies": {
18 | "normalize.css": "^8.0.0",
19 | "vue": "^2.5.13",
20 | "vue-axios-plugin": "^1.2.3"
21 | },
22 | "devDependencies": {
23 | "babel-core": "^6.26.0",
24 | "babel-loader": "^7.1.2",
25 | "babel-plugin-transform-runtime": "^6.23.0",
26 | "babel-preset-env": "^1.6.1",
27 | "babel-preset-stage-2": "^6.24.1",
28 | "css-loader": "^0.28.9",
29 | "eslint": "^4.18.2",
30 | "eslint-config-airbnb-base": "^12.1.0",
31 | "eslint-plugin-import": "^2.9.0",
32 | "eslint-plugin-vue": "^4.3.0",
33 | "extract-text-webpack-plugin": "^3.0.2",
34 | "node-sass": "^4.7.2",
35 | "raw-loader": "^0.5.1",
36 | "sass-loader": "^6.0.6",
37 | "sass-resources-loader": "^1.3.2",
38 | "style-loader": "^0.20.1",
39 | "url-loader": "^0.6.2",
40 | "vue-loader": "^14.1.1",
41 | "vue-template-compiler": "^2.5.13",
42 | "webpack": "^3.10.0",
43 | "webpack-dev-server": "^2.11.1"
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/chapter2/4/src/app.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | // 引入插件
3 | import VueAxiosPlugin from 'vue-axios-plugin';
4 |
5 | import './styles/app.scss';
6 | import userinfo from './info';
7 | import { deepClone, log as logger } from './utils';
8 | import hello1 from './hello1.vue';
9 | import hello2 from './hello2.vue';
10 |
11 |
12 | // 使用插件
13 | Vue.use(VueAxiosPlugin);
14 |
15 | /* eslint-disable no-new */
16 | new Vue({
17 | el: '#app',
18 | template: '
',
19 | data() {
20 | return {
21 | userinfo: deepClone(userinfo),
22 | };
23 | },
24 | components: {
25 | hello1,
26 | hello2,
27 | },
28 | created() {
29 | // 你会发现这里也同时改变了源原数据 info ,
30 | // 所以需要用到深拷贝源数据赋值给 data 中的 info
31 | logger('App created');
32 | },
33 | });
34 |
--------------------------------------------------------------------------------
/chapter2/4/src/hello1.vue:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
48 |
53 |
--------------------------------------------------------------------------------
/chapter2/4/src/hello2.vue:
--------------------------------------------------------------------------------
1 |
2 | {{ msg }}
3 |
4 |
14 |
19 |
20 |
--------------------------------------------------------------------------------
/chapter2/4/src/info.js:
--------------------------------------------------------------------------------
1 | const info = {
2 | name: 'yugasun',
3 | site: 'https://yugasun.com',
4 | };
5 |
6 | export default info;
7 |
--------------------------------------------------------------------------------
/chapter2/4/src/styles/_var.scss:
--------------------------------------------------------------------------------
1 | $green: rgb(41, 209, 41);
2 | $red: rgb(177, 28, 28);
3 |
--------------------------------------------------------------------------------
/chapter2/4/src/styles/app.scss:
--------------------------------------------------------------------------------
1 | * {
2 | margin: 0;
3 | padding: 0;
4 | }
5 |
6 | html,body {
7 | width: 100%;
8 | height: 100%;
9 | background: #eeeeee;
10 | }
11 |
12 | .app {
13 | padding: 20px;
14 | text-align: center;
15 | }
16 |
--------------------------------------------------------------------------------
/chapter2/4/src/utils.js:
--------------------------------------------------------------------------------
1 | /**
2 | * 简单的深拷贝实现,个人经常这么使用
3 | * 这里obj中不能包含特殊类型值:undefined,NaN,function类型值
4 | * @param {object} obj
5 | */
6 | export function deepClone(obj) {
7 | return JSON.parse(JSON.stringify(obj));
8 | }
9 |
10 | /**
11 | * log 函数的二次封装,这里只是为了演示
12 | * @param {any} content
13 | */
14 | export function log(content) {
15 | console.log(`[ Logger ]: ${JSON.stringify(content)}`);
16 | }
17 |
--------------------------------------------------------------------------------
/chapter2/4/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 |
3 | function resolve(dir) {
4 | return path.resolve(__dirname, dir);
5 | }
6 |
7 | module.exports = {
8 | // 入口文件
9 | entry: './src/app.js',
10 | // 编译输出文件
11 | output: {
12 | path: resolve('./'),
13 | filename: 'build.js',
14 | },
15 | resolve: {
16 | alias: {
17 | // 因为我们这里用的是 require 引入方式,所以应该使用vue.common.js/vue.js/vue.min.js
18 | vue$: 'vue/dist/vue.common.js',
19 | },
20 | },
21 | devServer: {
22 | // 这里定义 webpack-dev-server 开启的web服务的根目录
23 | contentBase: resolve('./'),
24 | },
25 | module: {
26 | // 这里用来配置处理不同后缀文件所使用的loader
27 | rules: [
28 | {
29 | test: /.scss$/,
30 | use: [
31 | {
32 | loader: 'style-loader',
33 | },
34 | {
35 | loader: 'css-loader',
36 | },
37 | {
38 | loader: 'sass-loader',
39 | },
40 | ],
41 | },
42 | {
43 | test: /.vue$/,
44 | loader: 'vue-loader',
45 | options: {
46 | loaders: {
47 | scss: [
48 | {
49 | loader: 'vue-style-loader',
50 | },
51 | {
52 | loader: 'css-loader',
53 | },
54 | {
55 | loader: 'sass-loader',
56 | },
57 | {
58 | loader: 'sass-resources-loader',
59 | options: {
60 | resources: [resolve('./src/styles/_var.scss')],
61 | },
62 | },
63 | ],
64 | },
65 | },
66 | },
67 | {
68 | test: /.js$/,
69 | loader: 'babel-loader',
70 | include: [resolve('./src')],
71 | },
72 | ],
73 | },
74 | };
75 |
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/.babelrc:
--------------------------------------------------------------------------------
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-vue-jsx", "transform-runtime"]
12 | }
13 |
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/.editorconfig:
--------------------------------------------------------------------------------
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
10 |
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/.eslintignore:
--------------------------------------------------------------------------------
1 | /build/
2 | /config/
3 | /dist/
4 | /*.js
5 |
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/.eslintrc.js:
--------------------------------------------------------------------------------
1 | // https://eslint.org/docs/user-guide/configuring
2 |
3 | module.exports = {
4 | root: true,
5 | parserOptions: {
6 | parser: 'babel-eslint'
7 | },
8 | env: {
9 | browser: true,
10 | },
11 | // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
12 | // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
13 | extends: ['plugin:vue/essential', 'airbnb-base'],
14 | // required to lint *.vue files
15 | plugins: [
16 | 'vue'
17 | ],
18 | // check if imports actually resolve
19 | settings: {
20 | 'import/resolver': {
21 | webpack: {
22 | config: 'build/webpack.base.conf.js'
23 | }
24 | }
25 | },
26 | // add your custom rules here
27 | rules: {
28 | // don't require .vue extension when importing
29 | 'import/extensions': ['error', 'always', {
30 | js: 'never',
31 | vue: 'never'
32 | }],
33 | // disallow reassignment of function parameters
34 | // disallow parameter object manipulation except for specific exclusions
35 | 'no-param-reassign': ['error', {
36 | props: true,
37 | ignorePropertyModificationsFor: [
38 | 'state', // for vuex state
39 | 'acc', // for reduce accumulators
40 | 'e' // for e.returnvalue
41 | ]
42 | }],
43 | // allow optionalDependencies
44 | 'import/no-extraneous-dependencies': ['error', {
45 | optionalDependencies: ['test/unit/index.js']
46 | }],
47 | // allow debugger during development
48 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | /dist/
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Editor directories and files
9 | .idea
10 | .vscode
11 | *.suo
12 | *.ntvs*
13 | *.njsproj
14 | *.sln
15 |
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/.postcssrc.js:
--------------------------------------------------------------------------------
1 | // https://github.com/michael-ciniawsky/postcss-load-config
2 |
3 | module.exports = {
4 | "plugins": {
5 | "postcss-import": {},
6 | "postcss-url": {},
7 | // to edit target browsers: use "browserslist" field in package.json
8 | "autoprefixer": {}
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/README.md:
--------------------------------------------------------------------------------
1 | # vue-router-demo
2 |
3 | > Vue.js Router Demo Project
4 |
5 | ## Build Setup
6 |
7 | ``` bash
8 | # install dependencies
9 | npm install
10 |
11 | # serve with hot reload at localhost:8080
12 | npm run dev
13 |
14 | # build for production with minification
15 | npm run build
16 |
17 | # build for production and view the bundle analyzer report
18 | npm run build --report
19 | ```
20 |
21 | For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
22 |
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/build/build.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | require('./check-versions')()
3 |
4 | process.env.NODE_ENV = 'production'
5 |
6 | const ora = require('ora')
7 | const rm = require('rimraf')
8 | const path = require('path')
9 | const chalk = require('chalk')
10 | const webpack = require('webpack')
11 | const config = require('../config')
12 | const webpackConfig = require('./webpack.prod.conf')
13 |
14 | const spinner = ora('building for production...')
15 | spinner.start()
16 |
17 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
18 | if (err) throw err
19 | webpack(webpackConfig, (err, stats) => {
20 | spinner.stop()
21 | if (err) throw err
22 | process.stdout.write(stats.toString({
23 | colors: true,
24 | modules: false,
25 | children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
26 | chunks: false,
27 | chunkModules: false
28 | }) + '\n\n')
29 |
30 | if (stats.hasErrors()) {
31 | console.log(chalk.red(' Build failed with errors.\n'))
32 | process.exit(1)
33 | }
34 |
35 | console.log(chalk.cyan(' Build complete.\n'))
36 | console.log(chalk.yellow(
37 | ' Tip: built files are meant to be served over an HTTP server.\n' +
38 | ' Opening index.html over file:// won\'t work.\n'
39 | ))
40 | })
41 | })
42 |
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/build/check-versions.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const chalk = require('chalk')
3 | const semver = require('semver')
4 | const packageConfig = require('../package.json')
5 | const shell = require('shelljs')
6 |
7 | function exec (cmd) {
8 | return require('child_process').execSync(cmd).toString().trim()
9 | }
10 |
11 | const versionRequirements = [
12 | {
13 | name: 'node',
14 | currentVersion: semver.clean(process.version),
15 | versionRequirement: packageConfig.engines.node
16 | }
17 | ]
18 |
19 | if (shell.which('npm')) {
20 | versionRequirements.push({
21 | name: 'npm',
22 | currentVersion: exec('npm --version'),
23 | versionRequirement: packageConfig.engines.npm
24 | })
25 | }
26 |
27 | module.exports = function () {
28 | const warnings = []
29 |
30 | for (let i = 0; i < versionRequirements.length; i++) {
31 | const mod = versionRequirements[i]
32 |
33 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
34 | warnings.push(mod.name + ': ' +
35 | chalk.red(mod.currentVersion) + ' should be ' +
36 | chalk.green(mod.versionRequirement)
37 | )
38 | }
39 | }
40 |
41 | if (warnings.length) {
42 | console.log('')
43 | console.log(chalk.yellow('To use this template, you must update following to modules:'))
44 | console.log()
45 |
46 | for (let i = 0; i < warnings.length; i++) {
47 | const warning = warnings[i]
48 | console.log(' ' + warning)
49 | }
50 |
51 | console.log()
52 | process.exit(1)
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/build/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/chapter3/vue-router/hash/build/logo.png
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/build/vue-loader.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const utils = require('./utils')
3 | const config = require('../config')
4 | const isProduction = process.env.NODE_ENV === 'production'
5 | const sourceMapEnabled = isProduction
6 | ? config.build.productionSourceMap
7 | : config.dev.cssSourceMap
8 |
9 | module.exports = {
10 | loaders: utils.cssLoaders({
11 | sourceMap: sourceMapEnabled,
12 | extract: isProduction
13 | }),
14 | cssSourceMap: sourceMapEnabled,
15 | cacheBusting: config.dev.cacheBusting,
16 | transformToRequire: {
17 | video: ['src', 'poster'],
18 | source: 'src',
19 | img: 'src',
20 | image: 'xlink:href'
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/config/dev.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const merge = require('webpack-merge')
3 | const prodEnv = require('./prod.env')
4 |
5 | module.exports = merge(prodEnv, {
6 | NODE_ENV: '"development"'
7 | })
8 |
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/config/index.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | // Template version: 1.3.1
3 | // see http://vuejs-templates.github.io/webpack for documentation.
4 |
5 | const path = require('path')
6 |
7 | module.exports = {
8 | dev: {
9 |
10 | // Paths
11 | assetsSubDirectory: 'static',
12 | assetsPublicPath: '/',
13 | proxyTable: {},
14 |
15 | // Various Dev Server settings
16 | host: 'localhost', // can be overwritten by process.env.HOST
17 | port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
18 | autoOpenBrowser: false,
19 | errorOverlay: true,
20 | notifyOnErrors: true,
21 | poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
22 |
23 | // Use Eslint Loader?
24 | // If true, your code will be linted during bundling and
25 | // linting errors and warnings will be shown in the console.
26 | useEslint: true,
27 | // If true, eslint errors and warnings will also be shown in the error overlay
28 | // in the browser.
29 | showEslintErrorsInOverlay: false,
30 |
31 | /**
32 | * Source Maps
33 | */
34 |
35 | // https://webpack.js.org/configuration/devtool/#development
36 | devtool: 'cheap-module-eval-source-map',
37 |
38 | // If you have problems debugging vue-files in devtools,
39 | // set this to false - it *may* help
40 | // https://vue-loader.vuejs.org/en/options.html#cachebusting
41 | cacheBusting: true,
42 |
43 | cssSourceMap: true
44 | },
45 |
46 | build: {
47 | // Template for index.html
48 | index: path.resolve(__dirname, '../dist/index.html'),
49 |
50 | // Paths
51 | assetsRoot: path.resolve(__dirname, '../dist'),
52 | assetsSubDirectory: 'static',
53 | assetsPublicPath: '/',
54 |
55 | /**
56 | * Source Maps
57 | */
58 |
59 | productionSourceMap: true,
60 | // https://webpack.js.org/configuration/devtool/#production
61 | devtool: '#source-map',
62 |
63 | // Gzip off by default as many popular static hosts such as
64 | // Surge or Netlify already gzip all static assets for you.
65 | // Before setting to `true`, make sure to:
66 | // npm install --save-dev compression-webpack-plugin
67 | productionGzip: false,
68 | productionGzipExtensions: ['js', 'css'],
69 |
70 | // Run the build command with an extra argument to
71 | // View the bundle analyzer report after build finishes:
72 | // `npm run build --report`
73 | // Set to `true` or `false` to always turn it on or off
74 | bundleAnalyzerReport: process.env.npm_config_report
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/config/prod.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | module.exports = {
3 | NODE_ENV: '"production"'
4 | }
5 |
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | vue-router-demo
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-router-demo",
3 | "version": "1.0.0",
4 | "description": "Vue.js Router Demo Project",
5 | "author": "yugasun ",
6 | "private": true,
7 | "scripts": {
8 | "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
9 | "start": "npm run dev",
10 | "lint": "eslint --ext .js,.vue src",
11 | "build": "node build/build.js"
12 | },
13 | "dependencies": {
14 | "vue": "^2.5.16"
15 | },
16 | "devDependencies": {
17 | "autoprefixer": "^7.1.2",
18 | "babel-core": "^6.22.1",
19 | "babel-eslint": "^8.2.1",
20 | "babel-helper-vue-jsx-merge-props": "^2.0.3",
21 | "babel-loader": "^7.1.1",
22 | "babel-plugin-syntax-jsx": "^6.18.0",
23 | "babel-plugin-transform-runtime": "^6.22.0",
24 | "babel-plugin-transform-vue-jsx": "^3.5.0",
25 | "babel-preset-env": "^1.3.2",
26 | "babel-preset-stage-2": "^6.22.0",
27 | "chalk": "^2.0.1",
28 | "copy-webpack-plugin": "^4.0.1",
29 | "css-loader": "^0.28.0",
30 | "eslint": "^4.15.0",
31 | "eslint-config-airbnb-base": "^11.3.0",
32 | "eslint-friendly-formatter": "^3.0.0",
33 | "eslint-import-resolver-webpack": "^0.8.3",
34 | "eslint-loader": "^1.7.1",
35 | "eslint-plugin-import": "^2.7.0",
36 | "eslint-plugin-vue": "^4.0.0",
37 | "extract-text-webpack-plugin": "^3.0.0",
38 | "file-loader": "^1.1.4",
39 | "friendly-errors-webpack-plugin": "^1.6.1",
40 | "html-webpack-plugin": "^2.30.1",
41 | "node-notifier": "^5.1.2",
42 | "optimize-css-assets-webpack-plugin": "^3.2.0",
43 | "ora": "^1.2.0",
44 | "portfinder": "^1.0.13",
45 | "postcss-import": "^11.0.0",
46 | "postcss-loader": "^2.0.8",
47 | "postcss-url": "^7.2.1",
48 | "rimraf": "^2.6.0",
49 | "semver": "^5.3.0",
50 | "shelljs": "^0.7.6",
51 | "uglifyjs-webpack-plugin": "^1.1.1",
52 | "url-loader": "^0.5.8",
53 | "vue-loader": "^13.3.0",
54 | "vue-style-loader": "^3.0.1",
55 | "vue-template-compiler": "^2.5.16",
56 | "webpack": "^3.6.0",
57 | "webpack-bundle-analyzer": "^2.9.0",
58 | "webpack-dev-server": "^2.9.1",
59 | "webpack-merge": "^4.1.0"
60 | },
61 | "engines": {
62 | "node": ">= 6.0.0",
63 | "npm": ">= 3.0.0"
64 | },
65 | "browserslist": [
66 | "> 1%",
67 | "last 2 versions",
68 | "not ie <= 8"
69 | ]
70 | }
71 |
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/src/assets/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/chapter3/vue-router/hash/src/assets/logo.png
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/src/components/router-link.vue:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
40 |
41 |
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/src/layout/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 | Home
6 |
7 | -
8 | HelloWord
9 |
10 |
11 |
12 |
13 |
14 |
24 |
35 |
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/src/main.js:
--------------------------------------------------------------------------------
1 | // The Vue build version to load with the `import` command
2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
3 | import Vue from 'vue';
4 | import routes from './routes';
5 |
6 | Vue.config.productionTip = false;
7 |
8 | /* eslint-disable no-new */
9 | const app = new Vue({
10 | el: '#app',
11 | data() {
12 | return {
13 | currentRoute: '',
14 | };
15 | },
16 | computed: {
17 | ViewComponent() {
18 | const currentView = routes[this.currentRoute];
19 | /* eslint-disable */
20 | return (
21 | currentView
22 | ? require('./pages/' + currentView + '.vue')
23 | : require('./pages/404.vue')
24 | );
25 | },
26 | },
27 | render(h) {
28 | // 因为组件是以 es module 的方式引入的,
29 | // 此处必须使用 this.ViewComponent.default 属性作为参数
30 | return h(this.ViewComponent.default);
31 | },
32 | created () {
33 | window.location.hash = window.location.hash ? window.location.hash : '#/';
34 | this.currentRoute = window.location.hash;
35 | }
36 | });
37 |
38 | // 这里为了监听浏览器 前进/后退 按钮,来切换路由
39 | window.addEventListener('hashchange', () => {
40 | app.currentRoute = window.location.hash;
41 | });
42 |
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/src/pages/404.vue:
--------------------------------------------------------------------------------
1 |
2 | Page Not Found!
3 |
4 |
9 |
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/src/pages/Home.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | Home Page
4 |
5 |
6 |
16 |
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/src/routes.js:
--------------------------------------------------------------------------------
1 | export default {
2 | '#/': 'Home',
3 | '#/hello': 'HelloWorld',
4 | };
5 |
--------------------------------------------------------------------------------
/chapter3/vue-router/hash/static/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/chapter3/vue-router/hash/static/.gitkeep
--------------------------------------------------------------------------------
/chapter3/vue-router/history/.babelrc:
--------------------------------------------------------------------------------
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-vue-jsx", "transform-runtime"]
12 | }
13 |
--------------------------------------------------------------------------------
/chapter3/vue-router/history/.editorconfig:
--------------------------------------------------------------------------------
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
10 |
--------------------------------------------------------------------------------
/chapter3/vue-router/history/.eslintignore:
--------------------------------------------------------------------------------
1 | /build/
2 | /config/
3 | /dist/
4 | /*.js
5 |
--------------------------------------------------------------------------------
/chapter3/vue-router/history/.eslintrc.js:
--------------------------------------------------------------------------------
1 | // https://eslint.org/docs/user-guide/configuring
2 |
3 | module.exports = {
4 | root: true,
5 | parserOptions: {
6 | parser: 'babel-eslint'
7 | },
8 | env: {
9 | browser: true,
10 | },
11 | // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
12 | // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
13 | extends: ['plugin:vue/essential', 'airbnb-base'],
14 | // required to lint *.vue files
15 | plugins: [
16 | 'vue'
17 | ],
18 | // check if imports actually resolve
19 | settings: {
20 | 'import/resolver': {
21 | webpack: {
22 | config: 'build/webpack.base.conf.js'
23 | }
24 | }
25 | },
26 | // add your custom rules here
27 | rules: {
28 | // don't require .vue extension when importing
29 | 'import/extensions': ['error', 'always', {
30 | js: 'never',
31 | vue: 'never'
32 | }],
33 | // disallow reassignment of function parameters
34 | // disallow parameter object manipulation except for specific exclusions
35 | 'no-param-reassign': ['error', {
36 | props: true,
37 | ignorePropertyModificationsFor: [
38 | 'state', // for vuex state
39 | 'acc', // for reduce accumulators
40 | 'e' // for e.returnvalue
41 | ]
42 | }],
43 | // allow optionalDependencies
44 | 'import/no-extraneous-dependencies': ['error', {
45 | optionalDependencies: ['test/unit/index.js']
46 | }],
47 | // allow debugger during development
48 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/chapter3/vue-router/history/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | /dist/
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Editor directories and files
9 | .idea
10 | .vscode
11 | *.suo
12 | *.ntvs*
13 | *.njsproj
14 | *.sln
15 |
--------------------------------------------------------------------------------
/chapter3/vue-router/history/.postcssrc.js:
--------------------------------------------------------------------------------
1 | // https://github.com/michael-ciniawsky/postcss-load-config
2 |
3 | module.exports = {
4 | "plugins": {
5 | "postcss-import": {},
6 | "postcss-url": {},
7 | // to edit target browsers: use "browserslist" field in package.json
8 | "autoprefixer": {}
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/chapter3/vue-router/history/README.md:
--------------------------------------------------------------------------------
1 | # vue-router-demo
2 |
3 | > Vue.js Router Demo Project
4 |
5 | ## Build Setup
6 |
7 | ``` bash
8 | # install dependencies
9 | npm install
10 |
11 | # serve with hot reload at localhost:8080
12 | npm run dev
13 |
14 | # build for production with minification
15 | npm run build
16 |
17 | # build for production and view the bundle analyzer report
18 | npm run build --report
19 | ```
20 |
21 | For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
22 |
--------------------------------------------------------------------------------
/chapter3/vue-router/history/build/build.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | require('./check-versions')()
3 |
4 | process.env.NODE_ENV = 'production'
5 |
6 | const ora = require('ora')
7 | const rm = require('rimraf')
8 | const path = require('path')
9 | const chalk = require('chalk')
10 | const webpack = require('webpack')
11 | const config = require('../config')
12 | const webpackConfig = require('./webpack.prod.conf')
13 |
14 | const spinner = ora('building for production...')
15 | spinner.start()
16 |
17 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
18 | if (err) throw err
19 | webpack(webpackConfig, (err, stats) => {
20 | spinner.stop()
21 | if (err) throw err
22 | process.stdout.write(stats.toString({
23 | colors: true,
24 | modules: false,
25 | children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
26 | chunks: false,
27 | chunkModules: false
28 | }) + '\n\n')
29 |
30 | if (stats.hasErrors()) {
31 | console.log(chalk.red(' Build failed with errors.\n'))
32 | process.exit(1)
33 | }
34 |
35 | console.log(chalk.cyan(' Build complete.\n'))
36 | console.log(chalk.yellow(
37 | ' Tip: built files are meant to be served over an HTTP server.\n' +
38 | ' Opening index.html over file:// won\'t work.\n'
39 | ))
40 | })
41 | })
42 |
--------------------------------------------------------------------------------
/chapter3/vue-router/history/build/check-versions.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const chalk = require('chalk')
3 | const semver = require('semver')
4 | const packageConfig = require('../package.json')
5 | const shell = require('shelljs')
6 |
7 | function exec (cmd) {
8 | return require('child_process').execSync(cmd).toString().trim()
9 | }
10 |
11 | const versionRequirements = [
12 | {
13 | name: 'node',
14 | currentVersion: semver.clean(process.version),
15 | versionRequirement: packageConfig.engines.node
16 | }
17 | ]
18 |
19 | if (shell.which('npm')) {
20 | versionRequirements.push({
21 | name: 'npm',
22 | currentVersion: exec('npm --version'),
23 | versionRequirement: packageConfig.engines.npm
24 | })
25 | }
26 |
27 | module.exports = function () {
28 | const warnings = []
29 |
30 | for (let i = 0; i < versionRequirements.length; i++) {
31 | const mod = versionRequirements[i]
32 |
33 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
34 | warnings.push(mod.name + ': ' +
35 | chalk.red(mod.currentVersion) + ' should be ' +
36 | chalk.green(mod.versionRequirement)
37 | )
38 | }
39 | }
40 |
41 | if (warnings.length) {
42 | console.log('')
43 | console.log(chalk.yellow('To use this template, you must update following to modules:'))
44 | console.log()
45 |
46 | for (let i = 0; i < warnings.length; i++) {
47 | const warning = warnings[i]
48 | console.log(' ' + warning)
49 | }
50 |
51 | console.log()
52 | process.exit(1)
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/chapter3/vue-router/history/build/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/chapter3/vue-router/history/build/logo.png
--------------------------------------------------------------------------------
/chapter3/vue-router/history/build/vue-loader.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const utils = require('./utils')
3 | const config = require('../config')
4 | const isProduction = process.env.NODE_ENV === 'production'
5 | const sourceMapEnabled = isProduction
6 | ? config.build.productionSourceMap
7 | : config.dev.cssSourceMap
8 |
9 | module.exports = {
10 | loaders: utils.cssLoaders({
11 | sourceMap: sourceMapEnabled,
12 | extract: isProduction
13 | }),
14 | cssSourceMap: sourceMapEnabled,
15 | cacheBusting: config.dev.cacheBusting,
16 | transformToRequire: {
17 | video: ['src', 'poster'],
18 | source: 'src',
19 | img: 'src',
20 | image: 'xlink:href'
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/chapter3/vue-router/history/config/dev.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const merge = require('webpack-merge')
3 | const prodEnv = require('./prod.env')
4 |
5 | module.exports = merge(prodEnv, {
6 | NODE_ENV: '"development"'
7 | })
8 |
--------------------------------------------------------------------------------
/chapter3/vue-router/history/config/index.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | // Template version: 1.3.1
3 | // see http://vuejs-templates.github.io/webpack for documentation.
4 |
5 | const path = require('path')
6 |
7 | module.exports = {
8 | dev: {
9 |
10 | // Paths
11 | assetsSubDirectory: 'static',
12 | assetsPublicPath: '/',
13 | proxyTable: {},
14 |
15 | // Various Dev Server settings
16 | host: 'localhost', // can be overwritten by process.env.HOST
17 | port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
18 | autoOpenBrowser: false,
19 | errorOverlay: true,
20 | notifyOnErrors: true,
21 | poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
22 |
23 | // Use Eslint Loader?
24 | // If true, your code will be linted during bundling and
25 | // linting errors and warnings will be shown in the console.
26 | useEslint: true,
27 | // If true, eslint errors and warnings will also be shown in the error overlay
28 | // in the browser.
29 | showEslintErrorsInOverlay: false,
30 |
31 | /**
32 | * Source Maps
33 | */
34 |
35 | // https://webpack.js.org/configuration/devtool/#development
36 | devtool: 'cheap-module-eval-source-map',
37 |
38 | // If you have problems debugging vue-files in devtools,
39 | // set this to false - it *may* help
40 | // https://vue-loader.vuejs.org/en/options.html#cachebusting
41 | cacheBusting: true,
42 |
43 | cssSourceMap: true
44 | },
45 |
46 | build: {
47 | // Template for index.html
48 | index: path.resolve(__dirname, '../dist/index.html'),
49 |
50 | // Paths
51 | assetsRoot: path.resolve(__dirname, '../dist'),
52 | assetsSubDirectory: 'static',
53 | assetsPublicPath: '/',
54 |
55 | /**
56 | * Source Maps
57 | */
58 |
59 | productionSourceMap: true,
60 | // https://webpack.js.org/configuration/devtool/#production
61 | devtool: '#source-map',
62 |
63 | // Gzip off by default as many popular static hosts such as
64 | // Surge or Netlify already gzip all static assets for you.
65 | // Before setting to `true`, make sure to:
66 | // npm install --save-dev compression-webpack-plugin
67 | productionGzip: false,
68 | productionGzipExtensions: ['js', 'css'],
69 |
70 | // Run the build command with an extra argument to
71 | // View the bundle analyzer report after build finishes:
72 | // `npm run build --report`
73 | // Set to `true` or `false` to always turn it on or off
74 | bundleAnalyzerReport: process.env.npm_config_report
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/chapter3/vue-router/history/config/prod.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | module.exports = {
3 | NODE_ENV: '"production"'
4 | }
5 |
--------------------------------------------------------------------------------
/chapter3/vue-router/history/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | vue-router-demo
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/chapter3/vue-router/history/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-router-demo",
3 | "version": "1.0.0",
4 | "description": "Vue.js Router Demo Project",
5 | "author": "yugasun ",
6 | "private": true,
7 | "scripts": {
8 | "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
9 | "start": "npm run dev",
10 | "lint": "eslint --ext .js,.vue src",
11 | "build": "node build/build.js"
12 | },
13 | "dependencies": {
14 | "vue": "^2.5.16"
15 | },
16 | "devDependencies": {
17 | "autoprefixer": "^7.1.2",
18 | "babel-core": "^6.22.1",
19 | "babel-eslint": "^8.2.1",
20 | "babel-helper-vue-jsx-merge-props": "^2.0.3",
21 | "babel-loader": "^7.1.1",
22 | "babel-plugin-syntax-jsx": "^6.18.0",
23 | "babel-plugin-transform-runtime": "^6.22.0",
24 | "babel-plugin-transform-vue-jsx": "^3.5.0",
25 | "babel-preset-env": "^1.3.2",
26 | "babel-preset-stage-2": "^6.22.0",
27 | "chalk": "^2.0.1",
28 | "copy-webpack-plugin": "^4.0.1",
29 | "css-loader": "^0.28.0",
30 | "eslint": "^4.15.0",
31 | "eslint-config-airbnb-base": "^11.3.0",
32 | "eslint-friendly-formatter": "^3.0.0",
33 | "eslint-import-resolver-webpack": "^0.8.3",
34 | "eslint-loader": "^1.7.1",
35 | "eslint-plugin-import": "^2.7.0",
36 | "eslint-plugin-vue": "^4.0.0",
37 | "extract-text-webpack-plugin": "^3.0.0",
38 | "file-loader": "^1.1.4",
39 | "friendly-errors-webpack-plugin": "^1.6.1",
40 | "html-webpack-plugin": "^2.30.1",
41 | "node-notifier": "^5.1.2",
42 | "optimize-css-assets-webpack-plugin": "^3.2.0",
43 | "ora": "^1.2.0",
44 | "portfinder": "^1.0.13",
45 | "postcss-import": "^11.0.0",
46 | "postcss-loader": "^2.0.8",
47 | "postcss-url": "^7.2.1",
48 | "rimraf": "^2.6.0",
49 | "semver": "^5.3.0",
50 | "shelljs": "^0.7.6",
51 | "uglifyjs-webpack-plugin": "^1.1.1",
52 | "url-loader": "^0.5.8",
53 | "vue-loader": "^13.3.0",
54 | "vue-style-loader": "^3.0.1",
55 | "vue-template-compiler": "^2.5.16",
56 | "webpack": "^3.6.0",
57 | "webpack-bundle-analyzer": "^2.9.0",
58 | "webpack-dev-server": "^2.9.1",
59 | "webpack-merge": "^4.1.0"
60 | },
61 | "engines": {
62 | "node": ">= 6.0.0",
63 | "npm": ">= 3.0.0"
64 | },
65 | "browserslist": [
66 | "> 1%",
67 | "last 2 versions",
68 | "not ie <= 8"
69 | ]
70 | }
71 |
--------------------------------------------------------------------------------
/chapter3/vue-router/history/src/assets/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/chapter3/vue-router/history/src/assets/logo.png
--------------------------------------------------------------------------------
/chapter3/vue-router/history/src/components/router-link.vue:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
40 |
41 |
--------------------------------------------------------------------------------
/chapter3/vue-router/history/src/layout/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 | Home
6 |
7 | -
8 | HelloWord
9 |
10 |
11 |
12 |
13 |
14 |
24 |
35 |
--------------------------------------------------------------------------------
/chapter3/vue-router/history/src/main.js:
--------------------------------------------------------------------------------
1 | // The Vue build version to load with the `import` command
2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
3 | import Vue from 'vue';
4 | import routes from './routes';
5 |
6 | Vue.config.productionTip = false;
7 |
8 | /* eslint-disable no-new */
9 | const app = new Vue({
10 | el: '#app',
11 | data() {
12 | return {
13 | currentRoute: window.location.pathname,
14 | };
15 | },
16 | computed: {
17 | ViewComponent() {
18 | const currentView = routes[this.currentRoute];
19 | /* eslint-disable */
20 | return (
21 | currentView
22 | ? require('./pages/' + currentView + '.vue')
23 | : require('./pages/404.vue')
24 | );
25 | },
26 | },
27 | render(h) {
28 | // 因为组件是以 es module 的方式引入的,
29 | // 此处必须使用 this.ViewComponent.default 属性作为参数
30 | return h(this.ViewComponent.default);
31 | },
32 | });
33 |
34 | // 这里为了监听浏览器 前进/后退 按钮,来切换路由
35 | window.addEventListener('popstate', () => {
36 | app.currentRoute = window.location.pathname;
37 | });
38 |
--------------------------------------------------------------------------------
/chapter3/vue-router/history/src/pages/404.vue:
--------------------------------------------------------------------------------
1 |
2 | Page Not Found!
3 |
4 |
9 |
--------------------------------------------------------------------------------
/chapter3/vue-router/history/src/pages/Home.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | Home Page
4 |
5 |
6 |
16 |
--------------------------------------------------------------------------------
/chapter3/vue-router/history/src/routes.js:
--------------------------------------------------------------------------------
1 | export default {
2 | '/': 'Home',
3 | '/hello': 'HelloWorld',
4 | };
5 |
--------------------------------------------------------------------------------
/chapter3/vue-router/history/static/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/chapter3/vue-router/history/static/.gitkeep
--------------------------------------------------------------------------------
/chapter3/vue-router/simple/.babelrc:
--------------------------------------------------------------------------------
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-vue-jsx", "transform-runtime"]
12 | }
13 |
--------------------------------------------------------------------------------
/chapter3/vue-router/simple/.editorconfig:
--------------------------------------------------------------------------------
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
10 |
--------------------------------------------------------------------------------
/chapter3/vue-router/simple/.eslintignore:
--------------------------------------------------------------------------------
1 | /build/
2 | /config/
3 | /dist/
4 | /*.js
5 |
--------------------------------------------------------------------------------
/chapter3/vue-router/simple/.eslintrc.js:
--------------------------------------------------------------------------------
1 | // https://eslint.org/docs/user-guide/configuring
2 |
3 | module.exports = {
4 | root: true,
5 | parserOptions: {
6 | parser: 'babel-eslint'
7 | },
8 | env: {
9 | browser: true,
10 | },
11 | // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
12 | // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
13 | extends: ['plugin:vue/essential', 'airbnb-base'],
14 | // required to lint *.vue files
15 | plugins: [
16 | 'vue'
17 | ],
18 | // check if imports actually resolve
19 | settings: {
20 | 'import/resolver': {
21 | webpack: {
22 | config: 'build/webpack.base.conf.js'
23 | }
24 | }
25 | },
26 | // add your custom rules here
27 | rules: {
28 | // don't require .vue extension when importing
29 | 'import/extensions': ['error', 'always', {
30 | js: 'never',
31 | vue: 'never'
32 | }],
33 | // disallow reassignment of function parameters
34 | // disallow parameter object manipulation except for specific exclusions
35 | 'no-param-reassign': ['error', {
36 | props: true,
37 | ignorePropertyModificationsFor: [
38 | 'state', // for vuex state
39 | 'acc', // for reduce accumulators
40 | 'e' // for e.returnvalue
41 | ]
42 | }],
43 | // allow optionalDependencies
44 | 'import/no-extraneous-dependencies': ['error', {
45 | optionalDependencies: ['test/unit/index.js']
46 | }],
47 | // allow debugger during development
48 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/chapter3/vue-router/simple/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | /dist/
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Editor directories and files
9 | .idea
10 | .vscode
11 | *.suo
12 | *.ntvs*
13 | *.njsproj
14 | *.sln
15 |
--------------------------------------------------------------------------------
/chapter3/vue-router/simple/.postcssrc.js:
--------------------------------------------------------------------------------
1 | // https://github.com/michael-ciniawsky/postcss-load-config
2 |
3 | module.exports = {
4 | "plugins": {
5 | "postcss-import": {},
6 | "postcss-url": {},
7 | // to edit target browsers: use "browserslist" field in package.json
8 | "autoprefixer": {}
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/chapter3/vue-router/simple/README.md:
--------------------------------------------------------------------------------
1 | # vue-router-demo
2 |
3 | > Vue.js Router Demo Project
4 |
5 | ## Build Setup
6 |
7 | ``` bash
8 | # install dependencies
9 | npm install
10 |
11 | # serve with hot reload at localhost:8080
12 | npm run dev
13 |
14 | # build for production with minification
15 | npm run build
16 |
17 | # build for production and view the bundle analyzer report
18 | npm run build --report
19 | ```
20 |
21 | For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
22 |
--------------------------------------------------------------------------------
/chapter3/vue-router/simple/build/build.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | require('./check-versions')()
3 |
4 | process.env.NODE_ENV = 'production'
5 |
6 | const ora = require('ora')
7 | const rm = require('rimraf')
8 | const path = require('path')
9 | const chalk = require('chalk')
10 | const webpack = require('webpack')
11 | const config = require('../config')
12 | const webpackConfig = require('./webpack.prod.conf')
13 |
14 | const spinner = ora('building for production...')
15 | spinner.start()
16 |
17 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
18 | if (err) throw err
19 | webpack(webpackConfig, (err, stats) => {
20 | spinner.stop()
21 | if (err) throw err
22 | process.stdout.write(stats.toString({
23 | colors: true,
24 | modules: false,
25 | children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
26 | chunks: false,
27 | chunkModules: false
28 | }) + '\n\n')
29 |
30 | if (stats.hasErrors()) {
31 | console.log(chalk.red(' Build failed with errors.\n'))
32 | process.exit(1)
33 | }
34 |
35 | console.log(chalk.cyan(' Build complete.\n'))
36 | console.log(chalk.yellow(
37 | ' Tip: built files are meant to be served over an HTTP server.\n' +
38 | ' Opening index.html over file:// won\'t work.\n'
39 | ))
40 | })
41 | })
42 |
--------------------------------------------------------------------------------
/chapter3/vue-router/simple/build/check-versions.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const chalk = require('chalk')
3 | const semver = require('semver')
4 | const packageConfig = require('../package.json')
5 | const shell = require('shelljs')
6 |
7 | function exec (cmd) {
8 | return require('child_process').execSync(cmd).toString().trim()
9 | }
10 |
11 | const versionRequirements = [
12 | {
13 | name: 'node',
14 | currentVersion: semver.clean(process.version),
15 | versionRequirement: packageConfig.engines.node
16 | }
17 | ]
18 |
19 | if (shell.which('npm')) {
20 | versionRequirements.push({
21 | name: 'npm',
22 | currentVersion: exec('npm --version'),
23 | versionRequirement: packageConfig.engines.npm
24 | })
25 | }
26 |
27 | module.exports = function () {
28 | const warnings = []
29 |
30 | for (let i = 0; i < versionRequirements.length; i++) {
31 | const mod = versionRequirements[i]
32 |
33 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
34 | warnings.push(mod.name + ': ' +
35 | chalk.red(mod.currentVersion) + ' should be ' +
36 | chalk.green(mod.versionRequirement)
37 | )
38 | }
39 | }
40 |
41 | if (warnings.length) {
42 | console.log('')
43 | console.log(chalk.yellow('To use this template, you must update following to modules:'))
44 | console.log()
45 |
46 | for (let i = 0; i < warnings.length; i++) {
47 | const warning = warnings[i]
48 | console.log(' ' + warning)
49 | }
50 |
51 | console.log()
52 | process.exit(1)
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/chapter3/vue-router/simple/build/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/chapter3/vue-router/simple/build/logo.png
--------------------------------------------------------------------------------
/chapter3/vue-router/simple/build/vue-loader.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const utils = require('./utils')
3 | const config = require('../config')
4 | const isProduction = process.env.NODE_ENV === 'production'
5 | const sourceMapEnabled = isProduction
6 | ? config.build.productionSourceMap
7 | : config.dev.cssSourceMap
8 |
9 | module.exports = {
10 | loaders: utils.cssLoaders({
11 | sourceMap: sourceMapEnabled,
12 | extract: isProduction
13 | }),
14 | cssSourceMap: sourceMapEnabled,
15 | cacheBusting: config.dev.cacheBusting,
16 | transformToRequire: {
17 | video: ['src', 'poster'],
18 | source: 'src',
19 | img: 'src',
20 | image: 'xlink:href'
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/chapter3/vue-router/simple/config/dev.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const merge = require('webpack-merge')
3 | const prodEnv = require('./prod.env')
4 |
5 | module.exports = merge(prodEnv, {
6 | NODE_ENV: '"development"'
7 | })
8 |
--------------------------------------------------------------------------------
/chapter3/vue-router/simple/config/index.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | // Template version: 1.3.1
3 | // see http://vuejs-templates.github.io/webpack for documentation.
4 |
5 | const path = require('path')
6 |
7 | module.exports = {
8 | dev: {
9 |
10 | // Paths
11 | assetsSubDirectory: 'static',
12 | assetsPublicPath: '/',
13 | proxyTable: {},
14 |
15 | // Various Dev Server settings
16 | host: 'localhost', // can be overwritten by process.env.HOST
17 | port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
18 | autoOpenBrowser: false,
19 | errorOverlay: true,
20 | notifyOnErrors: true,
21 | poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
22 |
23 | // Use Eslint Loader?
24 | // If true, your code will be linted during bundling and
25 | // linting errors and warnings will be shown in the console.
26 | useEslint: true,
27 | // If true, eslint errors and warnings will also be shown in the error overlay
28 | // in the browser.
29 | showEslintErrorsInOverlay: false,
30 |
31 | /**
32 | * Source Maps
33 | */
34 |
35 | // https://webpack.js.org/configuration/devtool/#development
36 | devtool: 'cheap-module-eval-source-map',
37 |
38 | // If you have problems debugging vue-files in devtools,
39 | // set this to false - it *may* help
40 | // https://vue-loader.vuejs.org/en/options.html#cachebusting
41 | cacheBusting: true,
42 |
43 | cssSourceMap: true
44 | },
45 |
46 | build: {
47 | // Template for index.html
48 | index: path.resolve(__dirname, '../dist/index.html'),
49 |
50 | // Paths
51 | assetsRoot: path.resolve(__dirname, '../dist'),
52 | assetsSubDirectory: 'static',
53 | assetsPublicPath: '/',
54 |
55 | /**
56 | * Source Maps
57 | */
58 |
59 | productionSourceMap: true,
60 | // https://webpack.js.org/configuration/devtool/#production
61 | devtool: '#source-map',
62 |
63 | // Gzip off by default as many popular static hosts such as
64 | // Surge or Netlify already gzip all static assets for you.
65 | // Before setting to `true`, make sure to:
66 | // npm install --save-dev compression-webpack-plugin
67 | productionGzip: false,
68 | productionGzipExtensions: ['js', 'css'],
69 |
70 | // Run the build command with an extra argument to
71 | // View the bundle analyzer report after build finishes:
72 | // `npm run build --report`
73 | // Set to `true` or `false` to always turn it on or off
74 | bundleAnalyzerReport: process.env.npm_config_report
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/chapter3/vue-router/simple/config/prod.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | module.exports = {
3 | NODE_ENV: '"production"'
4 | }
5 |
--------------------------------------------------------------------------------
/chapter3/vue-router/simple/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | vue-router-demo
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/chapter3/vue-router/simple/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-router-demo",
3 | "version": "1.0.0",
4 | "description": "Vue.js Router Demo Project",
5 | "author": "yugasun ",
6 | "private": true,
7 | "scripts": {
8 | "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
9 | "start": "npm run dev",
10 | "lint": "eslint --ext .js,.vue src",
11 | "build": "node build/build.js"
12 | },
13 | "dependencies": {
14 | "vue": "^2.5.16"
15 | },
16 | "devDependencies": {
17 | "autoprefixer": "^7.1.2",
18 | "babel-core": "^6.22.1",
19 | "babel-eslint": "^8.2.1",
20 | "babel-helper-vue-jsx-merge-props": "^2.0.3",
21 | "babel-loader": "^7.1.1",
22 | "babel-plugin-syntax-jsx": "^6.18.0",
23 | "babel-plugin-transform-runtime": "^6.22.0",
24 | "babel-plugin-transform-vue-jsx": "^3.5.0",
25 | "babel-preset-env": "^1.3.2",
26 | "babel-preset-stage-2": "^6.22.0",
27 | "chalk": "^2.0.1",
28 | "copy-webpack-plugin": "^4.0.1",
29 | "css-loader": "^0.28.0",
30 | "eslint": "^4.15.0",
31 | "eslint-config-airbnb-base": "^11.3.0",
32 | "eslint-friendly-formatter": "^3.0.0",
33 | "eslint-import-resolver-webpack": "^0.8.3",
34 | "eslint-loader": "^1.7.1",
35 | "eslint-plugin-import": "^2.7.0",
36 | "eslint-plugin-vue": "^4.0.0",
37 | "extract-text-webpack-plugin": "^3.0.0",
38 | "file-loader": "^1.1.4",
39 | "friendly-errors-webpack-plugin": "^1.6.1",
40 | "html-webpack-plugin": "^2.30.1",
41 | "node-notifier": "^5.1.2",
42 | "optimize-css-assets-webpack-plugin": "^3.2.0",
43 | "ora": "^1.2.0",
44 | "portfinder": "^1.0.13",
45 | "postcss-import": "^11.0.0",
46 | "postcss-loader": "^2.0.8",
47 | "postcss-url": "^7.2.1",
48 | "rimraf": "^2.6.0",
49 | "semver": "^5.3.0",
50 | "shelljs": "^0.7.6",
51 | "uglifyjs-webpack-plugin": "^1.1.1",
52 | "url-loader": "^0.5.8",
53 | "vue-loader": "^13.3.0",
54 | "vue-style-loader": "^3.0.1",
55 | "vue-template-compiler": "^2.5.16",
56 | "webpack": "^3.6.0",
57 | "webpack-bundle-analyzer": "^2.9.0",
58 | "webpack-dev-server": "^2.9.1",
59 | "webpack-merge": "^4.1.0"
60 | },
61 | "engines": {
62 | "node": ">= 6.0.0",
63 | "npm": ">= 3.0.0"
64 | },
65 | "browserslist": [
66 | "> 1%",
67 | "last 2 versions",
68 | "not ie <= 8"
69 | ]
70 | }
71 |
--------------------------------------------------------------------------------
/chapter3/vue-router/simple/src/assets/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/chapter3/vue-router/simple/src/assets/logo.png
--------------------------------------------------------------------------------
/chapter3/vue-router/simple/src/layout/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
27 |
--------------------------------------------------------------------------------
/chapter3/vue-router/simple/src/main.js:
--------------------------------------------------------------------------------
1 | // The Vue build version to load with the `import` command
2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
3 | import Vue from 'vue';
4 |
5 | const routes = {
6 | '/': 'Home',
7 | '/hello': 'HelloWorld',
8 | };
9 |
10 | Vue.config.productionTip = false;
11 |
12 | /* eslint-disable no-new */
13 | new Vue({
14 | el: '#app',
15 | data() {
16 | return {
17 | currentRoute: window.location.pathname,
18 | };
19 | },
20 | computed: {
21 | ViewComponent() {
22 | const currentView = routes[this.currentRoute];
23 | /* eslint-disable */
24 | return (
25 | currentView
26 | ? require('./pages/' + currentView + '.vue')
27 | : require('./pages/404.vue')
28 | );
29 | },
30 | },
31 | render(h) {
32 | // 因为组件是以 es module 的方式引入的,
33 | // 此处必须使用 this.ViewComponent.default 属性作为参数
34 | return h(this.ViewComponent.default);
35 | },
36 | });
37 |
--------------------------------------------------------------------------------
/chapter3/vue-router/simple/src/pages/404.vue:
--------------------------------------------------------------------------------
1 |
2 | Page Not Found!
3 |
4 |
9 |
--------------------------------------------------------------------------------
/chapter3/vue-router/simple/src/pages/Home.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | Home Page
4 |
5 |
6 |
16 |
--------------------------------------------------------------------------------
/chapter3/vue-router/simple/static/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/chapter3/vue-router/simple/static/.gitkeep
--------------------------------------------------------------------------------
/chapter3/vue-state/1/.babelrc:
--------------------------------------------------------------------------------
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-vue-jsx", "transform-runtime"]
12 | }
13 |
--------------------------------------------------------------------------------
/chapter3/vue-state/1/.editorconfig:
--------------------------------------------------------------------------------
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
10 |
--------------------------------------------------------------------------------
/chapter3/vue-state/1/.eslintignore:
--------------------------------------------------------------------------------
1 | /build/
2 | /config/
3 | /dist/
4 | /*.js
5 |
--------------------------------------------------------------------------------
/chapter3/vue-state/1/.eslintrc.js:
--------------------------------------------------------------------------------
1 | // https://eslint.org/docs/user-guide/configuring
2 |
3 | module.exports = {
4 | root: true,
5 | parserOptions: {
6 | parser: 'babel-eslint'
7 | },
8 | env: {
9 | browser: true,
10 | },
11 | // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
12 | // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
13 | extends: ['plugin:vue/essential', 'airbnb-base'],
14 | // required to lint *.vue files
15 | plugins: [
16 | 'vue'
17 | ],
18 | // check if imports actually resolve
19 | settings: {
20 | 'import/resolver': {
21 | webpack: {
22 | config: 'build/webpack.base.conf.js'
23 | }
24 | }
25 | },
26 | // add your custom rules here
27 | rules: {
28 | // don't require .vue extension when importing
29 | 'import/extensions': ['error', 'always', {
30 | js: 'never',
31 | vue: 'never'
32 | }],
33 | // disallow reassignment of function parameters
34 | // disallow parameter object manipulation except for specific exclusions
35 | 'no-param-reassign': ['error', {
36 | props: true,
37 | ignorePropertyModificationsFor: [
38 | 'state', // for vuex state
39 | 'acc', // for reduce accumulators
40 | 'e' // for e.returnvalue
41 | ]
42 | }],
43 | // allow optionalDependencies
44 | 'import/no-extraneous-dependencies': ['error', {
45 | optionalDependencies: ['test/unit/index.js']
46 | }],
47 | // allow debugger during development
48 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/chapter3/vue-state/1/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | /dist/
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Editor directories and files
9 | .idea
10 | .vscode
11 | *.suo
12 | *.ntvs*
13 | *.njsproj
14 | *.sln
15 |
--------------------------------------------------------------------------------
/chapter3/vue-state/1/.postcssrc.js:
--------------------------------------------------------------------------------
1 | // https://github.com/michael-ciniawsky/postcss-load-config
2 |
3 | module.exports = {
4 | "plugins": {
5 | "postcss-import": {},
6 | "postcss-url": {},
7 | // to edit target browsers: use "browserslist" field in package.json
8 | "autoprefixer": {}
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/chapter3/vue-state/1/README.md:
--------------------------------------------------------------------------------
1 | # vue-router-demo
2 |
3 | > Vue.js Router Demo Project
4 |
5 | ## Build Setup
6 |
7 | ``` bash
8 | # install dependencies
9 | npm install
10 |
11 | # serve with hot reload at localhost:8080
12 | npm run dev
13 |
14 | # build for production with minification
15 | npm run build
16 |
17 | # build for production and view the bundle analyzer report
18 | npm run build --report
19 | ```
20 |
21 | For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
22 |
--------------------------------------------------------------------------------
/chapter3/vue-state/1/build/build.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | require('./check-versions')()
3 |
4 | process.env.NODE_ENV = 'production'
5 |
6 | const ora = require('ora')
7 | const rm = require('rimraf')
8 | const path = require('path')
9 | const chalk = require('chalk')
10 | const webpack = require('webpack')
11 | const config = require('../config')
12 | const webpackConfig = require('./webpack.prod.conf')
13 |
14 | const spinner = ora('building for production...')
15 | spinner.start()
16 |
17 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
18 | if (err) throw err
19 | webpack(webpackConfig, (err, stats) => {
20 | spinner.stop()
21 | if (err) throw err
22 | process.stdout.write(stats.toString({
23 | colors: true,
24 | modules: false,
25 | children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
26 | chunks: false,
27 | chunkModules: false
28 | }) + '\n\n')
29 |
30 | if (stats.hasErrors()) {
31 | console.log(chalk.red(' Build failed with errors.\n'))
32 | process.exit(1)
33 | }
34 |
35 | console.log(chalk.cyan(' Build complete.\n'))
36 | console.log(chalk.yellow(
37 | ' Tip: built files are meant to be served over an HTTP server.\n' +
38 | ' Opening index.html over file:// won\'t work.\n'
39 | ))
40 | })
41 | })
42 |
--------------------------------------------------------------------------------
/chapter3/vue-state/1/build/check-versions.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const chalk = require('chalk')
3 | const semver = require('semver')
4 | const packageConfig = require('../package.json')
5 | const shell = require('shelljs')
6 |
7 | function exec (cmd) {
8 | return require('child_process').execSync(cmd).toString().trim()
9 | }
10 |
11 | const versionRequirements = [
12 | {
13 | name: 'node',
14 | currentVersion: semver.clean(process.version),
15 | versionRequirement: packageConfig.engines.node
16 | }
17 | ]
18 |
19 | if (shell.which('npm')) {
20 | versionRequirements.push({
21 | name: 'npm',
22 | currentVersion: exec('npm --version'),
23 | versionRequirement: packageConfig.engines.npm
24 | })
25 | }
26 |
27 | module.exports = function () {
28 | const warnings = []
29 |
30 | for (let i = 0; i < versionRequirements.length; i++) {
31 | const mod = versionRequirements[i]
32 |
33 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
34 | warnings.push(mod.name + ': ' +
35 | chalk.red(mod.currentVersion) + ' should be ' +
36 | chalk.green(mod.versionRequirement)
37 | )
38 | }
39 | }
40 |
41 | if (warnings.length) {
42 | console.log('')
43 | console.log(chalk.yellow('To use this template, you must update following to modules:'))
44 | console.log()
45 |
46 | for (let i = 0; i < warnings.length; i++) {
47 | const warning = warnings[i]
48 | console.log(' ' + warning)
49 | }
50 |
51 | console.log()
52 | process.exit(1)
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/chapter3/vue-state/1/build/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/chapter3/vue-state/1/build/logo.png
--------------------------------------------------------------------------------
/chapter3/vue-state/1/build/vue-loader.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const utils = require('./utils')
3 | const config = require('../config')
4 | const isProduction = process.env.NODE_ENV === 'production'
5 | const sourceMapEnabled = isProduction
6 | ? config.build.productionSourceMap
7 | : config.dev.cssSourceMap
8 |
9 | module.exports = {
10 | loaders: utils.cssLoaders({
11 | sourceMap: sourceMapEnabled,
12 | extract: isProduction
13 | }),
14 | cssSourceMap: sourceMapEnabled,
15 | cacheBusting: config.dev.cacheBusting,
16 | transformToRequire: {
17 | video: ['src', 'poster'],
18 | source: 'src',
19 | img: 'src',
20 | image: 'xlink:href'
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/chapter3/vue-state/1/config/dev.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const merge = require('webpack-merge')
3 | const prodEnv = require('./prod.env')
4 |
5 | module.exports = merge(prodEnv, {
6 | NODE_ENV: '"development"'
7 | })
8 |
--------------------------------------------------------------------------------
/chapter3/vue-state/1/config/index.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | // Template version: 1.3.1
3 | // see http://vuejs-templates.github.io/webpack for documentation.
4 |
5 | const path = require('path')
6 |
7 | module.exports = {
8 | dev: {
9 |
10 | // Paths
11 | assetsSubDirectory: 'static',
12 | assetsPublicPath: '/',
13 | proxyTable: {},
14 |
15 | // Various Dev Server settings
16 | host: 'localhost', // can be overwritten by process.env.HOST
17 | port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
18 | autoOpenBrowser: false,
19 | errorOverlay: true,
20 | notifyOnErrors: true,
21 | poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
22 |
23 | // Use Eslint Loader?
24 | // If true, your code will be linted during bundling and
25 | // linting errors and warnings will be shown in the console.
26 | useEslint: true,
27 | // If true, eslint errors and warnings will also be shown in the error overlay
28 | // in the browser.
29 | showEslintErrorsInOverlay: false,
30 |
31 | /**
32 | * Source Maps
33 | */
34 |
35 | // https://webpack.js.org/configuration/devtool/#development
36 | devtool: 'cheap-module-eval-source-map',
37 |
38 | // If you have problems debugging vue-files in devtools,
39 | // set this to false - it *may* help
40 | // https://vue-loader.vuejs.org/en/options.html#cachebusting
41 | cacheBusting: true,
42 |
43 | cssSourceMap: true
44 | },
45 |
46 | build: {
47 | // Template for index.html
48 | index: path.resolve(__dirname, '../dist/index.html'),
49 |
50 | // Paths
51 | assetsRoot: path.resolve(__dirname, '../dist'),
52 | assetsSubDirectory: 'static',
53 | assetsPublicPath: '/',
54 |
55 | /**
56 | * Source Maps
57 | */
58 |
59 | productionSourceMap: true,
60 | // https://webpack.js.org/configuration/devtool/#production
61 | devtool: '#source-map',
62 |
63 | // Gzip off by default as many popular static hosts such as
64 | // Surge or Netlify already gzip all static assets for you.
65 | // Before setting to `true`, make sure to:
66 | // npm install --save-dev compression-webpack-plugin
67 | productionGzip: false,
68 | productionGzipExtensions: ['js', 'css'],
69 |
70 | // Run the build command with an extra argument to
71 | // View the bundle analyzer report after build finishes:
72 | // `npm run build --report`
73 | // Set to `true` or `false` to always turn it on or off
74 | bundleAnalyzerReport: process.env.npm_config_report
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/chapter3/vue-state/1/config/prod.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | module.exports = {
3 | NODE_ENV: '"production"'
4 | }
5 |
--------------------------------------------------------------------------------
/chapter3/vue-state/1/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | vue-state-demo
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/chapter3/vue-state/1/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-router-demo",
3 | "version": "1.0.0",
4 | "description": "Vue.js Router Demo Project",
5 | "author": "yugasun ",
6 | "private": true,
7 | "scripts": {
8 | "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
9 | "start": "npm run dev",
10 | "lint": "eslint --ext .js,.vue src",
11 | "build": "node build/build.js"
12 | },
13 | "dependencies": {
14 | "vue": "^2.5.16"
15 | },
16 | "devDependencies": {
17 | "autoprefixer": "^7.1.2",
18 | "babel-core": "^6.22.1",
19 | "babel-eslint": "^8.2.1",
20 | "babel-helper-vue-jsx-merge-props": "^2.0.3",
21 | "babel-loader": "^7.1.1",
22 | "babel-plugin-syntax-jsx": "^6.18.0",
23 | "babel-plugin-transform-runtime": "^6.22.0",
24 | "babel-plugin-transform-vue-jsx": "^3.5.0",
25 | "babel-preset-env": "^1.3.2",
26 | "babel-preset-stage-2": "^6.22.0",
27 | "chalk": "^2.0.1",
28 | "copy-webpack-plugin": "^4.0.1",
29 | "css-loader": "^0.28.0",
30 | "eslint": "^4.15.0",
31 | "eslint-config-airbnb-base": "^11.3.0",
32 | "eslint-friendly-formatter": "^3.0.0",
33 | "eslint-import-resolver-webpack": "^0.8.3",
34 | "eslint-loader": "^1.7.1",
35 | "eslint-plugin-import": "^2.7.0",
36 | "eslint-plugin-vue": "^4.0.0",
37 | "extract-text-webpack-plugin": "^3.0.0",
38 | "file-loader": "^1.1.4",
39 | "friendly-errors-webpack-plugin": "^1.6.1",
40 | "html-webpack-plugin": "^2.30.1",
41 | "node-notifier": "^5.1.2",
42 | "optimize-css-assets-webpack-plugin": "^3.2.0",
43 | "ora": "^1.2.0",
44 | "portfinder": "^1.0.13",
45 | "postcss-import": "^11.0.0",
46 | "postcss-loader": "^2.0.8",
47 | "postcss-url": "^7.2.1",
48 | "rimraf": "^2.6.0",
49 | "semver": "^5.3.0",
50 | "shelljs": "^0.7.6",
51 | "uglifyjs-webpack-plugin": "^1.1.1",
52 | "url-loader": "^0.5.8",
53 | "vue-loader": "^13.3.0",
54 | "vue-style-loader": "^3.0.1",
55 | "vue-template-compiler": "^2.5.16",
56 | "webpack": "^3.6.0",
57 | "webpack-bundle-analyzer": "^2.9.0",
58 | "webpack-dev-server": "^2.9.1",
59 | "webpack-merge": "^4.1.0"
60 | },
61 | "engines": {
62 | "node": ">= 6.0.0",
63 | "npm": ">= 3.0.0"
64 | },
65 | "browserslist": [
66 | "> 1%",
67 | "last 2 versions",
68 | "not ie <= 8"
69 | ]
70 | }
71 |
--------------------------------------------------------------------------------
/chapter3/vue-state/1/src/App.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
19 |
--------------------------------------------------------------------------------
/chapter3/vue-state/1/src/components/comp1.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Component 1
4 |
5 |
6 |
7 |
19 |
20 |
--------------------------------------------------------------------------------
/chapter3/vue-state/1/src/components/comp2.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Component 2
4 |
5 |
6 |
7 |
19 |
20 |
--------------------------------------------------------------------------------
/chapter3/vue-state/1/src/main.js:
--------------------------------------------------------------------------------
1 | // The Vue build version to load with the `import` command
2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
3 | import Vue from 'vue';
4 | import App from './App';
5 |
6 | Vue.config.productionTip = false;
7 |
8 | /* eslint-disable no-new */
9 | new Vue({
10 | el: '#app',
11 | template: '',
12 | components: { App },
13 | });
14 |
--------------------------------------------------------------------------------
/chapter3/vue-state/1/src/state.js:
--------------------------------------------------------------------------------
1 | export default {
2 | msg: 'Hello world',
3 | };
4 |
--------------------------------------------------------------------------------
/chapter3/vue-state/1/static/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/chapter3/vue-state/1/static/.gitkeep
--------------------------------------------------------------------------------
/chapter3/vue-state/2/.babelrc:
--------------------------------------------------------------------------------
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-vue-jsx", "transform-runtime"]
12 | }
13 |
--------------------------------------------------------------------------------
/chapter3/vue-state/2/.editorconfig:
--------------------------------------------------------------------------------
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
10 |
--------------------------------------------------------------------------------
/chapter3/vue-state/2/.eslintignore:
--------------------------------------------------------------------------------
1 | /build/
2 | /config/
3 | /dist/
4 | /*.js
5 |
--------------------------------------------------------------------------------
/chapter3/vue-state/2/.eslintrc.js:
--------------------------------------------------------------------------------
1 | // https://eslint.org/docs/user-guide/configuring
2 |
3 | module.exports = {
4 | root: true,
5 | parserOptions: {
6 | parser: 'babel-eslint'
7 | },
8 | env: {
9 | browser: true,
10 | },
11 | // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
12 | // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
13 | extends: ['plugin:vue/essential', 'airbnb-base'],
14 | // required to lint *.vue files
15 | plugins: [
16 | 'vue'
17 | ],
18 | // check if imports actually resolve
19 | settings: {
20 | 'import/resolver': {
21 | webpack: {
22 | config: 'build/webpack.base.conf.js'
23 | }
24 | }
25 | },
26 | // add your custom rules here
27 | rules: {
28 | // don't require .vue extension when importing
29 | 'import/extensions': ['error', 'always', {
30 | js: 'never',
31 | vue: 'never'
32 | }],
33 | // disallow reassignment of function parameters
34 | // disallow parameter object manipulation except for specific exclusions
35 | 'no-param-reassign': ['error', {
36 | props: true,
37 | ignorePropertyModificationsFor: [
38 | 'state', // for vuex state
39 | 'acc', // for reduce accumulators
40 | 'e' // for e.returnvalue
41 | ]
42 | }],
43 | // allow optionalDependencies
44 | 'import/no-extraneous-dependencies': ['error', {
45 | optionalDependencies: ['test/unit/index.js']
46 | }],
47 | // allow debugger during development
48 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/chapter3/vue-state/2/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | /dist/
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Editor directories and files
9 | .idea
10 | .vscode
11 | *.suo
12 | *.ntvs*
13 | *.njsproj
14 | *.sln
15 |
--------------------------------------------------------------------------------
/chapter3/vue-state/2/.postcssrc.js:
--------------------------------------------------------------------------------
1 | // https://github.com/michael-ciniawsky/postcss-load-config
2 |
3 | module.exports = {
4 | "plugins": {
5 | "postcss-import": {},
6 | "postcss-url": {},
7 | // to edit target browsers: use "browserslist" field in package.json
8 | "autoprefixer": {}
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/chapter3/vue-state/2/README.md:
--------------------------------------------------------------------------------
1 | # vue-router-demo
2 |
3 | > Vue.js Router Demo Project
4 |
5 | ## Build Setup
6 |
7 | ``` bash
8 | # install dependencies
9 | npm install
10 |
11 | # serve with hot reload at localhost:8080
12 | npm run dev
13 |
14 | # build for production with minification
15 | npm run build
16 |
17 | # build for production and view the bundle analyzer report
18 | npm run build --report
19 | ```
20 |
21 | For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
22 |
--------------------------------------------------------------------------------
/chapter3/vue-state/2/build/build.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | require('./check-versions')()
3 |
4 | process.env.NODE_ENV = 'production'
5 |
6 | const ora = require('ora')
7 | const rm = require('rimraf')
8 | const path = require('path')
9 | const chalk = require('chalk')
10 | const webpack = require('webpack')
11 | const config = require('../config')
12 | const webpackConfig = require('./webpack.prod.conf')
13 |
14 | const spinner = ora('building for production...')
15 | spinner.start()
16 |
17 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
18 | if (err) throw err
19 | webpack(webpackConfig, (err, stats) => {
20 | spinner.stop()
21 | if (err) throw err
22 | process.stdout.write(stats.toString({
23 | colors: true,
24 | modules: false,
25 | children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
26 | chunks: false,
27 | chunkModules: false
28 | }) + '\n\n')
29 |
30 | if (stats.hasErrors()) {
31 | console.log(chalk.red(' Build failed with errors.\n'))
32 | process.exit(1)
33 | }
34 |
35 | console.log(chalk.cyan(' Build complete.\n'))
36 | console.log(chalk.yellow(
37 | ' Tip: built files are meant to be served over an HTTP server.\n' +
38 | ' Opening index.html over file:// won\'t work.\n'
39 | ))
40 | })
41 | })
42 |
--------------------------------------------------------------------------------
/chapter3/vue-state/2/build/check-versions.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const chalk = require('chalk')
3 | const semver = require('semver')
4 | const packageConfig = require('../package.json')
5 | const shell = require('shelljs')
6 |
7 | function exec (cmd) {
8 | return require('child_process').execSync(cmd).toString().trim()
9 | }
10 |
11 | const versionRequirements = [
12 | {
13 | name: 'node',
14 | currentVersion: semver.clean(process.version),
15 | versionRequirement: packageConfig.engines.node
16 | }
17 | ]
18 |
19 | if (shell.which('npm')) {
20 | versionRequirements.push({
21 | name: 'npm',
22 | currentVersion: exec('npm --version'),
23 | versionRequirement: packageConfig.engines.npm
24 | })
25 | }
26 |
27 | module.exports = function () {
28 | const warnings = []
29 |
30 | for (let i = 0; i < versionRequirements.length; i++) {
31 | const mod = versionRequirements[i]
32 |
33 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
34 | warnings.push(mod.name + ': ' +
35 | chalk.red(mod.currentVersion) + ' should be ' +
36 | chalk.green(mod.versionRequirement)
37 | )
38 | }
39 | }
40 |
41 | if (warnings.length) {
42 | console.log('')
43 | console.log(chalk.yellow('To use this template, you must update following to modules:'))
44 | console.log()
45 |
46 | for (let i = 0; i < warnings.length; i++) {
47 | const warning = warnings[i]
48 | console.log(' ' + warning)
49 | }
50 |
51 | console.log()
52 | process.exit(1)
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/chapter3/vue-state/2/build/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/chapter3/vue-state/2/build/logo.png
--------------------------------------------------------------------------------
/chapter3/vue-state/2/build/vue-loader.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const utils = require('./utils')
3 | const config = require('../config')
4 | const isProduction = process.env.NODE_ENV === 'production'
5 | const sourceMapEnabled = isProduction
6 | ? config.build.productionSourceMap
7 | : config.dev.cssSourceMap
8 |
9 | module.exports = {
10 | loaders: utils.cssLoaders({
11 | sourceMap: sourceMapEnabled,
12 | extract: isProduction
13 | }),
14 | cssSourceMap: sourceMapEnabled,
15 | cacheBusting: config.dev.cacheBusting,
16 | transformToRequire: {
17 | video: ['src', 'poster'],
18 | source: 'src',
19 | img: 'src',
20 | image: 'xlink:href'
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/chapter3/vue-state/2/config/dev.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const merge = require('webpack-merge')
3 | const prodEnv = require('./prod.env')
4 |
5 | module.exports = merge(prodEnv, {
6 | NODE_ENV: '"development"'
7 | })
8 |
--------------------------------------------------------------------------------
/chapter3/vue-state/2/config/index.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | // Template version: 1.3.1
3 | // see http://vuejs-templates.github.io/webpack for documentation.
4 |
5 | const path = require('path')
6 |
7 | module.exports = {
8 | dev: {
9 |
10 | // Paths
11 | assetsSubDirectory: 'static',
12 | assetsPublicPath: '/',
13 | proxyTable: {},
14 |
15 | // Various Dev Server settings
16 | host: 'localhost', // can be overwritten by process.env.HOST
17 | port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
18 | autoOpenBrowser: false,
19 | errorOverlay: true,
20 | notifyOnErrors: true,
21 | poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
22 |
23 | // Use Eslint Loader?
24 | // If true, your code will be linted during bundling and
25 | // linting errors and warnings will be shown in the console.
26 | useEslint: true,
27 | // If true, eslint errors and warnings will also be shown in the error overlay
28 | // in the browser.
29 | showEslintErrorsInOverlay: false,
30 |
31 | /**
32 | * Source Maps
33 | */
34 |
35 | // https://webpack.js.org/configuration/devtool/#development
36 | devtool: 'cheap-module-eval-source-map',
37 |
38 | // If you have problems debugging vue-files in devtools,
39 | // set this to false - it *may* help
40 | // https://vue-loader.vuejs.org/en/options.html#cachebusting
41 | cacheBusting: true,
42 |
43 | cssSourceMap: true
44 | },
45 |
46 | build: {
47 | // Template for index.html
48 | index: path.resolve(__dirname, '../dist/index.html'),
49 |
50 | // Paths
51 | assetsRoot: path.resolve(__dirname, '../dist'),
52 | assetsSubDirectory: 'static',
53 | assetsPublicPath: '/',
54 |
55 | /**
56 | * Source Maps
57 | */
58 |
59 | productionSourceMap: true,
60 | // https://webpack.js.org/configuration/devtool/#production
61 | devtool: '#source-map',
62 |
63 | // Gzip off by default as many popular static hosts such as
64 | // Surge or Netlify already gzip all static assets for you.
65 | // Before setting to `true`, make sure to:
66 | // npm install --save-dev compression-webpack-plugin
67 | productionGzip: false,
68 | productionGzipExtensions: ['js', 'css'],
69 |
70 | // Run the build command with an extra argument to
71 | // View the bundle analyzer report after build finishes:
72 | // `npm run build --report`
73 | // Set to `true` or `false` to always turn it on or off
74 | bundleAnalyzerReport: process.env.npm_config_report
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/chapter3/vue-state/2/config/prod.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | module.exports = {
3 | NODE_ENV: '"production"'
4 | }
5 |
--------------------------------------------------------------------------------
/chapter3/vue-state/2/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | vue-state-demo
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/chapter3/vue-state/2/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-router-demo",
3 | "version": "1.0.0",
4 | "description": "Vue.js Router Demo Project",
5 | "author": "yugasun ",
6 | "private": true,
7 | "scripts": {
8 | "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
9 | "start": "npm run dev",
10 | "lint": "eslint --ext .js,.vue src",
11 | "build": "node build/build.js"
12 | },
13 | "dependencies": {
14 | "vue": "^2.5.16"
15 | },
16 | "devDependencies": {
17 | "autoprefixer": "^7.1.2",
18 | "babel-core": "^6.22.1",
19 | "babel-eslint": "^8.2.1",
20 | "babel-helper-vue-jsx-merge-props": "^2.0.3",
21 | "babel-loader": "^7.1.1",
22 | "babel-plugin-syntax-jsx": "^6.18.0",
23 | "babel-plugin-transform-runtime": "^6.22.0",
24 | "babel-plugin-transform-vue-jsx": "^3.5.0",
25 | "babel-preset-env": "^1.3.2",
26 | "babel-preset-stage-2": "^6.22.0",
27 | "chalk": "^2.0.1",
28 | "copy-webpack-plugin": "^4.0.1",
29 | "css-loader": "^0.28.0",
30 | "eslint": "^4.15.0",
31 | "eslint-config-airbnb-base": "^11.3.0",
32 | "eslint-friendly-formatter": "^3.0.0",
33 | "eslint-import-resolver-webpack": "^0.8.3",
34 | "eslint-loader": "^1.7.1",
35 | "eslint-plugin-import": "^2.7.0",
36 | "eslint-plugin-vue": "^4.0.0",
37 | "extract-text-webpack-plugin": "^3.0.0",
38 | "file-loader": "^1.1.4",
39 | "friendly-errors-webpack-plugin": "^1.6.1",
40 | "html-webpack-plugin": "^2.30.1",
41 | "node-notifier": "^5.1.2",
42 | "optimize-css-assets-webpack-plugin": "^3.2.0",
43 | "ora": "^1.2.0",
44 | "portfinder": "^1.0.13",
45 | "postcss-import": "^11.0.0",
46 | "postcss-loader": "^2.0.8",
47 | "postcss-url": "^7.2.1",
48 | "rimraf": "^2.6.0",
49 | "semver": "^5.3.0",
50 | "shelljs": "^0.7.6",
51 | "uglifyjs-webpack-plugin": "^1.1.1",
52 | "url-loader": "^0.5.8",
53 | "vue-loader": "^13.3.0",
54 | "vue-style-loader": "^3.0.1",
55 | "vue-template-compiler": "^2.5.16",
56 | "webpack": "^3.6.0",
57 | "webpack-bundle-analyzer": "^2.9.0",
58 | "webpack-dev-server": "^2.9.1",
59 | "webpack-merge": "^4.1.0"
60 | },
61 | "engines": {
62 | "node": ">= 6.0.0",
63 | "npm": ">= 3.0.0"
64 | },
65 | "browserslist": [
66 | "> 1%",
67 | "last 2 versions",
68 | "not ie <= 8"
69 | ]
70 | }
71 |
--------------------------------------------------------------------------------
/chapter3/vue-state/2/src/App.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
19 |
--------------------------------------------------------------------------------
/chapter3/vue-state/2/src/components/comp1.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Component 1
4 |
5 |
6 |
7 |
18 |
19 |
--------------------------------------------------------------------------------
/chapter3/vue-state/2/src/components/comp2.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Component 2
4 |
5 |
6 |
7 |
18 |
19 |
--------------------------------------------------------------------------------
/chapter3/vue-state/2/src/main.js:
--------------------------------------------------------------------------------
1 | // The Vue build version to load with the `import` command
2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
3 | import Vue from 'vue';
4 | import App from './App';
5 |
6 | Vue.config.productionTip = false;
7 |
8 | /* eslint-disable no-new */
9 | new Vue({
10 | el: '#app',
11 | template: '',
12 | components: { App },
13 | });
14 |
--------------------------------------------------------------------------------
/chapter3/vue-state/2/src/state.js:
--------------------------------------------------------------------------------
1 | const state = {
2 | msg: 'Hello world',
3 | };
4 |
5 | export default {
6 | data() {
7 | return {
8 | state,
9 | };
10 | },
11 | };
12 |
13 |
--------------------------------------------------------------------------------
/chapter3/vue-state/2/static/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/chapter3/vue-state/2/static/.gitkeep
--------------------------------------------------------------------------------
/chapter3/vue-state/3/.babelrc:
--------------------------------------------------------------------------------
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-vue-jsx", "transform-runtime"]
12 | }
13 |
--------------------------------------------------------------------------------
/chapter3/vue-state/3/.editorconfig:
--------------------------------------------------------------------------------
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
10 |
--------------------------------------------------------------------------------
/chapter3/vue-state/3/.eslintignore:
--------------------------------------------------------------------------------
1 | /build/
2 | /config/
3 | /dist/
4 | /*.js
5 |
--------------------------------------------------------------------------------
/chapter3/vue-state/3/.eslintrc.js:
--------------------------------------------------------------------------------
1 | // https://eslint.org/docs/user-guide/configuring
2 |
3 | module.exports = {
4 | root: true,
5 | parserOptions: {
6 | parser: 'babel-eslint'
7 | },
8 | env: {
9 | browser: true,
10 | },
11 | // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
12 | // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
13 | extends: ['plugin:vue/essential', 'airbnb-base'],
14 | // required to lint *.vue files
15 | plugins: [
16 | 'vue'
17 | ],
18 | // check if imports actually resolve
19 | settings: {
20 | 'import/resolver': {
21 | webpack: {
22 | config: 'build/webpack.base.conf.js'
23 | }
24 | }
25 | },
26 | // add your custom rules here
27 | rules: {
28 | // don't require .vue extension when importing
29 | 'import/extensions': ['error', 'always', {
30 | js: 'never',
31 | vue: 'never'
32 | }],
33 | // disallow reassignment of function parameters
34 | // disallow parameter object manipulation except for specific exclusions
35 | 'no-param-reassign': ['error', {
36 | props: true,
37 | ignorePropertyModificationsFor: [
38 | 'state', // for vuex state
39 | 'acc', // for reduce accumulators
40 | 'e' // for e.returnvalue
41 | ]
42 | }],
43 | // allow optionalDependencies
44 | 'import/no-extraneous-dependencies': ['error', {
45 | optionalDependencies: ['test/unit/index.js']
46 | }],
47 | // allow debugger during development
48 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
49 | 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off'
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/chapter3/vue-state/3/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | /dist/
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Editor directories and files
9 | .idea
10 | .vscode
11 | *.suo
12 | *.ntvs*
13 | *.njsproj
14 | *.sln
15 |
--------------------------------------------------------------------------------
/chapter3/vue-state/3/.postcssrc.js:
--------------------------------------------------------------------------------
1 | // https://github.com/michael-ciniawsky/postcss-load-config
2 |
3 | module.exports = {
4 | "plugins": {
5 | "postcss-import": {},
6 | "postcss-url": {},
7 | // to edit target browsers: use "browserslist" field in package.json
8 | "autoprefixer": {}
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/chapter3/vue-state/3/README.md:
--------------------------------------------------------------------------------
1 | # vue-router-demo
2 |
3 | > Vue.js Router Demo Project
4 |
5 | ## Build Setup
6 |
7 | ``` bash
8 | # install dependencies
9 | npm install
10 |
11 | # serve with hot reload at localhost:8080
12 | npm run dev
13 |
14 | # build for production with minification
15 | npm run build
16 |
17 | # build for production and view the bundle analyzer report
18 | npm run build --report
19 | ```
20 |
21 | For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
22 |
--------------------------------------------------------------------------------
/chapter3/vue-state/3/build/build.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | require('./check-versions')()
3 |
4 | process.env.NODE_ENV = 'production'
5 |
6 | const ora = require('ora')
7 | const rm = require('rimraf')
8 | const path = require('path')
9 | const chalk = require('chalk')
10 | const webpack = require('webpack')
11 | const config = require('../config')
12 | const webpackConfig = require('./webpack.prod.conf')
13 |
14 | const spinner = ora('building for production...')
15 | spinner.start()
16 |
17 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
18 | if (err) throw err
19 | webpack(webpackConfig, (err, stats) => {
20 | spinner.stop()
21 | if (err) throw err
22 | process.stdout.write(stats.toString({
23 | colors: true,
24 | modules: false,
25 | children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
26 | chunks: false,
27 | chunkModules: false
28 | }) + '\n\n')
29 |
30 | if (stats.hasErrors()) {
31 | console.log(chalk.red(' Build failed with errors.\n'))
32 | process.exit(1)
33 | }
34 |
35 | console.log(chalk.cyan(' Build complete.\n'))
36 | console.log(chalk.yellow(
37 | ' Tip: built files are meant to be served over an HTTP server.\n' +
38 | ' Opening index.html over file:// won\'t work.\n'
39 | ))
40 | })
41 | })
42 |
--------------------------------------------------------------------------------
/chapter3/vue-state/3/build/check-versions.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const chalk = require('chalk')
3 | const semver = require('semver')
4 | const packageConfig = require('../package.json')
5 | const shell = require('shelljs')
6 |
7 | function exec (cmd) {
8 | return require('child_process').execSync(cmd).toString().trim()
9 | }
10 |
11 | const versionRequirements = [
12 | {
13 | name: 'node',
14 | currentVersion: semver.clean(process.version),
15 | versionRequirement: packageConfig.engines.node
16 | }
17 | ]
18 |
19 | if (shell.which('npm')) {
20 | versionRequirements.push({
21 | name: 'npm',
22 | currentVersion: exec('npm --version'),
23 | versionRequirement: packageConfig.engines.npm
24 | })
25 | }
26 |
27 | module.exports = function () {
28 | const warnings = []
29 |
30 | for (let i = 0; i < versionRequirements.length; i++) {
31 | const mod = versionRequirements[i]
32 |
33 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
34 | warnings.push(mod.name + ': ' +
35 | chalk.red(mod.currentVersion) + ' should be ' +
36 | chalk.green(mod.versionRequirement)
37 | )
38 | }
39 | }
40 |
41 | if (warnings.length) {
42 | console.log('')
43 | console.log(chalk.yellow('To use this template, you must update following to modules:'))
44 | console.log()
45 |
46 | for (let i = 0; i < warnings.length; i++) {
47 | const warning = warnings[i]
48 | console.log(' ' + warning)
49 | }
50 |
51 | console.log()
52 | process.exit(1)
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/chapter3/vue-state/3/build/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/chapter3/vue-state/3/build/logo.png
--------------------------------------------------------------------------------
/chapter3/vue-state/3/build/vue-loader.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const utils = require('./utils')
3 | const config = require('../config')
4 | const isProduction = process.env.NODE_ENV === 'production'
5 | const sourceMapEnabled = isProduction
6 | ? config.build.productionSourceMap
7 | : config.dev.cssSourceMap
8 |
9 | module.exports = {
10 | loaders: utils.cssLoaders({
11 | sourceMap: sourceMapEnabled,
12 | extract: isProduction
13 | }),
14 | cssSourceMap: sourceMapEnabled,
15 | cacheBusting: config.dev.cacheBusting,
16 | transformToRequire: {
17 | video: ['src', 'poster'],
18 | source: 'src',
19 | img: 'src',
20 | image: 'xlink:href'
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/chapter3/vue-state/3/config/dev.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const merge = require('webpack-merge')
3 | const prodEnv = require('./prod.env')
4 |
5 | module.exports = merge(prodEnv, {
6 | NODE_ENV: '"development"'
7 | })
8 |
--------------------------------------------------------------------------------
/chapter3/vue-state/3/config/index.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | // Template version: 1.3.1
3 | // see http://vuejs-templates.github.io/webpack for documentation.
4 |
5 | const path = require('path')
6 |
7 | module.exports = {
8 | dev: {
9 |
10 | // Paths
11 | assetsSubDirectory: 'static',
12 | assetsPublicPath: '/',
13 | proxyTable: {},
14 |
15 | // Various Dev Server settings
16 | host: 'localhost', // can be overwritten by process.env.HOST
17 | port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
18 | autoOpenBrowser: false,
19 | errorOverlay: true,
20 | notifyOnErrors: true,
21 | poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
22 |
23 | // Use Eslint Loader?
24 | // If true, your code will be linted during bundling and
25 | // linting errors and warnings will be shown in the console.
26 | useEslint: true,
27 | // If true, eslint errors and warnings will also be shown in the error overlay
28 | // in the browser.
29 | showEslintErrorsInOverlay: false,
30 |
31 | /**
32 | * Source Maps
33 | */
34 |
35 | // https://webpack.js.org/configuration/devtool/#development
36 | devtool: 'cheap-module-eval-source-map',
37 |
38 | // If you have problems debugging vue-files in devtools,
39 | // set this to false - it *may* help
40 | // https://vue-loader.vuejs.org/en/options.html#cachebusting
41 | cacheBusting: true,
42 |
43 | cssSourceMap: true
44 | },
45 |
46 | build: {
47 | // Template for index.html
48 | index: path.resolve(__dirname, '../dist/index.html'),
49 |
50 | // Paths
51 | assetsRoot: path.resolve(__dirname, '../dist'),
52 | assetsSubDirectory: 'static',
53 | assetsPublicPath: '/',
54 |
55 | /**
56 | * Source Maps
57 | */
58 |
59 | productionSourceMap: true,
60 | // https://webpack.js.org/configuration/devtool/#production
61 | devtool: '#source-map',
62 |
63 | // Gzip off by default as many popular static hosts such as
64 | // Surge or Netlify already gzip all static assets for you.
65 | // Before setting to `true`, make sure to:
66 | // npm install --save-dev compression-webpack-plugin
67 | productionGzip: false,
68 | productionGzipExtensions: ['js', 'css'],
69 |
70 | // Run the build command with an extra argument to
71 | // View the bundle analyzer report after build finishes:
72 | // `npm run build --report`
73 | // Set to `true` or `false` to always turn it on or off
74 | bundleAnalyzerReport: process.env.npm_config_report
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/chapter3/vue-state/3/config/prod.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | module.exports = {
3 | NODE_ENV: '"production"'
4 | }
5 |
--------------------------------------------------------------------------------
/chapter3/vue-state/3/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | vue-state-demo
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/chapter3/vue-state/3/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-router-demo",
3 | "version": "1.0.0",
4 | "description": "Vue.js Router Demo Project",
5 | "author": "yugasun ",
6 | "private": true,
7 | "scripts": {
8 | "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
9 | "start": "npm run dev",
10 | "lint": "eslint --ext .js,.vue src",
11 | "build": "node build/build.js"
12 | },
13 | "dependencies": {
14 | "vue": "^2.5.16"
15 | },
16 | "devDependencies": {
17 | "autoprefixer": "^7.1.2",
18 | "babel-core": "^6.22.1",
19 | "babel-eslint": "^8.2.1",
20 | "babel-helper-vue-jsx-merge-props": "^2.0.3",
21 | "babel-loader": "^7.1.1",
22 | "babel-plugin-syntax-jsx": "^6.18.0",
23 | "babel-plugin-transform-runtime": "^6.22.0",
24 | "babel-plugin-transform-vue-jsx": "^3.5.0",
25 | "babel-preset-env": "^1.3.2",
26 | "babel-preset-stage-2": "^6.22.0",
27 | "chalk": "^2.0.1",
28 | "copy-webpack-plugin": "^4.0.1",
29 | "css-loader": "^0.28.0",
30 | "eslint": "^4.15.0",
31 | "eslint-config-airbnb-base": "^11.3.0",
32 | "eslint-friendly-formatter": "^3.0.0",
33 | "eslint-import-resolver-webpack": "^0.8.3",
34 | "eslint-loader": "^1.7.1",
35 | "eslint-plugin-import": "^2.7.0",
36 | "eslint-plugin-vue": "^4.0.0",
37 | "extract-text-webpack-plugin": "^3.0.0",
38 | "file-loader": "^1.1.4",
39 | "friendly-errors-webpack-plugin": "^1.6.1",
40 | "html-webpack-plugin": "^2.30.1",
41 | "node-notifier": "^5.1.2",
42 | "optimize-css-assets-webpack-plugin": "^3.2.0",
43 | "ora": "^1.2.0",
44 | "portfinder": "^1.0.13",
45 | "postcss-import": "^11.0.0",
46 | "postcss-loader": "^2.0.8",
47 | "postcss-url": "^7.2.1",
48 | "rimraf": "^2.6.0",
49 | "semver": "^5.3.0",
50 | "shelljs": "^0.7.6",
51 | "uglifyjs-webpack-plugin": "^1.1.1",
52 | "url-loader": "^0.5.8",
53 | "vue-loader": "^13.3.0",
54 | "vue-style-loader": "^3.0.1",
55 | "vue-template-compiler": "^2.5.16",
56 | "webpack": "^3.6.0",
57 | "webpack-bundle-analyzer": "^2.9.0",
58 | "webpack-dev-server": "^2.9.1",
59 | "webpack-merge": "^4.1.0"
60 | },
61 | "engines": {
62 | "node": ">= 6.0.0",
63 | "npm": ">= 3.0.0"
64 | },
65 | "browserslist": [
66 | "> 1%",
67 | "last 2 versions",
68 | "not ie <= 8"
69 | ]
70 | }
71 |
--------------------------------------------------------------------------------
/chapter3/vue-state/3/src/App.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
19 |
--------------------------------------------------------------------------------
/chapter3/vue-state/3/src/components/comp1.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Component 1
4 | Change by object reference:
5 | Change by event:
6 |
7 |
8 |
29 |
30 |
--------------------------------------------------------------------------------
/chapter3/vue-state/3/src/components/comp2.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Component 2
4 | Change by object reference:
5 | Change by event:
6 |
7 |
8 |
30 |
31 |
--------------------------------------------------------------------------------
/chapter3/vue-state/3/src/main.js:
--------------------------------------------------------------------------------
1 | // The Vue build version to load with the `import` command
2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
3 | import Vue from 'vue';
4 | import App from './App';
5 | import EventBus from './state';
6 |
7 | Vue.prototype.$bus = EventBus;
8 | Vue.config.productionTip = false;
9 |
10 | /* eslint-disable no-new */
11 | new Vue({
12 | el: '#app',
13 | template: '',
14 | components: { App },
15 | });
16 |
--------------------------------------------------------------------------------
/chapter3/vue-state/3/src/state.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 |
3 | const EventBus = new Vue({
4 | data: {
5 | msg: 'Hello world',
6 | },
7 | watch: {
8 | // 这里为了实现对象引用监听,然后出发change事件,实现状态同步
9 | msg(val) {
10 | this.$emit('msg-change', { value: val });
11 | },
12 | },
13 | });
14 |
15 | EventBus.$on('msg-change', (payload) => {
16 | console.log(`Msg has changed to ${payload.value}`);
17 | EventBus.msg = payload.value;
18 | });
19 |
20 | export default EventBus;
21 |
--------------------------------------------------------------------------------
/chapter3/vue-state/3/static/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/chapter3/vue-state/3/static/.gitkeep
--------------------------------------------------------------------------------
/chapter4/1/.babelrc:
--------------------------------------------------------------------------------
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-vue-jsx", "transform-runtime"]
12 | }
13 |
--------------------------------------------------------------------------------
/chapter4/1/.editorconfig:
--------------------------------------------------------------------------------
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
10 |
--------------------------------------------------------------------------------
/chapter4/1/.eslintignore:
--------------------------------------------------------------------------------
1 | /build/
2 | /config/
3 | /dist/
4 | /*.js
5 |
--------------------------------------------------------------------------------
/chapter4/1/.eslintrc.js:
--------------------------------------------------------------------------------
1 | // https://eslint.org/docs/user-guide/configuring
2 |
3 | module.exports = {
4 | root: true,
5 | parserOptions: {
6 | parser: 'babel-eslint'
7 | },
8 | env: {
9 | browser: true,
10 | },
11 | // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
12 | // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
13 | extends: ['plugin:vue/essential', 'airbnb-base'],
14 | // required to lint *.vue files
15 | plugins: [
16 | 'vue'
17 | ],
18 | // check if imports actually resolve
19 | settings: {
20 | 'import/resolver': {
21 | webpack: {
22 | config: 'build/webpack.base.conf.js'
23 | }
24 | }
25 | },
26 | // add your custom rules here
27 | rules: {
28 | // don't require .vue extension when importing
29 | 'import/extensions': ['error', 'always', {
30 | js: 'never',
31 | vue: 'never'
32 | }],
33 | // disallow reassignment of function parameters
34 | // disallow parameter object manipulation except for specific exclusions
35 | 'no-param-reassign': ['error', {
36 | props: true,
37 | ignorePropertyModificationsFor: [
38 | 'state', // for vuex state
39 | 'acc', // for reduce accumulators
40 | 'e' // for e.returnvalue
41 | ]
42 | }],
43 | // allow optionalDependencies
44 | 'import/no-extraneous-dependencies': ['error', {
45 | optionalDependencies: ['test/unit/index.js']
46 | }],
47 | // allow debugger during development
48 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/chapter4/1/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | /dist/
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Editor directories and files
9 | .idea
10 | .vscode
11 | *.suo
12 | *.ntvs*
13 | *.njsproj
14 | *.sln
15 |
--------------------------------------------------------------------------------
/chapter4/1/.postcssrc.js:
--------------------------------------------------------------------------------
1 | // https://github.com/michael-ciniawsky/postcss-load-config
2 |
3 | module.exports = {
4 | "plugins": {
5 | "postcss-import": {},
6 | "postcss-url": {},
7 | // to edit target browsers: use "browserslist" field in package.json
8 | "autoprefixer": {}
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/chapter4/1/README.md:
--------------------------------------------------------------------------------
1 | # vue-router-demo
2 |
3 | > Vue.js Router Demo Project
4 |
5 | ## Build Setup
6 |
7 | ``` bash
8 | # install dependencies
9 | npm install
10 |
11 | # serve with hot reload at localhost:8080
12 | npm run dev
13 |
14 | # build for production with minification
15 | npm run build
16 |
17 | # build for production and view the bundle analyzer report
18 | npm run build --report
19 | ```
20 |
21 | For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
22 |
--------------------------------------------------------------------------------
/chapter4/1/build/build.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | require('./check-versions')()
3 |
4 | process.env.NODE_ENV = 'production'
5 |
6 | const ora = require('ora')
7 | const rm = require('rimraf')
8 | const path = require('path')
9 | const chalk = require('chalk')
10 | const webpack = require('webpack')
11 | const config = require('../config')
12 | const webpackConfig = require('./webpack.prod.conf')
13 |
14 | const spinner = ora('building for production...')
15 | spinner.start()
16 |
17 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
18 | if (err) throw err
19 | webpack(webpackConfig, (err, stats) => {
20 | spinner.stop()
21 | if (err) throw err
22 | process.stdout.write(stats.toString({
23 | colors: true,
24 | modules: false,
25 | children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
26 | chunks: false,
27 | chunkModules: false
28 | }) + '\n\n')
29 |
30 | if (stats.hasErrors()) {
31 | console.log(chalk.red(' Build failed with errors.\n'))
32 | process.exit(1)
33 | }
34 |
35 | console.log(chalk.cyan(' Build complete.\n'))
36 | console.log(chalk.yellow(
37 | ' Tip: built files are meant to be served over an HTTP server.\n' +
38 | ' Opening index.html over file:// won\'t work.\n'
39 | ))
40 | })
41 | })
42 |
--------------------------------------------------------------------------------
/chapter4/1/build/check-versions.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const chalk = require('chalk')
3 | const semver = require('semver')
4 | const packageConfig = require('../package.json')
5 | const shell = require('shelljs')
6 |
7 | function exec (cmd) {
8 | return require('child_process').execSync(cmd).toString().trim()
9 | }
10 |
11 | const versionRequirements = [
12 | {
13 | name: 'node',
14 | currentVersion: semver.clean(process.version),
15 | versionRequirement: packageConfig.engines.node
16 | }
17 | ]
18 |
19 | if (shell.which('npm')) {
20 | versionRequirements.push({
21 | name: 'npm',
22 | currentVersion: exec('npm --version'),
23 | versionRequirement: packageConfig.engines.npm
24 | })
25 | }
26 |
27 | module.exports = function () {
28 | const warnings = []
29 |
30 | for (let i = 0; i < versionRequirements.length; i++) {
31 | const mod = versionRequirements[i]
32 |
33 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
34 | warnings.push(mod.name + ': ' +
35 | chalk.red(mod.currentVersion) + ' should be ' +
36 | chalk.green(mod.versionRequirement)
37 | )
38 | }
39 | }
40 |
41 | if (warnings.length) {
42 | console.log('')
43 | console.log(chalk.yellow('To use this template, you must update following to modules:'))
44 | console.log()
45 |
46 | for (let i = 0; i < warnings.length; i++) {
47 | const warning = warnings[i]
48 | console.log(' ' + warning)
49 | }
50 |
51 | console.log()
52 | process.exit(1)
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/chapter4/1/build/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/chapter4/1/build/logo.png
--------------------------------------------------------------------------------
/chapter4/1/build/vue-loader.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const utils = require('./utils')
3 | const config = require('../config')
4 | const isProduction = process.env.NODE_ENV === 'production'
5 | const sourceMapEnabled = isProduction
6 | ? config.build.productionSourceMap
7 | : config.dev.cssSourceMap
8 |
9 | module.exports = {
10 | loaders: utils.cssLoaders({
11 | sourceMap: sourceMapEnabled,
12 | extract: isProduction
13 | }),
14 | cssSourceMap: sourceMapEnabled,
15 | cacheBusting: config.dev.cacheBusting,
16 | transformToRequire: {
17 | video: ['src', 'poster'],
18 | source: 'src',
19 | img: 'src',
20 | image: 'xlink:href'
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/chapter4/1/build/webpack.base.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const path = require('path')
3 | const utils = require('./utils')
4 | const config = require('../config')
5 | const vueLoaderConfig = require('./vue-loader.conf')
6 |
7 | function resolve (dir) {
8 | return path.join(__dirname, '..', dir)
9 | }
10 |
11 | const createLintingRule = () => ({
12 | test: /\.(js|vue)$/,
13 | loader: 'eslint-loader',
14 | enforce: 'pre',
15 | include: [resolve('src'), resolve('test')],
16 | options: {
17 | formatter: require('eslint-friendly-formatter'),
18 | emitWarning: !config.dev.showEslintErrorsInOverlay
19 | }
20 | })
21 |
22 | module.exports = {
23 | context: path.resolve(__dirname, '../'),
24 | entry: {
25 | app: './src/main.js'
26 | },
27 | output: {
28 | path: config.build.assetsRoot,
29 | filename: '[name].js',
30 | publicPath: process.env.NODE_ENV === 'production'
31 | ? config.build.assetsPublicPath
32 | : config.dev.assetsPublicPath
33 | },
34 | resolve: {
35 | extensions: ['.js', '.vue', '.json'],
36 | alias: {
37 | 'vue$': 'vue/dist/vue.esm.js',
38 | '@': resolve('src'),
39 | }
40 | },
41 | module: {
42 | rules: [
43 | ...(config.dev.useEslint ? [createLintingRule()] : []),
44 | {
45 | test: /\.vue$/,
46 | loader: 'vue-loader',
47 | options: vueLoaderConfig
48 | },
49 | {
50 | test: /\.js$/,
51 | loader: 'babel-loader',
52 | include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
53 | },
54 | {
55 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
56 | loader: 'url-loader',
57 | options: {
58 | limit: 10000,
59 | name: utils.assetsPath('img/[name].[hash:7].[ext]')
60 | }
61 | },
62 | {
63 | test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
64 | loader: 'url-loader',
65 | options: {
66 | limit: 10000,
67 | name: utils.assetsPath('media/[name].[hash:7].[ext]')
68 | }
69 | },
70 | {
71 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
72 | loader: 'url-loader',
73 | options: {
74 | limit: 10000,
75 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
76 | }
77 | }
78 | ]
79 | },
80 | node: {
81 | // prevent webpack from injecting useless setImmediate polyfill because Vue
82 | // source contains it (although only uses it if it's native).
83 | setImmediate: false,
84 | // prevent webpack from injecting mocks to Node native modules
85 | // that does not make sense for the client
86 | dgram: 'empty',
87 | fs: 'empty',
88 | net: 'empty',
89 | tls: 'empty',
90 | child_process: 'empty'
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/chapter4/1/config/dev.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const merge = require('webpack-merge')
3 | const prodEnv = require('./prod.env')
4 |
5 | module.exports = merge(prodEnv, {
6 | NODE_ENV: '"development"'
7 | })
8 |
--------------------------------------------------------------------------------
/chapter4/1/config/index.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | // Template version: 1.3.1
3 | // see http://vuejs-templates.github.io/webpack for documentation.
4 |
5 | const path = require('path')
6 |
7 | module.exports = {
8 | dev: {
9 |
10 | // Paths
11 | assetsSubDirectory: 'static',
12 | assetsPublicPath: '/',
13 | proxyTable: {},
14 |
15 | // Various Dev Server settings
16 | host: 'localhost', // can be overwritten by process.env.HOST
17 | port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
18 | autoOpenBrowser: false,
19 | errorOverlay: true,
20 | notifyOnErrors: true,
21 | poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
22 |
23 | // Use Eslint Loader?
24 | // If true, your code will be linted during bundling and
25 | // linting errors and warnings will be shown in the console.
26 | useEslint: true,
27 | // If true, eslint errors and warnings will also be shown in the error overlay
28 | // in the browser.
29 | showEslintErrorsInOverlay: false,
30 |
31 | /**
32 | * Source Maps
33 | */
34 |
35 | // https://webpack.js.org/configuration/devtool/#development
36 | devtool: 'cheap-module-eval-source-map',
37 |
38 | // If you have problems debugging vue-files in devtools,
39 | // set this to false - it *may* help
40 | // https://vue-loader.vuejs.org/en/options.html#cachebusting
41 | cacheBusting: true,
42 |
43 | cssSourceMap: true
44 | },
45 |
46 | build: {
47 | // Template for index.html
48 | index: path.resolve(__dirname, '../dist/index.html'),
49 |
50 | // Paths
51 | assetsRoot: path.resolve(__dirname, '../dist'),
52 | assetsSubDirectory: 'static',
53 | assetsPublicPath: '/',
54 |
55 | /**
56 | * Source Maps
57 | */
58 |
59 | productionSourceMap: true,
60 | // https://webpack.js.org/configuration/devtool/#production
61 | devtool: '#source-map',
62 |
63 | // Gzip off by default as many popular static hosts such as
64 | // Surge or Netlify already gzip all static assets for you.
65 | // Before setting to `true`, make sure to:
66 | // npm install --save-dev compression-webpack-plugin
67 | productionGzip: false,
68 | productionGzipExtensions: ['js', 'css'],
69 |
70 | // Run the build command with an extra argument to
71 | // View the bundle analyzer report after build finishes:
72 | // `npm run build --report`
73 | // Set to `true` or `false` to always turn it on or off
74 | bundleAnalyzerReport: process.env.npm_config_report
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/chapter4/1/config/prod.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | module.exports = {
3 | NODE_ENV: '"production"'
4 | }
5 |
--------------------------------------------------------------------------------
/chapter4/1/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | vue-state-demo
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/chapter4/1/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-router-demo",
3 | "version": "1.0.0",
4 | "description": "Vue.js Router Demo Project",
5 | "author": "yugasun ",
6 | "private": true,
7 | "scripts": {
8 | "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
9 | "start": "npm run dev",
10 | "lint": "eslint --ext .js,.vue src",
11 | "build": "node build/build.js"
12 | },
13 | "dependencies": {
14 | "vue": "^2.5.16",
15 | "vue-router": "^3.0.1",
16 | "vuex": "^3.0.1"
17 | },
18 | "devDependencies": {
19 | "autoprefixer": "^7.1.2",
20 | "babel-core": "^6.22.1",
21 | "babel-eslint": "^8.2.1",
22 | "babel-helper-vue-jsx-merge-props": "^2.0.3",
23 | "babel-loader": "^7.1.1",
24 | "babel-plugin-syntax-jsx": "^6.18.0",
25 | "babel-plugin-transform-runtime": "^6.22.0",
26 | "babel-plugin-transform-vue-jsx": "^3.5.0",
27 | "babel-preset-env": "^1.3.2",
28 | "babel-preset-stage-2": "^6.22.0",
29 | "chalk": "^2.0.1",
30 | "copy-webpack-plugin": "^4.0.1",
31 | "css-loader": "^0.28.0",
32 | "eslint": "^4.15.0",
33 | "eslint-config-airbnb-base": "^11.3.0",
34 | "eslint-friendly-formatter": "^3.0.0",
35 | "eslint-import-resolver-webpack": "^0.8.3",
36 | "eslint-loader": "^1.7.1",
37 | "eslint-plugin-import": "^2.7.0",
38 | "eslint-plugin-vue": "^4.0.0",
39 | "extract-text-webpack-plugin": "^3.0.0",
40 | "file-loader": "^1.1.4",
41 | "friendly-errors-webpack-plugin": "^1.6.1",
42 | "html-webpack-plugin": "^2.30.1",
43 | "node-notifier": "^5.1.2",
44 | "optimize-css-assets-webpack-plugin": "^3.2.0",
45 | "ora": "^1.2.0",
46 | "portfinder": "^1.0.13",
47 | "postcss-import": "^11.0.0",
48 | "postcss-loader": "^2.0.8",
49 | "postcss-url": "^7.2.1",
50 | "rimraf": "^2.6.0",
51 | "semver": "^5.3.0",
52 | "shelljs": "^0.7.6",
53 | "uglifyjs-webpack-plugin": "^1.1.1",
54 | "url-loader": "^0.5.8",
55 | "vue-loader": "^13.3.0",
56 | "vue-style-loader": "^3.0.1",
57 | "vue-template-compiler": "^2.5.16",
58 | "webpack": "^3.6.0",
59 | "webpack-bundle-analyzer": "^2.9.0",
60 | "webpack-dev-server": "^2.9.1",
61 | "webpack-merge": "^4.1.0"
62 | },
63 | "engines": {
64 | "node": ">= 6.0.0",
65 | "npm": ">= 3.0.0"
66 | },
67 | "browserslist": [
68 | "> 1%",
69 | "last 2 versions",
70 | "not ie <= 8"
71 | ]
72 | }
73 |
--------------------------------------------------------------------------------
/chapter4/1/src/App.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
11 |
--------------------------------------------------------------------------------
/chapter4/1/src/components/comp1.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Component 1
4 |
5 |
6 |
7 |
8 |
44 |
45 |
--------------------------------------------------------------------------------
/chapter4/1/src/components/comp2.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Component 2
4 |
5 |
6 |
7 |
26 |
27 |
--------------------------------------------------------------------------------
/chapter4/1/src/components/comp3.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
12 |
17 |
18 |
--------------------------------------------------------------------------------
/chapter4/1/src/main.js:
--------------------------------------------------------------------------------
1 | // The Vue build version to load with the `import` command
2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
3 | import Vue from 'vue';
4 | import App from './App';
5 | import router from './router';
6 | import store from './store';
7 |
8 | Vue.config.productionTip = false;
9 |
10 | /* eslint-disable no-new */
11 | new Vue({
12 | router,
13 | store,
14 | el: '#app',
15 | template: '',
16 | components: { App },
17 | });
18 |
--------------------------------------------------------------------------------
/chapter4/1/src/router/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import VueRouter from 'vue-router';
3 |
4 | import Index from '@/views/index';
5 |
6 | Vue.use(VueRouter);
7 |
8 | const routes = [
9 | {
10 | path: '/',
11 | component: Index,
12 | },
13 | {
14 | path: '/:id',
15 | component: Index,
16 | },
17 | ];
18 |
19 | export default new VueRouter({
20 | routes,
21 | });
22 |
23 |
--------------------------------------------------------------------------------
/chapter4/1/src/store/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import Vuex from 'vuex';
3 |
4 | Vue.use(Vuex);
5 |
6 | const types = {
7 | UPDATE_MSG: 'UPDATE_MSG',
8 | };
9 |
10 | const mutations = {
11 | [types.UPDATE_MSG](state, payload) {
12 | state.msg = payload.msg;
13 | },
14 | };
15 |
16 | const actions = {
17 | [types.UPDATE_MSG]({ commit }, payload) {
18 | commit(types.UPDATE_MSG, payload);
19 | },
20 | };
21 |
22 | export default new Vuex.Store({
23 | state: {
24 | msg: 'Hello world',
25 | },
26 | mutations,
27 | actions,
28 | });
29 |
--------------------------------------------------------------------------------
/chapter4/1/src/views/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | 挑战到第二页
4 | 返回
5 |
6 |
7 |
{{ username }}
8 |
9 |
16 |
17 |
18 |
57 |
--------------------------------------------------------------------------------
/chapter4/1/static/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/chapter4/1/static/.gitkeep
--------------------------------------------------------------------------------
/chapter4/2/.babelrc:
--------------------------------------------------------------------------------
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-vue-jsx", "transform-runtime"]
12 | }
13 |
--------------------------------------------------------------------------------
/chapter4/2/.editorconfig:
--------------------------------------------------------------------------------
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
10 |
--------------------------------------------------------------------------------
/chapter4/2/.eslintignore:
--------------------------------------------------------------------------------
1 | /build/
2 | /config/
3 | /dist/
4 | /*.js
5 |
--------------------------------------------------------------------------------
/chapter4/2/.eslintrc.js:
--------------------------------------------------------------------------------
1 | // https://eslint.org/docs/user-guide/configuring
2 |
3 | module.exports = {
4 | root: true,
5 | parserOptions: {
6 | parser: 'babel-eslint'
7 | },
8 | env: {
9 | browser: true,
10 | },
11 | // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
12 | // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
13 | extends: ['plugin:vue/essential', 'airbnb-base'],
14 | // required to lint *.vue files
15 | plugins: [
16 | 'vue'
17 | ],
18 | // check if imports actually resolve
19 | settings: {
20 | 'import/resolver': {
21 | webpack: {
22 | config: 'build/webpack.base.conf.js'
23 | }
24 | }
25 | },
26 | // add your custom rules here
27 | rules: {
28 | // don't require .vue extension when importing
29 | 'import/extensions': ['error', 'always', {
30 | js: 'never',
31 | vue: 'never'
32 | }],
33 | // disallow reassignment of function parameters
34 | // disallow parameter object manipulation except for specific exclusions
35 | 'no-param-reassign': ['error', {
36 | props: true,
37 | ignorePropertyModificationsFor: [
38 | 'state', // for vuex state
39 | 'acc', // for reduce accumulators
40 | 'e' // for e.returnvalue
41 | ]
42 | }],
43 | // allow optionalDependencies
44 | 'import/no-extraneous-dependencies': ['error', {
45 | optionalDependencies: ['test/unit/index.js']
46 | }],
47 | // allow debugger during development
48 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
49 | 'no-console': 'off'
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/chapter4/2/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | /dist/
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Editor directories and files
9 | .idea
10 | .vscode
11 | *.suo
12 | *.ntvs*
13 | *.njsproj
14 | *.sln
15 |
--------------------------------------------------------------------------------
/chapter4/2/.postcssrc.js:
--------------------------------------------------------------------------------
1 | // https://github.com/michael-ciniawsky/postcss-load-config
2 |
3 | module.exports = {
4 | "plugins": {
5 | "postcss-import": {},
6 | "postcss-url": {},
7 | // to edit target browsers: use "browserslist" field in package.json
8 | "autoprefixer": {}
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/chapter4/2/README.md:
--------------------------------------------------------------------------------
1 | # vue-router-demo
2 |
3 | > Vue.js Router Demo Project
4 |
5 | ## Build Setup
6 |
7 | ``` bash
8 | # install dependencies
9 | npm install
10 |
11 | # serve with hot reload at localhost:8080
12 | npm run dev
13 |
14 | # build for production with minification
15 | npm run build
16 |
17 | # build for production and view the bundle analyzer report
18 | npm run build --report
19 | ```
20 |
21 | For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
22 |
--------------------------------------------------------------------------------
/chapter4/2/build/build.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | require('./check-versions')()
3 |
4 | process.env.NODE_ENV = 'production'
5 |
6 | const ora = require('ora')
7 | const rm = require('rimraf')
8 | const path = require('path')
9 | const chalk = require('chalk')
10 | const webpack = require('webpack')
11 | const config = require('../config')
12 | const webpackConfig = require('./webpack.prod.conf')
13 |
14 | const spinner = ora('building for production...')
15 | spinner.start()
16 |
17 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
18 | if (err) throw err
19 | webpack(webpackConfig, (err, stats) => {
20 | spinner.stop()
21 | if (err) throw err
22 | process.stdout.write(stats.toString({
23 | colors: true,
24 | modules: false,
25 | children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
26 | chunks: false,
27 | chunkModules: false
28 | }) + '\n\n')
29 |
30 | if (stats.hasErrors()) {
31 | console.log(chalk.red(' Build failed with errors.\n'))
32 | process.exit(1)
33 | }
34 |
35 | console.log(chalk.cyan(' Build complete.\n'))
36 | console.log(chalk.yellow(
37 | ' Tip: built files are meant to be served over an HTTP server.\n' +
38 | ' Opening index.html over file:// won\'t work.\n'
39 | ))
40 | })
41 | })
42 |
--------------------------------------------------------------------------------
/chapter4/2/build/check-versions.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const chalk = require('chalk')
3 | const semver = require('semver')
4 | const packageConfig = require('../package.json')
5 | const shell = require('shelljs')
6 |
7 | function exec (cmd) {
8 | return require('child_process').execSync(cmd).toString().trim()
9 | }
10 |
11 | const versionRequirements = [
12 | {
13 | name: 'node',
14 | currentVersion: semver.clean(process.version),
15 | versionRequirement: packageConfig.engines.node
16 | }
17 | ]
18 |
19 | if (shell.which('npm')) {
20 | versionRequirements.push({
21 | name: 'npm',
22 | currentVersion: exec('npm --version'),
23 | versionRequirement: packageConfig.engines.npm
24 | })
25 | }
26 |
27 | module.exports = function () {
28 | const warnings = []
29 |
30 | for (let i = 0; i < versionRequirements.length; i++) {
31 | const mod = versionRequirements[i]
32 |
33 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
34 | warnings.push(mod.name + ': ' +
35 | chalk.red(mod.currentVersion) + ' should be ' +
36 | chalk.green(mod.versionRequirement)
37 | )
38 | }
39 | }
40 |
41 | if (warnings.length) {
42 | console.log('')
43 | console.log(chalk.yellow('To use this template, you must update following to modules:'))
44 | console.log()
45 |
46 | for (let i = 0; i < warnings.length; i++) {
47 | const warning = warnings[i]
48 | console.log(' ' + warning)
49 | }
50 |
51 | console.log()
52 | process.exit(1)
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/chapter4/2/build/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/chapter4/2/build/logo.png
--------------------------------------------------------------------------------
/chapter4/2/build/vue-loader.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const utils = require('./utils')
3 | const config = require('../config')
4 | const isProduction = process.env.NODE_ENV === 'production'
5 | const sourceMapEnabled = isProduction
6 | ? config.build.productionSourceMap
7 | : config.dev.cssSourceMap
8 |
9 | module.exports = {
10 | loaders: utils.cssLoaders({
11 | sourceMap: sourceMapEnabled,
12 | extract: isProduction
13 | }),
14 | cssSourceMap: sourceMapEnabled,
15 | cacheBusting: config.dev.cacheBusting,
16 | transformToRequire: {
17 | video: ['src', 'poster'],
18 | source: 'src',
19 | img: 'src',
20 | image: 'xlink:href'
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/chapter4/2/build/webpack.base.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const path = require('path')
3 | const utils = require('./utils')
4 | const config = require('../config')
5 | const vueLoaderConfig = require('./vue-loader.conf')
6 |
7 | function resolve (dir) {
8 | return path.join(__dirname, '..', dir)
9 | }
10 |
11 | const createLintingRule = () => ({
12 | test: /\.(js|vue)$/,
13 | loader: 'eslint-loader',
14 | enforce: 'pre',
15 | include: [resolve('src'), resolve('test')],
16 | options: {
17 | formatter: require('eslint-friendly-formatter'),
18 | emitWarning: !config.dev.showEslintErrorsInOverlay
19 | }
20 | })
21 |
22 | module.exports = {
23 | context: path.resolve(__dirname, '../'),
24 | entry: {
25 | app: './src/main.js'
26 | },
27 | output: {
28 | path: config.build.assetsRoot,
29 | filename: '[name].js',
30 | publicPath: process.env.NODE_ENV === 'production'
31 | ? config.build.assetsPublicPath
32 | : config.dev.assetsPublicPath
33 | },
34 | resolve: {
35 | extensions: ['.js', '.vue', '.json'],
36 | alias: {
37 | 'vue$': 'vue/dist/vue.esm.js',
38 | '@': resolve('src'),
39 | }
40 | },
41 | module: {
42 | rules: [
43 | ...(config.dev.useEslint ? [createLintingRule()] : []),
44 | {
45 | test: /\.vue$/,
46 | loader: 'vue-loader',
47 | options: vueLoaderConfig
48 | },
49 | {
50 | test: /\.js$/,
51 | loader: 'babel-loader',
52 | include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
53 | },
54 | {
55 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
56 | loader: 'url-loader',
57 | options: {
58 | limit: 10000,
59 | name: utils.assetsPath('img/[name].[hash:7].[ext]')
60 | }
61 | },
62 | {
63 | test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
64 | loader: 'url-loader',
65 | options: {
66 | limit: 10000,
67 | name: utils.assetsPath('media/[name].[hash:7].[ext]')
68 | }
69 | },
70 | {
71 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
72 | loader: 'url-loader',
73 | options: {
74 | limit: 10000,
75 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
76 | }
77 | }
78 | ]
79 | },
80 | node: {
81 | // prevent webpack from injecting useless setImmediate polyfill because Vue
82 | // source contains it (although only uses it if it's native).
83 | setImmediate: false,
84 | // prevent webpack from injecting mocks to Node native modules
85 | // that does not make sense for the client
86 | dgram: 'empty',
87 | fs: 'empty',
88 | net: 'empty',
89 | tls: 'empty',
90 | child_process: 'empty'
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/chapter4/2/config/dev.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const merge = require('webpack-merge')
3 | const prodEnv = require('./prod.env')
4 |
5 | module.exports = merge(prodEnv, {
6 | NODE_ENV: '"development"'
7 | })
8 |
--------------------------------------------------------------------------------
/chapter4/2/config/index.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | // Template version: 1.3.1
3 | // see http://vuejs-templates.github.io/webpack for documentation.
4 |
5 | const path = require('path')
6 |
7 | module.exports = {
8 | dev: {
9 |
10 | // Paths
11 | assetsSubDirectory: 'static',
12 | assetsPublicPath: '/',
13 | proxyTable: {},
14 |
15 | // Various Dev Server settings
16 | host: 'localhost', // can be overwritten by process.env.HOST
17 | port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
18 | autoOpenBrowser: false,
19 | errorOverlay: true,
20 | notifyOnErrors: true,
21 | poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
22 |
23 | // Use Eslint Loader?
24 | // If true, your code will be linted during bundling and
25 | // linting errors and warnings will be shown in the console.
26 | useEslint: true,
27 | // If true, eslint errors and warnings will also be shown in the error overlay
28 | // in the browser.
29 | showEslintErrorsInOverlay: false,
30 |
31 | /**
32 | * Source Maps
33 | */
34 |
35 | // https://webpack.js.org/configuration/devtool/#development
36 | devtool: 'cheap-module-eval-source-map',
37 |
38 | // If you have problems debugging vue-files in devtools,
39 | // set this to false - it *may* help
40 | // https://vue-loader.vuejs.org/en/options.html#cachebusting
41 | cacheBusting: true,
42 |
43 | cssSourceMap: true
44 | },
45 |
46 | build: {
47 | // Template for index.html
48 | index: path.resolve(__dirname, '../dist/index.html'),
49 |
50 | // Paths
51 | assetsRoot: path.resolve(__dirname, '../dist'),
52 | assetsSubDirectory: 'static',
53 | assetsPublicPath: '/',
54 |
55 | /**
56 | * Source Maps
57 | */
58 |
59 | productionSourceMap: true,
60 | // https://webpack.js.org/configuration/devtool/#production
61 | devtool: '#source-map',
62 |
63 | // Gzip off by default as many popular static hosts such as
64 | // Surge or Netlify already gzip all static assets for you.
65 | // Before setting to `true`, make sure to:
66 | // npm install --save-dev compression-webpack-plugin
67 | productionGzip: false,
68 | productionGzipExtensions: ['js', 'css'],
69 |
70 | // Run the build command with an extra argument to
71 | // View the bundle analyzer report after build finishes:
72 | // `npm run build --report`
73 | // Set to `true` or `false` to always turn it on or off
74 | bundleAnalyzerReport: process.env.npm_config_report
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/chapter4/2/config/prod.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | module.exports = {
3 | NODE_ENV: '"production"'
4 | }
5 |
--------------------------------------------------------------------------------
/chapter4/2/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | vue-state-demo
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/chapter4/2/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-router-demo",
3 | "version": "1.0.0",
4 | "description": "Vue.js Router Demo Project",
5 | "author": "yugasun ",
6 | "private": true,
7 | "scripts": {
8 | "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
9 | "start": "npm run dev",
10 | "lint": "eslint --ext .js,.vue src",
11 | "build": "node build/build.js"
12 | },
13 | "dependencies": {
14 | "vue": "^2.5.16",
15 | "vue-router": "^3.0.1",
16 | "vuex": "^3.0.1"
17 | },
18 | "devDependencies": {
19 | "autoprefixer": "^7.1.2",
20 | "babel-core": "^6.22.1",
21 | "babel-eslint": "^8.2.1",
22 | "babel-helper-vue-jsx-merge-props": "^2.0.3",
23 | "babel-loader": "^7.1.1",
24 | "babel-plugin-syntax-jsx": "^6.18.0",
25 | "babel-plugin-transform-runtime": "^6.22.0",
26 | "babel-plugin-transform-vue-jsx": "^3.5.0",
27 | "babel-preset-env": "^1.3.2",
28 | "babel-preset-stage-2": "^6.22.0",
29 | "chalk": "^2.0.1",
30 | "copy-webpack-plugin": "^4.0.1",
31 | "css-loader": "^0.28.0",
32 | "eslint": "^4.15.0",
33 | "eslint-config-airbnb-base": "^11.3.0",
34 | "eslint-friendly-formatter": "^3.0.0",
35 | "eslint-import-resolver-webpack": "^0.8.3",
36 | "eslint-loader": "^1.7.1",
37 | "eslint-plugin-import": "^2.7.0",
38 | "eslint-plugin-vue": "^4.0.0",
39 | "extract-text-webpack-plugin": "^3.0.0",
40 | "file-loader": "^1.1.4",
41 | "friendly-errors-webpack-plugin": "^1.6.1",
42 | "html-webpack-plugin": "^2.30.1",
43 | "node-notifier": "^5.1.2",
44 | "optimize-css-assets-webpack-plugin": "^3.2.0",
45 | "ora": "^1.2.0",
46 | "portfinder": "^1.0.13",
47 | "postcss-import": "^11.0.0",
48 | "postcss-loader": "^2.0.8",
49 | "postcss-url": "^7.2.1",
50 | "rimraf": "^2.6.0",
51 | "semver": "^5.3.0",
52 | "shelljs": "^0.7.6",
53 | "uglifyjs-webpack-plugin": "^1.1.1",
54 | "url-loader": "^0.5.8",
55 | "vue-loader": "^13.3.0",
56 | "vue-style-loader": "^3.0.1",
57 | "vue-template-compiler": "^2.5.16",
58 | "webpack": "^3.6.0",
59 | "webpack-bundle-analyzer": "^2.9.0",
60 | "webpack-dev-server": "^2.9.1",
61 | "webpack-merge": "^4.1.0"
62 | },
63 | "engines": {
64 | "node": ">= 6.0.0",
65 | "npm": ">= 3.0.0"
66 | },
67 | "browserslist": [
68 | "> 1%",
69 | "last 2 versions",
70 | "not ie <= 8"
71 | ]
72 | }
73 |
--------------------------------------------------------------------------------
/chapter4/2/src/App.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
11 |
--------------------------------------------------------------------------------
/chapter4/2/src/components/comp1.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Component 1
4 |
5 |
6 |
7 |
8 |
47 |
48 |
--------------------------------------------------------------------------------
/chapter4/2/src/components/comp2.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Component 2
4 |
5 |
6 |
7 |
29 |
30 |
--------------------------------------------------------------------------------
/chapter4/2/src/components/comp3.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
12 |
17 |
18 |
--------------------------------------------------------------------------------
/chapter4/2/src/main.js:
--------------------------------------------------------------------------------
1 | // The Vue build version to load with the `import` command
2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
3 | import Vue from 'vue';
4 | import App from './App';
5 | import router from './router';
6 | import store from './store';
7 |
8 | Vue.config.productionTip = false;
9 |
10 | Vue.mixin({
11 | created() {
12 | console.log(`Component ${this.$options.name} created from 全局打点`);
13 | },
14 | mounted() {
15 | console.log(`Component ${this.$options.name} mounted from 全局打点`);
16 | },
17 | });
18 |
19 | /* eslint-disable no-new */
20 | new Vue({
21 | router,
22 | store,
23 | el: '#app',
24 | template: '',
25 | components: { App },
26 | });
27 |
--------------------------------------------------------------------------------
/chapter4/2/src/mixins/func.js:
--------------------------------------------------------------------------------
1 | export default {
2 | mounted() {
3 | this.sayHello();
4 | },
5 | methods: {
6 | sayHello() {
7 | console.log('产品妹子,你好美!');
8 | },
9 | },
10 | };
11 |
--------------------------------------------------------------------------------
/chapter4/2/src/mixins/log.js:
--------------------------------------------------------------------------------
1 | export default {
2 | created() {
3 | console.log(`Component ${this.$options.name} created.`);
4 | },
5 | mounted() {
6 | console.log(`Component ${this.$options.name} mounted.`);
7 | },
8 | };
9 |
--------------------------------------------------------------------------------
/chapter4/2/src/router/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import VueRouter from 'vue-router';
3 |
4 | import Index from '@/views/index';
5 |
6 | Vue.use(VueRouter);
7 |
8 | const routes = [
9 | {
10 | path: '/',
11 | component: Index,
12 | },
13 | {
14 | path: '/:id',
15 | component: Index,
16 | },
17 | ];
18 |
19 | export default new VueRouter({
20 | routes,
21 | });
22 |
23 |
--------------------------------------------------------------------------------
/chapter4/2/src/store/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import Vuex from 'vuex';
3 |
4 | Vue.use(Vuex);
5 |
6 | const types = {
7 | UPDATE_MSG: 'UPDATE_MSG',
8 | };
9 |
10 | const mutations = {
11 | [types.UPDATE_MSG](state, payload) {
12 | state.msg = payload.msg;
13 | },
14 | };
15 |
16 | const actions = {
17 | [types.UPDATE_MSG]({ commit }, payload) {
18 | commit(types.UPDATE_MSG, payload);
19 | },
20 | };
21 |
22 | export default new Vuex.Store({
23 | state: {
24 | msg: 'Hello world',
25 | },
26 | mutations,
27 | actions,
28 | });
29 |
--------------------------------------------------------------------------------
/chapter4/2/src/views/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | 跳转到第二页
4 | 返回
5 |
6 |
7 |
{{ username }}
8 |
9 |
16 |
17 |
18 |
57 |
--------------------------------------------------------------------------------
/chapter4/2/static/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/chapter4/2/static/.gitkeep
--------------------------------------------------------------------------------
/chapter4/3/.babelrc:
--------------------------------------------------------------------------------
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-vue-jsx", "transform-runtime"]
12 | }
13 |
--------------------------------------------------------------------------------
/chapter4/3/.editorconfig:
--------------------------------------------------------------------------------
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
10 |
--------------------------------------------------------------------------------
/chapter4/3/.eslintignore:
--------------------------------------------------------------------------------
1 | /build/
2 | /config/
3 | /dist/
4 | /*.js
5 |
--------------------------------------------------------------------------------
/chapter4/3/.eslintrc.js:
--------------------------------------------------------------------------------
1 | // https://eslint.org/docs/user-guide/configuring
2 |
3 | module.exports = {
4 | root: true,
5 | parserOptions: {
6 | parser: 'babel-eslint'
7 | },
8 | env: {
9 | browser: true,
10 | },
11 | // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
12 | // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
13 | extends: ['plugin:vue/essential', 'airbnb-base'],
14 | // required to lint *.vue files
15 | plugins: [
16 | 'vue'
17 | ],
18 | // check if imports actually resolve
19 | settings: {
20 | 'import/resolver': {
21 | webpack: {
22 | config: 'build/webpack.base.conf.js'
23 | }
24 | }
25 | },
26 | // add your custom rules here
27 | rules: {
28 | // don't require .vue extension when importing
29 | 'import/extensions': ['error', 'always', {
30 | js: 'never',
31 | vue: 'never'
32 | }],
33 | // disallow reassignment of function parameters
34 | // disallow parameter object manipulation except for specific exclusions
35 | 'no-param-reassign': ['error', {
36 | props: true,
37 | ignorePropertyModificationsFor: [
38 | 'state', // for vuex state
39 | 'acc', // for reduce accumulators
40 | 'e' // for e.returnvalue
41 | ]
42 | }],
43 | // allow optionalDependencies
44 | 'import/no-extraneous-dependencies': ['error', {
45 | optionalDependencies: ['test/unit/index.js']
46 | }],
47 | // allow debugger during development
48 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/chapter4/3/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | /dist/
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Editor directories and files
9 | .idea
10 | .vscode
11 | *.suo
12 | *.ntvs*
13 | *.njsproj
14 | *.sln
15 |
--------------------------------------------------------------------------------
/chapter4/3/.postcssrc.js:
--------------------------------------------------------------------------------
1 | // https://github.com/michael-ciniawsky/postcss-load-config
2 |
3 | module.exports = {
4 | "plugins": {
5 | "postcss-import": {},
6 | "postcss-url": {},
7 | // to edit target browsers: use "browserslist" field in package.json
8 | "autoprefixer": {}
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/chapter4/3/README.md:
--------------------------------------------------------------------------------
1 | # vue-router-demo
2 |
3 | > Vue.js Router Demo Project
4 |
5 | ## Build Setup
6 |
7 | ``` bash
8 | # install dependencies
9 | npm install
10 |
11 | # serve with hot reload at localhost:8080
12 | npm run dev
13 |
14 | # build for production with minification
15 | npm run build
16 |
17 | # build for production and view the bundle analyzer report
18 | npm run build --report
19 | ```
20 |
21 | For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
22 |
--------------------------------------------------------------------------------
/chapter4/3/build/build.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | require('./check-versions')()
3 |
4 | process.env.NODE_ENV = 'production'
5 |
6 | const ora = require('ora')
7 | const rm = require('rimraf')
8 | const path = require('path')
9 | const chalk = require('chalk')
10 | const webpack = require('webpack')
11 | const config = require('../config')
12 | const webpackConfig = require('./webpack.prod.conf')
13 |
14 | const spinner = ora('building for production...')
15 | spinner.start()
16 |
17 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
18 | if (err) throw err
19 | webpack(webpackConfig, (err, stats) => {
20 | spinner.stop()
21 | if (err) throw err
22 | process.stdout.write(stats.toString({
23 | colors: true,
24 | modules: false,
25 | children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
26 | chunks: false,
27 | chunkModules: false
28 | }) + '\n\n')
29 |
30 | if (stats.hasErrors()) {
31 | console.log(chalk.red(' Build failed with errors.\n'))
32 | process.exit(1)
33 | }
34 |
35 | console.log(chalk.cyan(' Build complete.\n'))
36 | console.log(chalk.yellow(
37 | ' Tip: built files are meant to be served over an HTTP server.\n' +
38 | ' Opening index.html over file:// won\'t work.\n'
39 | ))
40 | })
41 | })
42 |
--------------------------------------------------------------------------------
/chapter4/3/build/check-versions.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const chalk = require('chalk')
3 | const semver = require('semver')
4 | const packageConfig = require('../package.json')
5 | const shell = require('shelljs')
6 |
7 | function exec (cmd) {
8 | return require('child_process').execSync(cmd).toString().trim()
9 | }
10 |
11 | const versionRequirements = [
12 | {
13 | name: 'node',
14 | currentVersion: semver.clean(process.version),
15 | versionRequirement: packageConfig.engines.node
16 | }
17 | ]
18 |
19 | if (shell.which('npm')) {
20 | versionRequirements.push({
21 | name: 'npm',
22 | currentVersion: exec('npm --version'),
23 | versionRequirement: packageConfig.engines.npm
24 | })
25 | }
26 |
27 | module.exports = function () {
28 | const warnings = []
29 |
30 | for (let i = 0; i < versionRequirements.length; i++) {
31 | const mod = versionRequirements[i]
32 |
33 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
34 | warnings.push(mod.name + ': ' +
35 | chalk.red(mod.currentVersion) + ' should be ' +
36 | chalk.green(mod.versionRequirement)
37 | )
38 | }
39 | }
40 |
41 | if (warnings.length) {
42 | console.log('')
43 | console.log(chalk.yellow('To use this template, you must update following to modules:'))
44 | console.log()
45 |
46 | for (let i = 0; i < warnings.length; i++) {
47 | const warning = warnings[i]
48 | console.log(' ' + warning)
49 | }
50 |
51 | console.log()
52 | process.exit(1)
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/chapter4/3/build/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/chapter4/3/build/logo.png
--------------------------------------------------------------------------------
/chapter4/3/build/vue-loader.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const utils = require('./utils')
3 | const config = require('../config')
4 | const isProduction = process.env.NODE_ENV === 'production'
5 | const sourceMapEnabled = isProduction
6 | ? config.build.productionSourceMap
7 | : config.dev.cssSourceMap
8 |
9 | module.exports = {
10 | loaders: utils.cssLoaders({
11 | sourceMap: sourceMapEnabled,
12 | extract: isProduction
13 | }),
14 | cssSourceMap: sourceMapEnabled,
15 | cacheBusting: config.dev.cacheBusting,
16 | transformToRequire: {
17 | video: ['src', 'poster'],
18 | source: 'src',
19 | img: 'src',
20 | image: 'xlink:href'
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/chapter4/3/build/webpack.base.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const path = require('path')
3 | const utils = require('./utils')
4 | const config = require('../config')
5 | const vueLoaderConfig = require('./vue-loader.conf')
6 |
7 | function resolve (dir) {
8 | return path.join(__dirname, '..', dir)
9 | }
10 |
11 | const createLintingRule = () => ({
12 | test: /\.(js|vue)$/,
13 | loader: 'eslint-loader',
14 | enforce: 'pre',
15 | include: [resolve('src'), resolve('test')],
16 | options: {
17 | formatter: require('eslint-friendly-formatter'),
18 | emitWarning: !config.dev.showEslintErrorsInOverlay
19 | }
20 | })
21 |
22 | module.exports = {
23 | context: path.resolve(__dirname, '../'),
24 | entry: {
25 | app: './src/main.js'
26 | },
27 | output: {
28 | path: config.build.assetsRoot,
29 | filename: '[name].js',
30 | publicPath: process.env.NODE_ENV === 'production'
31 | ? config.build.assetsPublicPath
32 | : config.dev.assetsPublicPath
33 | },
34 | resolve: {
35 | extensions: ['.js', '.vue', '.json'],
36 | alias: {
37 | 'vue$': 'vue/dist/vue.esm.js',
38 | '@': resolve('src'),
39 | }
40 | },
41 | module: {
42 | rules: [
43 | ...(config.dev.useEslint ? [createLintingRule()] : []),
44 | {
45 | test: /\.vue$/,
46 | loader: 'vue-loader',
47 | options: vueLoaderConfig
48 | },
49 | {
50 | test: /\.js$/,
51 | loader: 'babel-loader',
52 | include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
53 | },
54 | {
55 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
56 | loader: 'url-loader',
57 | options: {
58 | limit: 10000,
59 | name: utils.assetsPath('img/[name].[hash:7].[ext]')
60 | }
61 | },
62 | {
63 | test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
64 | loader: 'url-loader',
65 | options: {
66 | limit: 10000,
67 | name: utils.assetsPath('media/[name].[hash:7].[ext]')
68 | }
69 | },
70 | {
71 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
72 | loader: 'url-loader',
73 | options: {
74 | limit: 10000,
75 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
76 | }
77 | }
78 | ]
79 | },
80 | node: {
81 | // prevent webpack from injecting useless setImmediate polyfill because Vue
82 | // source contains it (although only uses it if it's native).
83 | setImmediate: false,
84 | // prevent webpack from injecting mocks to Node native modules
85 | // that does not make sense for the client
86 | dgram: 'empty',
87 | fs: 'empty',
88 | net: 'empty',
89 | tls: 'empty',
90 | child_process: 'empty'
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/chapter4/3/config/dev.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const merge = require('webpack-merge')
3 | const prodEnv = require('./prod.env')
4 |
5 | module.exports = merge(prodEnv, {
6 | NODE_ENV: '"development"'
7 | })
8 |
--------------------------------------------------------------------------------
/chapter4/3/config/index.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | // Template version: 1.3.1
3 | // see http://vuejs-templates.github.io/webpack for documentation.
4 |
5 | const path = require('path')
6 |
7 | module.exports = {
8 | dev: {
9 |
10 | // Paths
11 | assetsSubDirectory: 'static',
12 | assetsPublicPath: '/',
13 | proxyTable: {},
14 |
15 | // Various Dev Server settings
16 | host: 'localhost', // can be overwritten by process.env.HOST
17 | port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
18 | autoOpenBrowser: false,
19 | errorOverlay: true,
20 | notifyOnErrors: true,
21 | poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
22 |
23 | // Use Eslint Loader?
24 | // If true, your code will be linted during bundling and
25 | // linting errors and warnings will be shown in the console.
26 | useEslint: true,
27 | // If true, eslint errors and warnings will also be shown in the error overlay
28 | // in the browser.
29 | showEslintErrorsInOverlay: false,
30 |
31 | /**
32 | * Source Maps
33 | */
34 |
35 | // https://webpack.js.org/configuration/devtool/#development
36 | devtool: 'cheap-module-eval-source-map',
37 |
38 | // If you have problems debugging vue-files in devtools,
39 | // set this to false - it *may* help
40 | // https://vue-loader.vuejs.org/en/options.html#cachebusting
41 | cacheBusting: true,
42 |
43 | cssSourceMap: true
44 | },
45 |
46 | build: {
47 | // Template for index.html
48 | index: path.resolve(__dirname, '../dist/index.html'),
49 |
50 | // Paths
51 | assetsRoot: path.resolve(__dirname, '../dist'),
52 | assetsSubDirectory: 'static',
53 | assetsPublicPath: '/',
54 |
55 | /**
56 | * Source Maps
57 | */
58 |
59 | productionSourceMap: true,
60 | // https://webpack.js.org/configuration/devtool/#production
61 | devtool: '#source-map',
62 |
63 | // Gzip off by default as many popular static hosts such as
64 | // Surge or Netlify already gzip all static assets for you.
65 | // Before setting to `true`, make sure to:
66 | // npm install --save-dev compression-webpack-plugin
67 | productionGzip: false,
68 | productionGzipExtensions: ['js', 'css'],
69 |
70 | // Run the build command with an extra argument to
71 | // View the bundle analyzer report after build finishes:
72 | // `npm run build --report`
73 | // Set to `true` or `false` to always turn it on or off
74 | bundleAnalyzerReport: process.env.npm_config_report
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/chapter4/3/config/prod.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | module.exports = {
3 | NODE_ENV: '"production"'
4 | }
5 |
--------------------------------------------------------------------------------
/chapter4/3/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | vue-state-demo
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/chapter4/3/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-router-demo",
3 | "version": "1.0.0",
4 | "description": "Vue.js Router Demo Project",
5 | "author": "yugasun ",
6 | "private": true,
7 | "scripts": {
8 | "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
9 | "start": "npm run dev",
10 | "lint": "eslint --ext .js,.vue src",
11 | "build": "node build/build.js"
12 | },
13 | "dependencies": {
14 | "vue": "^2.5.16",
15 | "vue-i18n": "^8.8.2",
16 | "vue-router": "^3.0.1"
17 | },
18 | "devDependencies": {
19 | "autoprefixer": "^7.1.2",
20 | "babel-core": "^6.22.1",
21 | "babel-eslint": "^8.2.1",
22 | "babel-helper-vue-jsx-merge-props": "^2.0.3",
23 | "babel-loader": "^7.1.1",
24 | "babel-plugin-syntax-jsx": "^6.18.0",
25 | "babel-plugin-transform-runtime": "^6.22.0",
26 | "babel-plugin-transform-vue-jsx": "^3.5.0",
27 | "babel-preset-env": "^1.3.2",
28 | "babel-preset-stage-2": "^6.22.0",
29 | "chalk": "^2.0.1",
30 | "copy-webpack-plugin": "^4.0.1",
31 | "css-loader": "^0.28.0",
32 | "eslint": "^4.15.0",
33 | "eslint-config-airbnb-base": "^11.3.0",
34 | "eslint-friendly-formatter": "^3.0.0",
35 | "eslint-import-resolver-webpack": "^0.8.3",
36 | "eslint-loader": "^1.7.1",
37 | "eslint-plugin-import": "^2.7.0",
38 | "eslint-plugin-vue": "^4.0.0",
39 | "extract-text-webpack-plugin": "^3.0.0",
40 | "file-loader": "^1.1.4",
41 | "friendly-errors-webpack-plugin": "^1.6.1",
42 | "html-webpack-plugin": "^2.30.1",
43 | "node-notifier": "^5.1.2",
44 | "optimize-css-assets-webpack-plugin": "^3.2.0",
45 | "ora": "^1.2.0",
46 | "portfinder": "^1.0.13",
47 | "postcss-import": "^11.0.0",
48 | "postcss-loader": "^2.0.8",
49 | "postcss-url": "^7.2.1",
50 | "rimraf": "^2.6.0",
51 | "semver": "^5.3.0",
52 | "shelljs": "^0.7.6",
53 | "uglifyjs-webpack-plugin": "^1.1.1",
54 | "url-loader": "^0.5.8",
55 | "vue-loader": "^13.3.0",
56 | "vue-style-loader": "^3.0.1",
57 | "vue-template-compiler": "^2.5.16",
58 | "webpack": "^3.6.0",
59 | "webpack-bundle-analyzer": "^2.9.0",
60 | "webpack-dev-server": "^2.9.1",
61 | "webpack-merge": "^4.1.0"
62 | },
63 | "engines": {
64 | "node": ">= 6.0.0",
65 | "npm": ">= 3.0.0"
66 | },
67 | "browserslist": [
68 | "> 1%",
69 | "last 2 versions",
70 | "not ie <= 8"
71 | ]
72 | }
73 |
--------------------------------------------------------------------------------
/chapter4/3/src/App.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
13 |
14 |
15 |
32 |
--------------------------------------------------------------------------------
/chapter4/3/src/lang/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import VueI18n from 'vue-i18n';
3 |
4 | import indexMsg from './modules/index';
5 | import loginMsg from './modules/login';
6 | import orderMsg from './modules/order';
7 |
8 | Vue.use(VueI18n);
9 |
10 | const messages = {
11 | zh: {
12 | ...indexMsg.zh,
13 | ...loginMsg.zh,
14 | ...orderMsg.zh,
15 | },
16 | en: {
17 | ...indexMsg.en,
18 | ...loginMsg.en,
19 | ...orderMsg.en,
20 | },
21 | };
22 |
23 | const i18n = new VueI18n({
24 | locale: 'zh',
25 | messages,
26 | });
27 |
28 | export default i18n;
29 |
--------------------------------------------------------------------------------
/chapter4/3/src/lang/modules/index.js:
--------------------------------------------------------------------------------
1 | const zh = {
2 | index: {
3 | header: {
4 | title: 'Vue-I18n 示例',
5 | subtitle: '你将学会如何使用 vue-i18n',
6 | },
7 | },
8 | };
9 |
10 | const en = {
11 | index: {
12 | header: {
13 | title: 'Vue-I18n Demo',
14 | subtitle: 'You will learn how to use vue-i18n',
15 | },
16 | },
17 | };
18 |
19 | export default {
20 | zh,
21 | en,
22 | };
23 |
--------------------------------------------------------------------------------
/chapter4/3/src/lang/modules/login.js:
--------------------------------------------------------------------------------
1 | const zh = {
2 | login: {
3 | tips: '请{minute}分{second}秒后再重试 | 请{hour}小时后再重试',
4 | },
5 | };
6 |
7 | const en = {
8 | login: {
9 | tips: 'Please try after {minute} minutes {second} seconds | Please try after {hour} hours',
10 | },
11 | };
12 |
13 | export default {
14 | zh,
15 | en,
16 | };
17 |
--------------------------------------------------------------------------------
/chapter4/3/src/lang/modules/order.js:
--------------------------------------------------------------------------------
1 | const zh = {
2 | order: {
3 | status: [
4 | '待付款',
5 | '待发货',
6 | '已发货',
7 | '已签收',
8 | '已取消',
9 | ],
10 | },
11 | };
12 |
13 | const en = {
14 | order: {
15 | status: [
16 | 'Pending',
17 | 'To be delivered',
18 | 'Shipped',
19 | 'Received',
20 | 'Canceled',
21 | ],
22 | },
23 | };
24 |
25 | export default {
26 | zh,
27 | en,
28 | };
29 |
--------------------------------------------------------------------------------
/chapter4/3/src/main.js:
--------------------------------------------------------------------------------
1 | // The Vue build version to load with the `import` command
2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
3 | import Vue from 'vue';
4 | import App from './App';
5 | import router from './router';
6 | import i18n from './lang';
7 |
8 | Vue.config.productionTip = false;
9 |
10 | /* eslint-disable no-new */
11 | new Vue({
12 | i18n,
13 | router,
14 | el: '#app',
15 | template: '',
16 | components: { App },
17 | });
18 |
--------------------------------------------------------------------------------
/chapter4/3/src/router/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import VueRouter from 'vue-router';
3 |
4 | import Index from '@/views/index';
5 |
6 | Vue.use(VueRouter);
7 |
8 | const routes = [
9 | {
10 | path: '/',
11 | component: Index,
12 | },
13 | {
14 | path: '/:id',
15 | component: Index,
16 | },
17 | ];
18 |
19 | export default new VueRouter({
20 | routes,
21 | });
22 |
23 |
--------------------------------------------------------------------------------
/chapter4/3/src/views/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{ indexMsg.title }}
5 | {{ indexMsg.subtitle }}
6 |
7 |
8 | {{ $tc('login.tips', 1, {minute: 30, second: 29}) }}
9 | {{ $tc('login.tips', 2, {hour: 1}) }}
10 |
11 |
12 |
13 | - {{ $t(`order.status[${orderStatus}]`) }}
14 |
15 |
16 |
17 |
18 |
19 |
34 |
--------------------------------------------------------------------------------
/chapter4/3/static/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/chapter4/3/static/.gitkeep
--------------------------------------------------------------------------------
/docs/.vuepress/components/AboutLayout.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |

6 |
作者
7 |
8 |
9 |
微信号:yugasun
10 |
英文名:Yuga Sun
11 |
职业:前端开发
12 |
13 | Github
14 | Blog
15 |
16 |
17 |
18 |
19 |
20 |
56 |
--------------------------------------------------------------------------------
/docs/.vuepress/config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | base: '/You-May-Not-Know-Vuejs/',
3 | title: '你也许不知道的 Vuejs',
4 | ga: 'UA-85991013-5',
5 | description: 'Vue 从入门到精通系列',
6 | head: [
7 | ['link', { rel: 'icon', href: '/logo.png' }],
8 | ['script', { async: 'async', type: 'text/javascript'}, 'var _hmt=_hmt||[];!function(){var e=document.createElement("script");e.src="https://hm.baidu.com/hm.js?22a0ab0b25c4b63f25e294e1585f3aa5";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)}();']
9 | ],
10 | markdown: {
11 | toc: {
12 | includeLevel: [2, 3, 4, 5, 6]
13 | }
14 | },
15 | themeConfig: {
16 | repo: 'yugasun/You-May-Not-Know-Vuejs',
17 | docsDir: 'docs',
18 | editLinks: true,
19 | editLinkText: '错别字纠正',
20 | sidebarDepth: 3,
21 | nav: [
22 | {
23 | text: '正文',
24 | link: '/art/',
25 | },
26 | {
27 | text: '人之初',
28 | link: '/donate/'
29 | },
30 | {
31 | text: '关于',
32 | link: '/about/'
33 | }
34 | ],
35 | sidebar: {
36 | '/art/': [
37 | '',
38 | 'you-may-not-know-vuejs-1',
39 | 'you-may-not-know-vuejs-2',
40 | 'you-may-not-know-vuejs-3',
41 | 'you-may-not-know-vuejs-4',
42 | 'you-may-not-know-vuejs-5',
43 | 'you-may-not-know-vuejs-6',
44 | 'you-may-not-know-vuejs-7',
45 | 'you-may-not-know-vuejs-8',
46 | 'you-may-not-know-vuejs-9',
47 | 'you-may-not-know-vuejs-10',
48 | 'you-may-not-know-vuejs-11',
49 | 'you-may-not-know-vuejs-12',
50 | 'you-may-not-know-vuejs-13',
51 | 'you-may-not-know-vuejs-14',
52 | 'you-may-not-know-vuejs-15',
53 | ],
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/docs/.vuepress/override.styl:
--------------------------------------------------------------------------------
1 | .content
2 | pre
3 | .highlighted-line
4 | background-color #0968F7
--------------------------------------------------------------------------------
/docs/.vuepress/public/alipay.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/docs/.vuepress/public/alipay.jpg
--------------------------------------------------------------------------------
/docs/.vuepress/public/logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/docs/.vuepress/public/logo.jpg
--------------------------------------------------------------------------------
/docs/.vuepress/public/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/docs/.vuepress/public/logo.png
--------------------------------------------------------------------------------
/docs/.vuepress/public/wechat.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/docs/.vuepress/public/wechat.jpg
--------------------------------------------------------------------------------
/docs/.vuepress/public/you-may-not-know-vuejs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yugasun/You-May-Not-Know-Vuejs/a90d44f3e53be74edf8741f8e4f09f48934e7f6c/docs/.vuepress/public/you-may-not-know-vuejs.png
--------------------------------------------------------------------------------
/docs/.vuepress/theme/Layout.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
14 |
--------------------------------------------------------------------------------
/docs/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | home: true
3 | heroImage: /logo.png
4 | actionText: 开始阅读
5 | actionLink: /art/
6 | features:
7 | - title: 通俗易懂
8 | details: 无论你是刚入门的前端,还是想了解Vue的后端,阅读起来毫不费力。
9 | - title: 循序渐进
10 | details:
11 | 从Vue的最基本的使用,到工程化的开发,再到最佳实践,一步一步循序渐进。
12 | - title: 诙谐幽默
13 | details:
14 | 文章会结合一些现实诙谐幽默的案例来带领你理解各种案例,加深理解。
15 | footer: Copyright © 2018-present yugasun
16 | ---
17 |
--------------------------------------------------------------------------------
/docs/about/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: AboutLayout
3 | ---
--------------------------------------------------------------------------------
/docs/art/README.md:
--------------------------------------------------------------------------------
1 | # 前言
2 |
3 | 《你可能不知道的Vuejs》系列文章是本人在过去时间里,从完全不知道 Vuejs 到熟练地使用 Vuejs 开发各种复杂的大型项目,从不同项目开发实践中总结的一些经验和技巧类文章。重点带你一步步熟悉如何使用Vuejs来开发基本的项目,包括周边生态中,一些较热门工具的使用和技巧,同时也会分享当面对较复杂功能需求时候,如何去分析和处理的过程。
4 |
5 | ## 我为什么要写这个系列
6 |
7 | 虽然网上各种有关Vuejs实践的文章和书籍琳琅满目,[Vuejs官网教程](https://cn.vuejs.org/v2/guide/) (Vuejs官方教程是我见过的最好的文档了,没有之一,建议大家在使用Vuejs之前,还是先去通读一遍。) 也非常详细,但是还是偶尔有很多朋友问我一些Vuejs相关的问题,我感到很奇怪,有那么多的文章来知道如何使用,为什么还是会有这样那样的问题呢?仔细想想也不意外了,发现他们有些人,一开始就直接使用官方 [webpack模板](https://github.com/vuejs-templates/webpack)来开发项目,[webpack](https://github.com/webpack/webpack) 都还没熟悉呢,遇到问题,就直直接蒙了,不知道从何下手,当然搜索引擎几乎可以帮你解决一切问题,但还是会花费你很多时间去弥补你对未知知识的缺失。
8 |
9 | 所以我还是决定写这个系列文章,本人不是大神,只是希望通过写这个系列文章,能够帮助到刚入门Vuejs的朋友,同时也对自己的知识进行梳理和总结。
10 |
11 | ## 序言
12 |
13 | 本系列文章将从像使用 `jquery` 那样使用 `Vuejs` 开始,然后通过循序渐进的学习,之后再慢慢引入 `webpack`,当然文章中也会顺带讲解一些ES6语法。最后会拿出一个项目实例来剖析和讲解一些使用技巧。
14 |
15 | 内容包括什么?
16 |
17 | 1. Vuejs的基本特性介绍及用法
18 | 2. Vuejs的高级用法
19 | 3. Vuejs结合webpack进行开发
20 | 4. 使用ES6语法快乐的玩耍Vuejs
21 | 5. Vuejs最佳实践
22 | 6. Vuejs项目实战
23 |
24 | 因为本文是开篇,所以在写作过程中,有可能内容会有所变动,也会根据读者的反馈和指正进行相应修改,但是大体内容还是按照上面的思路进行的。
25 |
26 | 本系列所有文章相关源码都github上找到:[You May Not Know Vuejs](https://github.com/yugasun/You-May-Not-Know-Vuejs)
27 |
28 | ## 最后
29 |
30 | 因为个人经验有限,文章难免会有所纰漏,欢迎大侠批评指正。
31 |
32 | ## 在线阅读
33 |
34 | * [专题站](https://yugasun.github.io/You-May-Not-Know-Vuejs/)
35 | * [掘金专栏](https://juejin.im/user/583b9227ac502e006c25d1a7/posts)
36 |
--------------------------------------------------------------------------------
/docs/donate/README.md:
--------------------------------------------------------------------------------
1 | # 人之初
2 |
3 | ## 需要你的帮助
4 |
5 | * 如果你在阅读过程中发现错别字,可以直接点击文章最下边的 **错别字纠正** 链接,帮助修改错别字。
6 | * 如果你在阅读过程中发现任何问题,请到Github仓库:[you-may-not-know-vuejs](https://github.com/yugasun/you-may-not-know-vuejs) 提交 `issue`。
7 |
8 | ## 捐赠
9 |
10 | 如果你真的能从这套文章中感受到我们的诚意且真正学到知识,并且你愿意再慷慨一点的话,那真是太好了,这将成为我们更新文章的动力,说实话写高质量的文章很费精力。可以选择:
11 |
12 | * `A`:微信
13 |
14 |
15 |
16 | * `B`:支付宝
17 |
18 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "you-may-not-know-vuejs",
3 | "description": "",
4 | "version": "1.0.0",
5 | "main": "index.js",
6 | "directories": {
7 | "doc": "docs"
8 | },
9 | "scripts": {
10 | "dev": "vuepress dev ./docs",
11 | "build": "vuepress build ./docs",
12 | "deploy": "npm run build && node ./build/deploy.js"
13 | },
14 | "repository": {
15 | "type": "git",
16 | "url": "git+https://github.com/yugasun/You-May-Not-Know-Vuejs.git"
17 | },
18 | "keywords": [
19 | "vue",
20 | "practice",
21 | "tutorial"
22 | ],
23 | "author": "yugasun",
24 | "license": "MIT",
25 | "bugs": {
26 | "url": "https://github.com/yugasun/You-May-Not-Know-Vuejs/issues"
27 | },
28 | "homepage": "https://github.com/yugasun/You-May-Not-Know-Vuejs#readme",
29 | "devDependencies": {
30 | "gh-pages": "^3.1.0",
31 | "vuepress": "^0.8.4"
32 | }
33 | }
34 |
--------------------------------------------------------------------------------