|
1 |
| -# Production Deployment <Badge text="WIP" /> |
| 1 | +# Production Deployment |
2 | 2 |
|
3 | 3 | ## Development vs. Production
|
4 | 4 |
|
| 5 | +During development, Vue provides a number of features to improve the development experience: |
| 6 | + |
| 7 | +- Warning for common errors and pitfalls |
| 8 | +- Props / events validation |
| 9 | +- Reactivity debugging hooks |
| 10 | +- Devtools integration |
| 11 | + |
| 12 | +However, these features become useless in production. Some of the warning checks also introduce small runtime overhead. When deploying to production, we should drop all the unused, development-only code branches for smaller payload size and better performance. |
| 13 | + |
5 | 14 | ## Without Build Tools
|
6 | 15 |
|
| 16 | +If you are using Vue without a build tool by loading it from a CDN or self-hosted script, make sure to use the production build (dist files that end in `.prod.js`) when deploying to production. Production builds are pre-minified with all development-only code branches removed. |
| 17 | + |
| 18 | +- If using global build (accessing via the `Vue` global): use `vue.global.prod.js`. |
| 19 | +- If using ESM build (accessing via native ESM imports): use `vue.esm-browser.prod.js`. |
| 20 | + |
| 21 | +Consult the [dist file guide](https://github.com/vuejs/vue-next/tree/master/packages/vue#which-dist-file-to-use) for more details. |
| 22 | + |
7 | 23 | ## With Build Tools
|
8 | 24 |
|
| 25 | +Projects scaffolded via `create-vue` (based on Vite) or Vue CLI (based on webpack) are pre-configured for production builds. |
| 26 | + |
| 27 | +If using a custom setup, make sure that: |
| 28 | + |
| 29 | +1. `vue` resolves to `vue.runtime.esm-bundler.js`. |
| 30 | +2. The [compile time feature flags](https://github.com/vuejs/vue-next/tree/master/packages/vue#bundler-build-feature-flags) are properly configured. |
| 31 | +3. <code>process.env<wbr>.NODE_ENV</code> is replaced with `"production"` during build. |
| 32 | + |
| 33 | +Additional references: |
| 34 | + |
| 35 | +- [Vite production build guide](https://vitejs.dev/guide/build.html) |
| 36 | +- [Vite deployment guide](https://vitejs.dev/guide/static-deploy.html) |
| 37 | +- [Vue CLI deployment guide](https://cli.vuejs.org/guide/deployment.html) |
| 38 | + |
9 | 39 | ## Tracking Runtime Errors
|
| 40 | + |
| 41 | +The [app-level error handler](/api/application.html#app-config-errorhandler) can be used to report errors to tracking services: |
| 42 | + |
| 43 | +```js |
| 44 | +import { createApp } from 'vue' |
| 45 | + |
| 46 | +const app = createApp(...) |
| 47 | + |
| 48 | +app.config.errorHandler = (err, instance, info) => { |
| 49 | + // report error to tracking services |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +Services such as [Sentry](https://docs.sentry.io/platforms/javascript/guides/vue/) and [Bugsnag](https://docs.bugsnag.com/platforms/javascript/vue/) also provide official integrations for Vue. |
0 commit comments