Vue project deployment to online dependency problem

has always been curious about one thing: when developing a vue project, we all install project dependencies through cnpm install. In a production environment, we just need to package the project and put it on an online server to run. Why can online servers run without installing related dependencies?

Jan.16,2022

first of all, you have to understand how the browser runs the code, and secondly, your packaging tool will analyze the dependencies in your code and bring up the necessary things, and most of the dependencies you install work for your packaging system, not for your own code


all plug-in packages can be divided into two categories, one for development and the other for runtime.

when you develop in the local environment, you need to use a local server plug-in, which is used when developing, because the production environment has its own server configuration, so you don't need it. Its function is to simulate the online server to provide a release path, so you can render your code in the browser. So what did he end up presenting?

that is the temporary html,css,js files generated by build tools such as gulp and webpack that package your business code and plug-ins. Only these files can be understood by the final browser and finally sent to production, and these three formats are also accepted locally.

when the tool is built locally, the plug-ins that you have to rely on at run time are also packaged into your js file, which is tantamount to extracting all the parts you need from the previously installed dependencies. The build tool does this kind of thing, so when developing with the build tool, it saves the hard work of manually adding script references to various plug-ins, but it can be replaced in this way.

the online server is the same as your local one, just waiting for you to upload the packaged file and present it to the browser.

Menu