问题描述:我在使用Meteor的iron cli创建一个项目,并使用了aldeed:collection2包来定义我的集合模式。但是在运行项目时,我遇到了与iron cli不兼容的问题。
解决方法:这个问题通常是因为aldeed:collection2包使用了ES6模块语法,而iron cli默认不支持。为了解决这个问题,你可以按照以下步骤操作:
meteor npm install --save babel-runtime babel-preset-meteor
{
"presets": ["meteor"]
}
import { Meteor } from 'meteor/meteor';
import { ValidatedMethod } from 'meteor/mdg:validated-method';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
const MyCollection = new Mongo.Collection('myCollection');
const myMethod = new ValidatedMethod({
name: 'myMethod',
validate: new SimpleSchema({
myField: {
type: String
}
}).validator(),
run({ myField }) {
// 你的方法逻辑
}
});
Meteor.startup(() => {
// 你的启动代码
});
meteor run
这样,你就可以在使用aldeed:collection2包的同时使用iron cli创建和运行你的Meteor项目了。