You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/v2/guide/index.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ If you are an experienced frontend developer and want to know how Vue compares t
17
17
The easiest way to try out Vue.js is using the [JSFiddle Hello World example](https://jsfiddle.net/chrisvfritz/50wL7mdz/). Feel free to open it in another tab and follow along as we go through some basic examples. Or, you can simply create an `.html` file and include Vue with:
The [Installation](installation.html) page provides more options of installing Vue. Note that we **do not** recommend beginners to start with `vue-cli`, especially if you are not yet familiar with Node.js-based build tools.
@@ -17,7 +17,7 @@ Vue does **not** support IE8 and below, because it uses ECMAScript 5 features th
17
17
18
18
Detailed release notes for each version are available on [GitHub](https://github.com/vuejs/vue/releases).
19
19
20
-
## Standalone
20
+
## Direct `<script>` Include
21
21
22
22
Simply download and include with a script tag. `Vue` will be registered as a global variable.
23
23
@@ -31,7 +31,7 @@ Simply download and include with a script tag. `Vue` will be registered as a glo
31
31
32
32
### CDN
33
33
34
-
Recommended: [unpkg](https://unpkg.com/vue/dist/vue.js), which will reflect the latest version as soon as it is published to npm. You can also browse the source of the npm package at [unpkg.com/vue/](https://unpkg.com/vue/).
34
+
Recommended: [https://unpkg.com/vue](https://unpkg.com/vue), which will reflect the latest version as soon as it is published to npm. You can also browse the source of the npm package at [https://unpkg.com/vue/](https://unpkg.com/vue/).
35
35
36
36
Also available on [jsDelivr](//cdn.jsdelivr.net/vue/latest/vue.js) or [cdnjs](//cdnjs.cloudflare.com/ajax/libs/vue/{{vue_version}}/vue.js), but these two services take some time to sync so the latest release may not be available yet.
37
37
@@ -44,58 +44,171 @@ NPM is the recommended installation method when building large scale application
44
44
$ npm install vue
45
45
```
46
46
47
-
### Standalone vs. Runtime-only Build
47
+
## CLI
48
+
49
+
Vue.js provides an [official CLI](https://github.com/vuejs/vue-cli) for quickly scaffolding ambitious Single Page Applications. It provides batteries-included build setups for a modern frontend workflow. It takes only a few minutes to get up and running with hot-reload, lint-on-save, and production-ready builds:
50
+
51
+
```bash
52
+
# install vue-cli
53
+
$ npm install --global vue-cli
54
+
# create a new project using the "webpack" template
55
+
$ vue init webpack my-project
56
+
# install dependencies and go!
57
+
$ cd my-project
58
+
$ npm install
59
+
$ npm run dev
60
+
```
61
+
62
+
<pclass="tip">The CLI assumes prior knowledge of Node.js and the associated build tools. If you are new to Vue or front-end build tools, we strongly suggest going through <ahref="./">the guide</a> without any build tools before using the CLI.</p>
63
+
64
+
## Explanation of Different Builds
48
65
49
-
There are two builds available, the standalone build and the runtime-only build. The difference being that the former includes the **template compiler** and the latter does not.
66
+
In the [`dist/` directory of the NPM package](https://unpkg.com/vue@latest/dist/) you will find many different builds of Vue.js. Here's an overview of the difference between them:
50
67
51
-
The template compiler is responsible for compiling Vue template strings into pure JavaScript render functions. If you want to use the `template` option, then you need the compiler.
- The standalone build includes the compiler and supports the `template` option. **It also relies on the presence of browser APIs so you cannot use it for server-side rendering.**
75
+
### Terms
54
76
55
-
-The runtime-only build does not include the template compiler, and does not support the `template` option. You can only use the `render` option when using the runtime-only build, but it works with single-file components, because single-file components' templates are pre-compiled into `render` functions during the build step. The runtime-only build is roughly 30% lighter-weight than the standalone build, weighing only {{ro_gz_size}}kb min+gzip.
77
+
-**Full**: builds that contains both the compiler and the runtime.
56
78
57
-
By default, the NPM package exports the **runtime-only** build. To use the standalone build, add the following alias to your Webpack config:
79
+
-**Compiler**: code that is responsible for compiling template strings into JavaScript render functions.
80
+
81
+
-**Runtime**: code that is responsible for creating Vue instances, rendering and patching virtual DOM, etc. Basically everything minus the compiler.
82
+
83
+
-**[UMD](https://github.com/umdjs/umd)**: UMD builds can be used directly in the browser via a `<script>` tag. The default file from Unpkg CDN at [https://unpkg.com/vue](https://unpkg.com/vue) is the Runtime + Compiler UMD build (`vue.js`).
84
+
85
+
-**[CommonJS](http://wiki.commonjs.org/wiki/Modules/1.1)**: CommonJS builds are intended for use with older bundlers like [browserify](http://browserify.org/) or [webpack 1](https://webpack.github.io). The default file for these bundlers (`pkg.main`) is the Runtime only CommonJS build (`vue.runtime.common.js`).
86
+
87
+
-**[ES Module](http://exploringjs.com/es6/ch_modules.html)**: ES module builds are intended for use with modern bundlers like [webpack 2](https://webpack.js.org) or [rollup](http://rollupjs.org/). The default file for these bundlers (`pkg.module`) is the Runtime only ES Module build (`vue.runtime.esm.js`).
88
+
89
+
### Runtime + Compiler vs. Runtime-only
90
+
91
+
If you need to compile templates on the fly (e.g. passing a string to the `template` option, or mounting to an element using its in-DOM HTML as the template), you will need the compiler and thus the full build:
58
92
59
93
```js
60
-
resolve: {
61
-
alias: {
62
-
'vue$':'vue/dist/vue.common.js'
94
+
// this requires the compiler
95
+
newVue({
96
+
template:`<div>{{ hi }}</div>`
97
+
})
98
+
99
+
// this does not
100
+
newVue({
101
+
render (h) {
102
+
returnh('div', this.hi)
103
+
}
104
+
})
105
+
```
106
+
107
+
When using `vue-loader` or `vueify`, templates inside `*.vue` files are pre-compiled into JavaScript at build time. You don't really need the compiler in the final bundle, and can therefore use the runtime-only build.
108
+
109
+
Since the runtime-only builds are roughly 30% lighter-weight than their full-build counterparts, you should use it whenever you can. If you still wish to use the full build instead, you need to configure an alias in your bundler:
110
+
111
+
#### Webpack
112
+
113
+
```js
114
+
module.exports= {
115
+
// ...
116
+
resolve: {
117
+
alias: {
118
+
'vue$':'vue/dist/vue.esm.js'// 'vue/dist/vue.common.js' for webpack 1
119
+
}
63
120
}
64
121
}
122
+
````
123
+
124
+
#### Rollup
125
+
126
+
``` js
127
+
const alias = require('rollup-plugin-alias')
128
+
129
+
rollup({
130
+
// ...
131
+
plugins: [
132
+
alias({
133
+
'vue': 'vue/dist/vue.esm.js'
134
+
})
135
+
]
136
+
})
65
137
```
66
138
67
-
For Browserify, you can add an alias to your package.json:
139
+
#### Browserify
140
+
141
+
Add to your project's `package.json`:
68
142
69
143
``` js
70
-
"browser": {
71
-
"vue":"vue/dist/vue.common"
72
-
},
144
+
{
145
+
// ...
146
+
"browser": {
147
+
"vue": "vue/dist/vue.common.js"
148
+
}
149
+
}
73
150
```
74
151
75
-
<pclass="tip">Do NOT do `import Vue from 'vue/dist/vue.js'` - since some tools or 3rd party libraries may import vue as well, this may cause the app to load both the runtime and standalone builds at the same time and lead to errors.</p>
152
+
### Development vs. Production Mode
76
153
77
-
### CSP environments
154
+
Development/production modes are hard-coded for the UMD builds: the un-minified files are for development, and the minified files are for production.
78
155
79
-
Some environments, such as Google Chrome Apps, enforce Content Security Policy (CSP), which prohibits the use of `new Function()`for evaluating expressions. The standalone build depends on this feature to compile templates, so is unusable in these environments.
156
+
CommonJS and ES Module builds are intended for bundlers, therefore we don't provide minified versions forthem. You will be responsible for minifying the final bundle yourself.
80
157
81
-
On the other hand, the runtime-only build is fully CSP-compliant. When using the runtime-only build with [Webpack + vue-loader](https://github.com/vuejs-templates/webpack-simple) or [Browserify + vueify](https://github.com/vuejs-templates/browserify-simple), your templates will be precompiled into `render` functions which work perfectly in CSP environments.
158
+
CommonJS and ES Module builds also preserve raw checks for`process.env.NODE_ENV` to determine the mode they should run in. You should use appropriate bundler configurations to replace these environment variables in order to control which mode Vue will run in. Replacing`process.env.NODE_ENV`with string literals also allows minifiers like UglifyJS to completely drop the development-only code blocks, reducing final file size.
82
159
83
-
##CLI
160
+
#### Webpack
84
161
85
-
Vue.js provides an [official CLI](https://github.com/vuejs/vue-cli) for quickly scaffolding ambitious Single Page Applications. It provides batteries-included build setups for a modern frontend workflow. It takes only a few minutes to get up and running with hot-reload, lint-on-save, and production-ready builds:
162
+
Use Webpack's [DefinePlugin](https://webpack.js.org/plugins/define-plugin/):
163
+
164
+
``` js
165
+
var webpack = require('webpack')
166
+
167
+
module.exports = {
168
+
// ...
169
+
plugins: [
170
+
// ...
171
+
new webpack.DefinePlugin({
172
+
'process.env': {
173
+
NODE_ENV: JSON.stringify('production')
174
+
}
175
+
})
176
+
]
177
+
}
178
+
```
179
+
180
+
#### Rollup
181
+
182
+
Use [rollup-plugin-replace](https://github.com/rollup/rollup-plugin-replace):
<pclass="tip">The CLI assumes prior knowledge of Node.js and the associated build tools. If you are new to Vue or front-end build tools, we strongly suggest going through <ahref="./">the guide</a> without any build tools before using the CLI.</p>
205
+
Also see [Production Deployment Tips](./deployment.html).
206
+
207
+
### CSP environments
208
+
209
+
Some environments, such as Google Chrome Apps, enforce Content Security Policy (CSP), which prohibits the use of `new Function()` for evaluating expressions. The standalone build depends on this feature to compile templates, so is unusable in these environments.
210
+
211
+
On the other hand, the runtime-only build is fully CSP-compliant. When using the runtime-only build with [Webpack + vue-loader](https://github.com/vuejs-templates/webpack-simple) or [Browserify + vueify](https://github.com/vuejs-templates/browserify-simple), your templates will be precompiled into `render` functions which work perfectly in CSP environments.
99
212
100
213
## Dev Build
101
214
@@ -110,11 +223,13 @@ npm run build
110
223
111
224
## Bower
112
225
226
+
Only UMD builds are available from Bower.
227
+
113
228
``` bash
114
229
# latest stable
115
230
$ bower install vue
116
231
```
117
232
118
233
## AMD Module Loaders
119
234
120
-
The standalone downloads or versions installed via Bower are wrapped with UMD so they can be used directly as an AMD module.
235
+
All UMDbuilds can be used directly as an AMDmodule.
0 commit comments