I am writing an Aurelia plugin and need consumers to have access to a decorator function which is defined within the plugin. How do I make it accessible to the plugin’s consumers?
Essentially you just export it. See here for the Stores connectTo decorator. https://github.com/aurelia/store/blob/master/src/decorator.ts#L21
Thanks! I figured it was easy.
I got sidetracked and just got around to trying this out. I’m using the current cli plugin structure with dev-app and src directories. My decorator is in src/decorators/my-decorator.js. When I try to import it in a dev-app class by referring to the plugin as “resources”, like this:
import {myDecorator} from 'resources/decorators/my-decorator';
I get an error stating “SyntaxError: Unexpected token ‘{’. import call expects exactly one argument.”
If I move my decorator file into the dev-app directory and import it like this:
import {myDecorator} from './my-decorator';
It works fine.
That SyntaxError looks very strange in context of 'resources/...'
, can you share a small repo to reproduce it?
I got no issue on your resources import.
My decorator begins with:
import {bindable, bindingMode} from 'aurelia-framework';
I assume the error is referring to this. Could you try adding this import statement to your my-decorator.js file?
Never mind! I just realized I needed to terminate au run
and rerun it! Now all is well. Thanks for everyone’s help.