wuye1200 / blog

alber blog
0 stars 0 forks source link

npm #23

Open wuye1200 opened 5 years ago

wuye1200 commented 5 years ago

sinopia 本地npm快速解决方案

npm install -g sinopia

启动 sinopia

pwd
/home/nadmin
$ sinopia
warn --- config file - /home/nadmin/sinopia/config.yaml
warn --- http address - http://0.0.0.0:4873/
http --> 200, req: 'GET http://registry.npm.taobao.org/express', bytes: 0/578356
http <-- 200, user: admin, req: 'GET /express', bytes: 0/34448
http --> 200, req: 'GET http://registry.npm.taobao.org/type-is', bytes: 0/54083

pm2 start sinopia

安装nrm

nrm是 npm registry 管理工具, 能够查看和切换当前使用的registry。不安装也可以。

npm install -g nrm
nrm ls
-----------------------------------------------------------
  npm ---- https://registry.npmjs.org/
  cnpm --- http://r.cnpmjs.org/
* taobao - https://registry.npm.taobao.org/
  nj ----- https://registry.nodejitsu.com/
  rednpm - http://registry.mirror.cqupt.edu.cn/
  npmMirror  https://skimdb.npmjs.com/registry/
  edunpm - http://registry.enpmjs.org/
  mytestnpm  http://ServerS:4873/  

使用命令 $ nrm add XXXXX http://XXXXXX:4873 # 添加本地的npm镜像地址 $ nrm use XXXX # 使用本址的镜像地址

发布

npm publish 运行npm adduser注册账号,如果已经有账号直接运行 npm login 登录成功时可通过npm whoami查看

wuye1200 commented 5 years ago

npm init 初始化

这里用的是webpack-simple,可以理解为精简版的vue-cli npm install npm dev

还需要在src下面新建一个index.js作为入口文件,代码:

// src/index.js export { default } from './components/vue-xxx

修改package.json

"main": "dist/index.js", "jsnext:main": "src/index.js", // 采用es6模块化入口 "private": false, // 因为组件包是公用的,所以private为false

修改webpack.config.js

// 原
module.exports = {
  entry: './src/main.js',
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/dist/',
    filename: 'build.js'
  }
...
}
// 新
module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/dist/',
    filename: 'index.js',
    libraryTarget: 'umd',
    umdNamedDefine: true
  }
...
}

测试插件

npm run build npm pack