Vue-cli v3.10 Create a project, publish NPM package, and step on the pit
January 19, 2024
by 陳詩涵
No Comments
Install the vue – cli
Please make sure nodeJS,vue is installed first
NPM install -g@vue /cli
Vue CLI package name changed from vue-cli to @vue/ CLI. If you have installed an older version of VUe-CLI (1.x or 2.x) globally, you need to uninstall it first through NPM uninstall vue-cli -g or YARN Global Remove VUe-cli.
Vue-v Check whether the installation is successful
Bash: vue: command not found; Run vue -v in the installation directory to check whether the installation is successful. If the installation is successful, but an error is reported in other directories, please check whether the environment variables are correctly configured. If the fault persists, uninstall node,vue, and vue- CLI again
The user variables
System variables
Create a project
Create a project named vue-short-cut: vue create vue-short-cut
Select Settings: you can choose default(Babel, ESLint), or maally select features to choose your vuex,typescript, etc configuration.
Check whether the installation is successful:
Create the contents of the NPM package
1. Project directory (functional development, no problem in testing, normal installation of dependent packages if any)
2. Configuration in package.json
Check whether the package exists:www.npmjs.com/
Adding Component Information
{
"name": "vue-short-cut".// Package name, which cannot conflict with an existing name;"version":"0.1.0 from".// The version number cannot be the same as the historical version number;"description":"Use vue's Directive to quickly get focus, support return, arrow keys, and return + arrow keys."./ / profile;"main":"lib/vue-short-cut.umd.min.js".// The entry file should point to the compiled package file;"keyword":"vue directive short cut focus".// Keywords, separated by Spaces;"author":"logmei"./ / the author;"private":false.// If private, change to false to publish to NPM;"license":"MIT".// Open source protocol.. }Copy the code
Add package commands in scripts (cli3+ does not need to configure webpack.config.js separately)
Build the target official document
Target: Builds the application by default. Change it to lib to enable the build library mode
Name: indicates the output file name
Dest: output directory, dist by default, lib instead
Entry: The path to the entry file. The default path is SRC/app. vue
Gitignore ignore files (files that are not ignored will be sent to NPM, the same directory after installation, just like unzips their own files, installed in node_modules)
1. Go to the official website to register userswww.npmjs.com
2. Local delivery
Login: NPM login
Publish: NPM publish
Issues encountered at launch
1, need to modify the address, generally in order to download faster will be changednpm config set registry https://registry.npm.taobao.org, but the NPM package must be published with the address of NPM:npm config set registry http://registry.npmjs.org/
npm ERR! code E403
npm ERR! 403 Forbidden - PUT https://registry.npm.taobao.org/vue-short-cut - [no_perms] Private mode enable, only admin can publish this moduleCopy the code
2. Change package.json to name
npm ERR! publish Failed PUT 403
npm ERR! code E403
npm ERR! You do not have permission to publish "vue-short-cut". Are you logged inas the correct user?
Copy the code
3. If the package name is similar to an existing package, it will prompt you to change the package name, modify the name in package.json, and run itnpm publish --access=public
npm ERR! code E403
npm ERR! 403 Forbidden - PUT http://registry.npmjs.org/vue-short-cut - Package name too similar to existing packages; try renaming your package to '@logmei/vue-short-cut' and publishing with 'npm publish --access=public' insteadCopy the code
4. The version cannot be repeated. You need to change the version in package.json
npm ERR! code E403
npm ERR! 403 Forbidden - PUT http:Size cut - You cannot publish over the previously published versions: 0.1.2.Copy the code
According to the specification, unpublish is only allowed with versions published in the last 24 hours. Even if you undo the package, you can no longer send the package with the same name and version as the package being revoked.
View the package after successful publishing
Use the published NPM package
The installationnpm i @logmei/vue-short-cut -D
Check the installation package and find that the installation is successful
References in main.js can also be referenced on individual pages
import VueShortCut from'@logmei/vue-short-cut'
Vue.use(VueShortCut)
Copy the code