This time I will bring you an analysis of the steps for publishing vue components to npm. What are the precautions for publishing vue components to npm? The following is a practical case, let's take a look.
Why do you have this idea? It is mainly because the custom components in the vue project are used in multiple projects. When modifying a bug, you always have to modify it in the project branch and then synchronize it to the main line. This will easily lead to the branches not being synchronized to the main line after modification. This will slowly lead to inconsistent component versions, making upgrading components very cumbersome. In the end, we may have to maintain different versions of multiple components, which is not what we want. So I plan to package and publish the components to npm. In each project, you only need to modify the component version in package.json to synchronize the latest version.Component release process
1. I didn’t know much about packaging at first. I just simply extracted the original .vue file and related css and image resources, and then Put it under a project. Here are the detailed steps for publishing components to npm: (1) Create a new component project and initialize a package.json file through npm init (2) Extract the components Put it in the project path.
(3) In the directory where package.json is located, execute npm adduser. Here you need to register an npm account
(4) and then you are asked to enter your username, password, and email address filled in when registering. As shown in the picture:
attribute in package.json to set the path for loading js. As shown in the picture:
#4. The loading problem is solved, and the remaining problem is packaging. Since packaging requires some webpack configuration, I directly initialized a project with vue-cli and adjusted the webpack in it. The main thing is to remove the packagingconfiguration file webpack.prod.conf.js in the build, and remove the HtmlWebpackPlugin, etc. here.
https://github.com/myGitZone/mapModule Here is an example, this project is just a demo.
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website! Recommended reading:Detailed explanation of the steps for Vue to use vee-validate to verify the form
The above is the detailed content of Vue component publishing to npm step analysis. For more information, please follow other related articles on the PHP Chinese website!