Vue can be used as a standalone script file - no build step required!
Some typical use cases:
- You don't want to add the complexity of a build step as your frontend logic is not very complex
- You are using a backend framework that is rendering most of the HTML
The official docs describe Vue without a build step as "a more declarative replacement of jQuery".
To avoid the build step, we can load Vue directly from a CDN via the script tag:
In our example, we use unpkg as CDN to fetch the npm package. Of course, you can use any other CDN that serves npm packages or download the file and serve it yourself.
The CDN link loads a global build of Vue. This build exposes all top-level APIs on the global Vue object. Let's take a look at a working example:
I deployed this index.html
to Netlify: Check it out
Notes on Production Use
When deploying to production you should make sure to use the production builds (dist files that end in .prod.js
):
Check Which dist file to use? for more details.
If you liked this Vue tip, follow me on X to get notified about new tips, blog posts, and more. Alternatively (or additionally), you can subscribe to my weekly Vue & Nuxt newsletter:
Vue Tip: Defining and Registering Vue Web Components
Web Components is an umbrella term for a set of web native APIs that allows developers to create reusable custom elements. Vue has excellent support for both consuming and creating custom elements.
Vue Tip: Change the Interpolation Delimiter
It is possible to adjust the delimiters used for text interpolation within the template to avoid conflicting with server-side frameworks that also use mustache syntax.