james-ui
v0.0.11
Published
组件库
Downloads
13
Readme
/* 打包命令: "lib": "vue-cli-service build --target lib --name james --dest lib packages/index.js" target: 默认为构建应用,改为 lib 即可启用构建库模式 name: 输出文件名 exports["james"] dest: 输出目录,默认为 dist,这里我们改为 lib entry: 入口文件路径,默认为 src/App.vue,这里改为 packages/index.js
vue-cli-service build [options] [entry|pattern]
选项:
--mode 指定环境模式 (默认值:production)
--dest 指定输出目录 (默认值:dist)
--modern 面向现代浏览器带自动回退地构建应用
--target app | lib | wc | wc-async (默认值:app)
--name 库或 Web Components 模式下的名字 (默认值:package.json 中的 "name" 字段或入口文件名)
--no-clean 在构建项目之前不清除目标目录
--report 生成 report.html 以帮助分析包内容
--report-json 生成 report.json 以帮助分析包内容
--watch 监听文件变化
*/
examples文件里面是测试文件,不用发布到npm组件里面
本地测试: npm run serve
打包: 把packages里面的内容全部打包 npm run lib
发布: .npmignore文件是npm上传忽略文件列表 npm run login npm run pub
最终上传到npm组件库的内容是: lib: 放置的是所有组件打包之后的内容 packages: 放置的是单个包
使用方式:
1. 安装包
cnpm i -D james-ui
2. 配置
main.js中
全局引入组件
import JamesUi from 'james-ui';
Vue.use(JamesUi);
引入单个组件
import { JamesLink, JamesColor } from 'james-ui';
Vue.use(JamesLink);
Vue.use(JamesColor);
使用的时候注意使用 my-plugin-import: 1. 默认导入( 全部导入 ) 加载lib里面的文件 2. 导入列表 加载packages里面的文件
实现全部加载:
import JamesUi from 'james-ui';
转化成:
import JamesUi from '../node_module/james-ui/lib/james.umd.min.js';
实现按需加载:
import { JamesColor, JamesLink } from 'james-ui';
转化成:
import JamesColor from '../node_module/james-ui/packages/components/JamesColor/index.js';
import JamesLink from '../node_module/james-ui/packages/components/JamesLink/index.js';
最终实现的效果:按需加载,没有引入的组件,不会打包进去; 全部加载,所有组件全部打包进去