vulcanjs 功能是以包进行管理,包里面包含了运行依赖的组件以及对于路由的注册
参考项目
- 项目结构
├── README.md├── license.md├── package-lock.json├── package.json├── packages│ ├── _boilerplate-generator│ │ ├── README.md│ │ ├── generator.js│ │ ├── package.js│ │ ├── template-web.browser.js│ │ ├── template-web.cordova.js│ │ └── template.js│ ├── _buffer│ │ ├── buffer.js│ │ └── package.js│ └── dalong-demo│ ├── lib│ │ ├── client│ │ │ └── main.js│ │ ├── modules│ │ │ ├── components│ │ │ │ └── user.jsx│ │ │ ├── index.js│ │ │ └── routes.js│ │ └── server│ │ └── main.js│ └── package.js├── sample_settings.json├── settings.json└── yarn.lock
- 代码说明
代码从vulcanjs starter 获取,删除了默认的package
对于我们主要编写包的代码,就是在packages 目录下创建功能,然后就是在.meteor/packages 进行包的注册
packages/dalong-demo/package.jsPackage.describe({name: 'dalong-demo',});Package.onUse(function (api) {api.use(['promise',// vulcan core'vulcan:core@1.12.3',]);api.mainModule('lib/server/main.js', 'server');api.mainModule('lib/client/main.js', 'client');});packages/dalong-demo/lib/client/main.jspackages/dalong-demo/lib/server/main.jsimport '../modules/index.js';packages/dalong-demo/lib/modules/index.jsimport './routes.js';packages/dalong-demo/lib/modules/routes.jsimport { addRoute, Components } from 'meteor/vulcan:core';import './components/user.jsx';addRoute({ name: 'user', path: '/', componentName: 'dalonginfo' });packages/dalong-demo/lib/modules/components/user.jsximport {registerComponent } from 'meteor/vulcan:core';import React from 'react';const Header = props => {return ()}registerComponent('dalonginfo', Header);dalong demo
注册包
.meteor/packages 文件
# see http://docs.vulcanjs.org/packagesvulcan:core@1.11.2vulcan:i18n@1.12.3############ Your Packages ############ dalong-demo
启动
yarn && yarn start
效果
说明
打开调试控制台,可能会有一些错误,当前可以不用管
参考资料