Skip to content

Commit 13c5718

Browse files
June 2018 (#146)
* Update unit-testing-vue-components.md (vuejs#1623) * Fixed a typo (vuejs#1625) Removed an extra 's' to fix a grammatical mistake * fix a typo (vuejs#1627) * Update v-for list example (vuejs#1628) * Add presentation role to style-only li item * fix: code snippet language (close vuejs#1617) (vuejs#1626) * Update todo-list-example for a11y (vuejs#1630) * Update todo-list-example for a11y * Implement review suggestions * Use explicit label instead of aria-label * Move v-model directive to top for improved readability * change NODE_ENV to follow recommendations from webpack (vuejs#1622) * change NODE_ENV to follow recommendations from weback * Update deployment.md * note that modes are not available in transition groups, fixes vuejs#1619 * add examples for in API doc * add comparison note about react-like libraries * Update components.md (vuejs#1632) * Update components.md * Update components.md * improve flow of single root component section * cookbook entry for storage (vuejs#1550) * cookbook entry for storage * minor tweak * updates to article * updates to article * maybe the last tweak * the honest to god really last mod * Update index.md (vuejs#1634) * docs(guide/comparison): correct size stat of Angular CLI project (vuejs#1638) * Update client-side-storage.md (vuejs#1640) * Update creating-custom-scroll-directives.md (vuejs#1639) * chore: update ad code * remove unnecessary word 'know' (vuejs#1641) * Updated broken links for the Vue Test Utils documentation. (vuejs#1643) * Reorganize component props to introduce prop types earlier, fixes vuejs#1644 (vuejs#1646) @BlitZz96 brought up a good point in [this issue](vuejs#1644) about users lacking the necessary background knowledge to fully understand Passing Static and Dynamic Props, at least as it relates to booleans and potentially other types in the future. To fix this, I added a new Prop Types section right before it. * First stab at SFC to npm documentation (vuejs#1558) * First stab at SFC to npm documentation * Clean up sample code, clarify .vue usage with SSR builds * Run build tasks in parallel, fix dependency order * Backtick all instances of .vue, minor edits for clarity * Fix typo on link * Update url to vue-sfc-rollup utility in acknowledgements * Fix order, other edits suggested by @sdras * Additional explanation about sfc-to-npm recipe package.json * Rename packaing-sfc-for-npm.md to packaging-sfc-for-npm.md (vuejs#1652) * Update link in comparison guide (vuejs#1653) The phrase "These state management patterns and even Redux itself can be easily integrated into Vue applications" has a link to a deprecated project. Instead I link to a yarnpkg.com search I saw used in https://vuejs.org/v2/guide/state-management.html, which links all "redux vue" projects (so it's always up to date) * chore: update vue version * Fix link to docs on custom inputs (vuejs#1660) The old link redirected me to https://vuejs.org/v2/guide/components-custom-events.html#Binding-Native-Events-to-Components which was unexpected. I think the correct link is https://vuejs.org/v2/guide/components.html#Using-v-model-on-Components as per this change. * correct wrong link (vuejs#1661) * Update events.md correct wrong link * Update events.md correct wrong link * Feature/vuemeetups (vuejs#1665) * feature: Add link to VueMeetups * feature: Add section on becoming a community leader * minor tweaks to meetup section * Added details about Lifecycle Hooks (vuejs#1664) * Added details about Lifecycle Hooks Mostly a clarification for beginners without prior knowledge about what Lifecycle hooks are. Makes it easier to understand when perhaps only knowing that the developer has a `mounted()` hook. I left out the function syntax because of generality. Add if it makes more sense to add. I am not fully knowledgable in Vue yet. * add (de)activated to lifecycle hooks list in style guide * improve comparisons react scaling down section * add text versions of image code examples * remove extra comma in components * TypeScript project generation in @vue/cli 3.0 (vuejs#1668) * TypeScript project generation in @vue/cli 3.0 update information about generating TypeScript project using new @vue/cli 3.0 * tweaks to Vue CLI 3 TypeScript support docs * chore: update sponsors * Sylvain and Forresst feedbacks Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * chore: update sponsors * update CLI docs link * add Scrimba links for preview * @ForrestT and @raisonblue feedback Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * Feedback of @rspt Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * Fix example indentation in the Unit Testing Vue Components recipe (vuejs#1683) * Update debugging-in-vscode.md (vuejs#1662) * Added link to vuemeetups.org to the ecosystem drop-down menu on website. (vuejs#1685) * Correct mistake of Migration from Vue 1.x (vuejs#1686) * Fix code style in Form Validation recipe (vuejs#1682) * Fix code style in Form Validation recipe * More style code slight improvement in Form Validation recipe * Fix code style in Client-Side Storage recipe (vuejs#1690) * [Doc EN]: `typescript.md` (vuejs#1679) * New in with + symbol Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com> * Review of 2.5.0 doc Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com> * Review Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com> * Fix syntax typo Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com> * Add space between new line of documentation Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * Add @posva review Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * Add french str Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * Change directeur to director Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * Fix EN doc Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * Subtitle for typescript.md Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * Revert instance.md Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * [cookbook] Dockerize Vue.js App (vuejs#1483) * First draft with 'Simple Example' section * Fix typo on Docker 'build' command * Fix copy of multiple files * Remove unnecessary whitespace * Fix typo in webpack template link * First draft of 'Real-World Example' * Update 'Real-World Example' with multi-stage build * Add 'Why Dockerize a Vue.js App?' section * Rename 'Why Dockerize a Vue.js App?' as 'Additinal Context' * Add 'Alternative Patterns' section * Minor fix on 'Alternative Patterns' * Fixed typo * Update order to avoid collision with other cookbooks * Clarify why NGINX in real-world example * Update debugging-in-vscode.md (vuejs#1663) * remove outdated information about polymer from comparison * update React comparison status * Remove extra part Signed-off-by: Haeresis <bruno.lesieur@gmail.com> * Remove extra content from api/index.md Signed-off-by: Haeresis <bruno.lesieur@gmail.com> * Remove extra merge Signed-off-by: Haeresis <bruno.lesieur@gmail.com>
1 parent d4a75e6 commit 13c5718

21 files changed

+340
-127
lines changed

src/v2/api/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2533,4 +2533,4 @@ Used to denote a `<template>` element as a scoped slot, which is replaced by [`s
25332533

25342534
## Rendu côté serveur
25352535

2536-
- Veuillez vous référer à la [documentation du package vue-server-renderer](https://github.com/vuejs/vue/tree/dev/packages/vue-server-renderer).
2536+
- Veuillez vous référer à la [documentation du package vue-server-renderer](https://github.com/vuejs/vue/tree/dev/packages/vue-server-renderer).

src/v2/cookbook/avoiding-memory-leaks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ new Vue({
4141
methods: {
4242
initializeChoices: function () {
4343
let list = []
44-
// lets load up our select with many choices
44+
// lets load up our select with many choices
4545
// so it will use a lot of memory
4646
for (let i = 0; i < 1000; i++) {
4747
list.push({
@@ -123,7 +123,7 @@ new Vue({
123123

124124
## Details about the Value
125125

126-
Memory management and performance testing can easily be neglected in the excitement of shipping quickly, however, keeping a small memory footprint is still important to your overall user experience.
126+
Memory management and performance testing can easily be neglected in the excitement of shipping quickly, however, keeping a small memory footprint is still important to your overall user experience.
127127

128128
Consider the types of devices your users may be using and what their normal flow will be. Could they use memory constrained laptops or mobile devices? Do your users typically do lots of in-application navigation? If either of these are true, then good memory management practices can help you avoid the worst case scenario of crashing a user’s browser. Even if neither of these are true, you can still potentially have degradation of performance over extended usage of your app if you are not careful.
129129

src/v2/cookbook/client-side-storage.md

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ This example has one form field bound to a Vue value called `name`. Here's the J
2222

2323
``` js
2424
const app = new Vue({
25-
el:'#app',
25+
el: '#app',
2626
data: {
27-
name:''
27+
name: ''
2828
},
2929
mounted() {
30-
if(localStorage.name) this.name = localStorage.name;
30+
if (localStorage.name) {
31+
this.name = localStorage.name;
32+
}
3133
},
3234
watch: {
3335
name(newName) {
@@ -37,7 +39,7 @@ const app = new Vue({
3739
});
3840
```
3941

40-
Focus on the `mounted` and `watch` parts. We use `mounted` to handle loading the value from localStorage. To handle writing the data base, we watch the `name` value and on change, immediately write it.
42+
Focus on the `mounted` and `watch` parts. We use `mounted` to handle loading the value from localStorage. To handle writing the data base, we watch the `name` value and on change, immediately write it.
4143

4244
You can run this yourself here:
4345

@@ -75,12 +77,16 @@ Now we've got two fields (again, bound to a Vue instance) but now there is the a
7577
const app = new Vue({
7678
el:'#app',
7779
data: {
78-
name:'',
79-
age:0
80+
name: '',
81+
age: 0
8082
},
8183
mounted() {
82-
if(localStorage.name) this.name = localStorage.name;
83-
if(localStorage.age) this.age = localStorage.age;
84+
if (localStorage.name) {
85+
this.name = localStorage.name;
86+
}
87+
if (localStorage.age) {
88+
this.age = localStorage.age;
89+
}
8490
},
8591
methods: {
8692
persist() {
@@ -106,30 +112,30 @@ As mentioned above, Local Storage only works with simple values. To store more c
106112
<h2>Cats</h2>
107113
<div v-for="(cat,n) in cats">
108114
<p>
109-
<span class="cat">{{cat}}</span> <button @click="removeCat(n)">Remove</button>
115+
<span class="cat">{{ cat }}</span> <button @click="removeCat(n)">Remove</button>
110116
</p>
111117
</div>
112-
118+
113119
<p>
114-
<input v-model="newCat">
120+
<input v-model="newCat">
115121
<button @click="addCat">Add Cat</button>
116122
</p>
117-
123+
118124
</div>
119125
```
120126

121127
This "app" consists of a simple list on top (with a button to remove a cat) and a small form at the bottom to add a new cat. Now let's look at the JavaScript.
122128

123129
``` js
124130
const app = new Vue({
125-
el:'#app',
131+
el: '#app',
126132
data: {
127-
cats:[],
128-
newCat:null
133+
cats: [],
134+
newCat: null
129135
},
130136
mounted() {
131-
132-
if(localStorage.getItem('cats')) {
137+
138+
if (localStorage.getItem('cats')) {
133139
try {
134140
this.cats = JSON.parse(localStorage.getItem('cats'));
135141
} catch(e) {
@@ -140,13 +146,16 @@ const app = new Vue({
140146
methods: {
141147
addCat() {
142148
// ensure they actually typed something
143-
if(!this.newCat) return;
149+
if (!this.newCat) {
150+
return;
151+
}
152+
144153
this.cats.push(this.newCat);
145154
this.newCat = '';
146155
this.saveCats();
147156
},
148157
removeCat(x) {
149-
this.cats.splice(x,1);
158+
this.cats.splice(x, 1);
150159
this.saveCats();
151160
},
152161
saveCats() {

src/v2/cookbook/debugging-in-vscode.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ Go to `config/index.js` and find the `devtool` property. Update it to:
2424
devtool: 'source-map',
2525
```
2626

27+
With Vue CLI 3 you need set `devtool` property inside `vue.config.js`:
28+
29+
```js
30+
module.exports = {
31+
configureWebpack: {
32+
devtool: 'source-map'
33+
}
34+
}
35+
```
36+
2737
### Launching the Application from VS Code
2838

2939
Click on the Debugging icon in the Activity Bar to bring up the Debug view, then click on the gear icon to configure a launch.json file, selecting **Chrome** for the environment. Replace content of the generated launch.json with the following two configurations:
@@ -53,19 +63,19 @@ Click on the Debugging icon in the Activity Bar to bring up the Debug view, then
5363

5464
1. Set a breakpoint in **src/components/HelloWorld.vue** on `line 90` where the `data` function returns a string.
5565

56-
![Breakpoint Renderer](/images/breakpoint_set.png)
66+
![Breakpoint Renderer](/images/breakpoint_set.png)
5767

5868
2. Open your favorite terminal at the root folder and serve the app using Vue CLI:
5969

60-
```
61-
npm start
62-
```
70+
```
71+
npm start
72+
```
6373

6474
3. Go to the Debug view, select the **'vuejs: chrome'** configuration, then press F5 or click the green play button.
6575

6676
4. Your breakpoint should now be hit as the new instance of Chrome opens `http://localhost:8080`.
6777

68-
![Breakpoint Hit](/images/breakpoint_hit.png)
78+
![Breakpoint Hit](/images/breakpoint_hit.png)
6979

7080
## Alternative Patterns
7181

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
---
2+
title: Dockerize Vue.js App (EN)
3+
type: cookbook
4+
order: 13
5+
---
6+
7+
## Simple Example
8+
9+
<p>Cette page est en cours de traduction. Pour nous aider, vous pouvez participer sur <a href="https://github.com/vuejs-fr/vuejs.org" target="_blank">le dépôt GitHub dédié de Vuejs-FR</a>.</p>So you built your first Vue.js app using the amazing [Vue.js webpack template](https://github.com/vuejs-templates/webpack) and now you really want to show off with your colleagues by demonstrating that you can also run it in a Docker container.</p>
10+
11+
Let's start by creating a `Dockerfile` in the root folder of our project:
12+
13+
```docker
14+
FROM node:9.11.1-alpine
15+
16+
# install simple http server for serving static content
17+
RUN npm install -g http-server
18+
19+
# make the 'app' folder the current working directory
20+
WORKDIR /app
21+
22+
# copy both 'package.json' and 'package-lock.json' (if available)
23+
COPY package*.json ./
24+
25+
# install project dependencies
26+
RUN npm install
27+
28+
# copy project files and folders to the current working directory (i.e. 'app' folder)
29+
COPY . .
30+
31+
# build app for production with minification
32+
RUN npm run build
33+
34+
EXPOSE 8080
35+
CMD [ "http-server", "dist" ]
36+
```
37+
38+
It may seem reduntant to first copy `package.json` and `package-lock.json` and then all project files and folders in two separate steps but there is actually [a very good reason for that](http://bitjudo.com/blog/2014/03/13/building-efficient-dockerfiles-node-dot-js/) (spoiler: it allows us to take advantage of cached Docker layers).
39+
40+
Now let's build the Docker image of our Vue.js app:
41+
42+
```bash
43+
docker build -t vuejs-cookbook/dockerize-vuejs-app .
44+
```
45+
46+
Finally, let's run our Vue.js app in a Docker container:
47+
48+
```bash
49+
docker run -it -p 8080:8080 --rm --name dockerize-vuejs-app-1 vuejs-cookbook/dockerize-vuejs-app
50+
```
51+
52+
We should be able to access our Vue.js app on `localhost:8080`.
53+
54+
## Real-World Example
55+
56+
In the previous example, we used a simple, zero-configuration command-line [http server](https://github.com/indexzero/http-server) to serve our Vue.js app which is perfectly ok for quick prototyping and _may_ even be ok for simple production scenarios. After all, the documentation says:
57+
58+
> It is powerful enough for production usage, but it's simple and hackable enough to be used for testing, local development, and learning.
59+
60+
Nevertheless, for realistically complex production use cases, it may be wiser to stand on the shoulders of some giant like [NGINX](https://www.nginx.com/) or [Apache](https://httpd.apache.org/) and that is exactly what we are going to do next: we are about to leverage NGINX to serve our vue.js app because it is considered to be one of the most performant and battle-tested solutions out there.
61+
62+
Let's refactor our `Dockerfile` to use NGINX:
63+
64+
```docker
65+
# build stage
66+
FROM node:9.11.1-alpine as build-stage
67+
WORKDIR /app
68+
COPY package*.json ./
69+
RUN npm install
70+
COPY . .
71+
RUN npm run build
72+
73+
# production stage
74+
FROM nginx:1.13.12-alpine as production-stage
75+
COPY --from=build-stage /app/dist /usr/share/nginx/html
76+
EXPOSE 80
77+
CMD ["nginx", "-g", "daemon off;"]
78+
```
79+
80+
Ok, let's see what's going on here:
81+
* we have split our original `Dockerfile` in multiple stages by leveraging the Docker [multi-stage builds](https://docs.docker.com/develop/develop-images/multistage-build/) feature;
82+
* the first stage is responsible for building a production-ready artifact of our Vue.js app;
83+
* the second stage is responsible for serving such artifact using NGINX.
84+
85+
Now let's build the Docker image of our Vue.js app:
86+
87+
```bash
88+
docker build -t vuejs-cookbook/dockerize-vuejs-app .
89+
```
90+
91+
Finally, let's run our Vue.js app in a Docker container:
92+
93+
```bash
94+
docker run -it -p 8080:80 --rm --name dockerize-vuejs-app-1 vuejs-cookbook/dockerize-vuejs-app
95+
```
96+
97+
We should be able to access our Vue.js app on `localhost:8080`.
98+
99+
## Additional Context
100+
101+
If you are reading this cookbook, chances are you already know why you decided to dockerize your Vue.js app. But if you simply landed on this page after hitting the Google's `I'm feeling lucky` button, let me share with you a couple of good reasons for doing that.
102+
103+
Today's modern trend is to build applications using the [Cloud-Native](https://pivotal.io/cloud-native) approach which revolves mainly around the following buzzwords:
104+
* Microservices
105+
* DevOps
106+
* Continuous Delivery
107+
108+
Let's see how these concepts actually affect our decision of dockerizing our Vue.js app.
109+
110+
### Effects of Microservices
111+
112+
By adopting the [microservices architectural style](https://martinfowler.com/microservices/), we end up building a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms. These services are built around business capabilities and independently deployable by fully automated deployment machinery.
113+
114+
So, committing to this architectural approach most of the time implies developing and delivering our front-end as an independent service.
115+
116+
### Effects of DevOps
117+
118+
The adoption of [DevOps](https://martinfowler.com/bliki/DevOpsCulture.html) culture, tools and agile engineering practices has, among other things, the nice effect of increasing the collaboration between the roles of development and operations. One of the main problem of the past (but also today in some realities) is that the dev team tended to be uninterested in the operation and maintenance of a system once it was handed over to the ops team, while the latter tended to be not really aware of the system's business goals and, therefore, reluctant in satisfying the operational needs of the system (also referred to as "whims of developers").
119+
120+
So, delivering our Vue.js app as a Docker image helps reducing, if not removing entirely, the difference between running the service on a deveveloper's laptop, the production environment or any environment we may think of.
121+
122+
### Effects of Continuous Delivery
123+
124+
By leveraging the [Continuous Delivery](https://martinfowler.com/bliki/ContinuousDelivery.html) discipline we build our software in a way that it can potentially be released to production at any time. Such engineering practice is enabled by means of what is normally called [continuous delivery pipeline](https://martinfowler.com/bliki/DeploymentPipeline.html). The purpose of a continuous delivery pipeline is to split our build into stages (e.g. compilation, unit tests, integration tests, performance tests, etc.) and let each stage verify our build artifact whenever our software changes. Ultimately, each stage increases our confidence in the production readiness of our build artifact and, therefore, reduces the risk of breaking things in production (or any other environment for that matters).
125+
126+
So, creating a Docker image for our Vue.js app is a good choice here because that would represent our final build artifact, the same artifact that would be verified against our continuous delivery pipeline and that could potentially be released to production with confidence.
127+
128+
## Alternative Patterns
129+
130+
If your company is not into Docker and Kubernetes just yet or you simply want to get your MVP out the door, maybe dockerizing your Vue.js app is not what you need.
131+
132+
Common alternatives are:
133+
* leveraging an all-in-one platform like [netlify](https://www.netlify.com/);
134+
* hosting your SPA on [Amazon S3](https://aws.amazon.com/s3/) and serving it with [Amazon CloudFront](https://aws.amazon.com/cloudfront/) (see [this](https://serverless-stack.com/chapters/deploy-the-frontend.html) link for a detailed guide).

0 commit comments

Comments
 (0)