-
Notifications
You must be signed in to change notification settings - Fork 4.7k
docs (#18): add deployment page #412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f7e08e6
docs (#18): add deployment page
bencodezen 2ad688a
docs: remove named file
bencodezen 958d79a
docs: fix app call
bencodezen b812d20
Update src/guide/tooling/deployment.md
sdras ebb8d4b
Update src/guide/tooling/deployment.md
sdras aa4bd32
Update src/guide/tooling/deployment.md
sdras 5ebdcca
Update src/guide/tooling/deployment.md
sdras a8579d1
Update src/guide/tooling/deployment.md
sdras a293f92
Update src/guide/tooling/deployment.md
sdras 29b4720
Update src/guide/tooling/deployment.md
sdras 8b1c1de
remove Webpack 3 details
sdras 9bd6f11
Merge branch 'docs/18-add-deployment-page' of https://github.com/vuej…
sdras File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# Production Deployment | ||
|
||
::: info | ||
Most of the tips below are enabled by default if you are using [Vue CLI](https://cli.vuejs.org). This section is only relevant if you are using a custom build setup. | ||
::: | ||
|
||
## Turn on Production Mode | ||
|
||
During development, Vue provides a lot of warnings to help you with common errors and pitfalls. However, these warning strings become useless in production and bloat your app's payload size. In addition, some of these warning checks have small runtime costs that can be avoided in [production mode](https://cli.vuejs.org/guide/mode-and-env.html#modes). | ||
|
||
### Without Build Tools | ||
|
||
If you are using the full build, i.e. directly including Vue via a script tag without a build tool, make sure to use the minified version for production. This can be found in the [Installation guide](installation.html#cdn). | ||
|
||
### With Build Tools | ||
|
||
When using a build tool like Webpack or Browserify, the production mode will be determined by `process.env.NODE_ENV` inside Vue's source code, and it will be in development mode by default. Both build tools provide ways to overwrite this variable to enable Vue's production mode, and warnings will be stripped by minifiers during the build. Vue CLI has this pre-configured for you, but it would be beneficial to know how it is done: | ||
|
||
#### Webpack | ||
|
||
In Webpack 4+, you can use the `mode` option: | ||
|
||
```js | ||
module.exports = { | ||
mode: 'production' | ||
} | ||
``` | ||
|
||
#### Browserify | ||
|
||
- Run your bundling command with the actual `NODE_ENV` environment variable set to `"production"`. This tells `vueify` to avoid including hot-reload and development related code. | ||
|
||
- Apply a global [envify](https://github.com/hughsk/envify) transform to your bundle. This allows the minifier to strip out all the warnings in Vue's source code wrapped in env variable conditional blocks. For example: | ||
|
||
```bash | ||
NODE_ENV=production browserify -g envify -e main.js | uglifyjs -c -m > build.js | ||
``` | ||
|
||
- Or, using [envify](https://github.com/hughsk/envify) with Gulp: | ||
|
||
```js | ||
// Use the envify custom module to specify environment variables | ||
const envify = require('envify/custom') | ||
|
||
browserify(browserifyOptions) | ||
.transform(vueify) | ||
.transform( | ||
// Required in order to process node_modules files | ||
{ global: true }, | ||
envify({ NODE_ENV: 'production' }) | ||
) | ||
.bundle() | ||
``` | ||
|
||
- Or, using [envify](https://github.com/hughsk/envify) with Grunt and [grunt-browserify](https://github.com/jmreidy/grunt-browserify): | ||
|
||
```js | ||
// Use the envify custom module to specify environment variables | ||
const envify = require('envify/custom') | ||
|
||
browserify: { | ||
dist: { | ||
options: { | ||
// Function to deviate from grunt-browserify's default order | ||
configure: (b) => | ||
b | ||
.transform('vueify') | ||
.transform( | ||
// Required in order to process node_modules files | ||
{ global: true }, | ||
envify({ NODE_ENV: 'production' }) | ||
) | ||
.bundle() | ||
} | ||
} | ||
} | ||
``` | ||
|
||
#### Rollup | ||
|
||
Use [@rollup/plugin-replace](https://github.com/rollup/plugins/tree/master/packages/replace): | ||
|
||
```js | ||
const replace = require('@rollup/plugin-replace') | ||
|
||
rollup({ | ||
// ... | ||
plugins: [ | ||
replace({ | ||
'process.env.NODE_ENV': JSON.stringify( 'production' ) | ||
}) | ||
] | ||
}).then(...) | ||
``` | ||
|
||
## Pre-Compiling Templates | ||
|
||
When using in-DOM templates or in-JavaScript template strings, the template-to-render-function compilation is performed on the fly. This is usually fast enough in most cases, but is best avoided if your application is performance-sensitive. | ||
|
||
The easiest way to pre-compile templates is using [Single-File Components](single-file-component.html) - the associated build setups automatically performs pre-compilation for you, so the built code contains the already compiled render functions instead of raw template strings. | ||
|
||
If you are using Webpack, and prefer separating JavaScript and template files, you can use [vue-template-loader](https://github.com/ktsn/vue-template-loader), which also transforms the template files into JavaScript render functions during the build step. | ||
|
||
## Extracting Component CSS | ||
|
||
When using Single-File Components, the CSS inside components are injected dynamically as `<style>` tags via JavaScript. This has a small runtime cost, and if you are using server-side rendering it will cause a "flash of unstyled content". Extracting the CSS across all components into the same file will avoid these issues, and also result in better CSS minification and caching. | ||
|
||
Refer to the respective build tool documentations to see how it's done: | ||
|
||
- [Webpack + vue-loader](https://vue-loader.vuejs.org/en/configurations/extract-css.html) (the `vue-cli` webpack template has this pre-configured) | ||
- [Browserify + vueify](https://github.com/vuejs/vueify#css-extraction) | ||
- [Rollup + rollup-plugin-vue](https://rollup-plugin-vue.vuejs.org/) | ||
|
||
## Tracking Runtime Errors | ||
|
||
If a runtime error occurs during a component's render, it will be passed to the global `app.config.errorHandler` config function if it has been set. It might be a good idea to leverage this hook together with an error-tracking service like [Sentry](https://sentry.io), which provides [an official integration](https://sentry.io/for/vue/) for Vue. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.