Search code examples
vuejs2web-deployment

Two ways of deploying Vue


I understand that there are basically two ways of deploying a vue app. One is to include the library directly with:

 <script src="https://unpkg.com/vue"></script>

and the other method is to use vue cli, then build with npm

I saw many tutorials, but I could not get a quite understanding of what exactly is different, or what are the advantages of each side?


Solution

  • Vue can be used through -

    1. CLI - es NPM / yarn to install Vue. Sets up default config pretty nicely
    2. NPM - (or yarn) install Vue directly and configure yourself [recommended for large projects]
    3. CDN - refer directly through in your HTML /script

    If you want to just include Vue in your script that has a larger objective, or accomplish something 'comparatively' simple, just use CDN. This is a good way to use the power of Vue without worrying about the intermediate build steps specific to Vue. Your completed product will continue to refer to Vue from CDN.

    Also, each CDN lookup will mean an additional server request - this is likely to serve content faster than your own server, but an additional lookup nevertheless. Having tens of CDNs is not ideal.

    For larger projects, NPM is ideal. You would want the power of Single File Components with (files with a .vue extension) that play well with editors, and provide a more structured way to develop the application (incl. things like scoped CSS).

    Also, the build step through local Vue is a must if you use functions not supported by browsers today, or want to support older browsers.

    https://v2.vuejs.org/v2/guide/installation.html