After successfully using decorators for a while inside the /imports directory with the use of the Babel ‘transform-decorators-legacy’-plugin, I found that they don’t work inside packages when I started to split my project into smaller parts.
When I import the decorators inside a local package (which are exported from another package) they do not work on (React Component) classes written inside that package (they work on React Components inside the /imports directory).
The package loads the ecmascript-package, and I have also tried to use the babel-runtime and babel-compiler packages, but without any difference.
Does anybody know what I am doing wrong?
Thanks for helping out!
For example, I have the following decorator exported from the ‘test-decorator’ package:
export function exampleDecorator(variable1) {
console.log(variable1);
return function (target) {
console.log(target);
};
}
When I use the decorator on a class inside the /imports directory, the console.log’s are shown.
Decorated class:
import { exampleDecorator } from 'meteor/test-decorator';
@exampleDecorator('variable1')
class UiMain extends Component {
}
But when I try the same code from inside a package, nothing is shown - but the component still works as expected (however, without the ‘extra decorations’). The .onUse configuration from the ‘destination’ package:
Package.onUse(function(api) {
api.versionsFrom('1.4.4.2');
api.use('ecmascript');
api.use('test-decorator');
api.mainModule('test-decorated-class.js');
});
Also when I place the decorator in the same file (inside the package) as the Component, nothing happens: it’s like the decorator line above the class definition is not there.