前言:工作的时候总是使用别人的npm包,然而我有时心底会好奇自己如何发布一个npm包呢,什么时候自己的包能够被很多人喜欢并使用呢...今天我终于迈出了第一步。
前提:会使用 npm,有 vue 基础,了解一点 webpack
Are you ready? Go!
一、编写自己的npm包
1. 新建一个空文件夹
2. 进入文件夹,终端(cmd)运行 npm init
完成后会在目录下生成一个 package.json 文件
我们可以根据自己的需要补充文件内容
这是我的:
{
"name": "bing-test-publish-npm",
"version": "1.0.0",
"description": "布一个npm包",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server --hot --inline",
"build": "webpack --display-error-details --config webpack.config.js"
},
"author": "bing",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-polyfill": "^6.26.0",