I created a new Aurelia
plugin, which is named Aurelia-Slickgrid
and got it all working locally with .feature('resources')
. I was then ready for the next step, making it available to everyone as a plugin and created a Github project and made it available under this GitHub link - Aurelia-Slickgrid. I used Aurelia Skeleton Plugin to create my plugin, also ran gulp build
to create the transpiled output. I then published it on NPM
and successfully installed it with npm i --save aurelia-slickgrid
. I am currently using Aurelia-CLI
to bundle and everything goes well, until I open the browser and see that an error got thrown in the console (now I'm left with a white page in the browser):
Uncaught TypeError: plugin.load is not a function
at Module.<anonymous> (vendor-bundle.js:5308)
...
For the moment, I am trying to load it as a plugin with Aurelia-CLI
. See below for the complete configuration used:
index.js
of the plugin
import {AureliaSlickgrid} from './aurelia-slickgrid';
import {SlickPager} from './slick-pager';
import {SlickWindowResizer} from './slick-window-resizer';
export function configure(config) {
config.globalResources('./aurelia-slickgrid');
config.globalResources('./slick-pager');
config.globalResources('./slick-window-resizer');
}
export {
AureliaSlickgrid,
SlickPager,
SlickWindowResizer
}
main.js
(of my local project)
aurelia.use
.standardConfiguration()
.feature('resources')
.plugin('aurelia-slickgrid');
aurelia.json
(of my local project)
{
"name": "aurelia-slickgrid",
"path": "../node_modules/aurelia-slickgrid/dist/amd",
"main": "index"
},
If you're testing with an empty Aurelia CLI project you need to add:
{
"name": "aurelia-slickgrid",
"path": "../node_modules/aurelia-slickgrid/dist/amd",
"main": "index"
},
"slickgrid-es6",
"jquery"
Finally import
to use it in code via:
import {AureliaSlickgrid} from 'aurelia-slickgrid';
The documentation on how to create an Aurelia Plugin
is almost non existing, so I based myself on another plugin, namely Aurelia-Bootstrap made by a great Aurelia Contributor. One of the file that greatly influenced my plugin code was his index.js and I used his coding styling to code mine.
Any idea where could be my problem?
I also tried to add resources
to the aurelia.json
, however it had no effects.
{
"name": "aurelia-slickgrid",
"path": "../node_modules/aurelia-slickgrid/dist/amd",
"main": "index",
"resources": [
"**/*.html"
]
},
Got a bit further, after searching for a few other Aurelia plugins. It seems that globalResources
should only be View/ViewModel pair (html/js), in my case I only have 1 of those pair which is SlickPager
and now only that one is being called by globalResources()
. Another possible problem, still to confirm though, I had a file named aurelia-slickgrid.js
which is the same naming as the plugin name, could that cause a conflict? Possibly...who knows. So anyway, I renamed it to slick-service.js
and renamed the class to SlickService
. I am now able to call 2/3 of my objects in the WebPack Skeleton
, however I still can't import SlickService
.
updated index.js
of the plugin
import { SlickService } from './slick-service';
import { SlickPager } from './slick-pager';
import { SlickWindowResizer } from './slick-window-resizer';
export function configure(aurelia) {
aurelia.globalResources('./slick-pager');
}
export { SlickService, SlickPager, SlickWindowResizer };
I can now call this in WebPack
without issues
import {SlickPager, SlickWindowResizer} from 'aurelia-slickgrid';
@inject(SlickPager, SlickWindowResizer)
export class Test {
constructor(slickPager, slickWindowResizer) {
console.log(slickPager, slickWindowResizer);
}
}
However if I import SlickService
as well, it throws an error
import {SlickPager, SlickWindowResizer, SlickService} from 'aurelia-slickgrid';
@inject(SlickPager, SlickWindowResizer, SlickService)
export class Test {
constructor(slickPager, slickWindowResizer, slickService) {
console.log(slickPager, slickWindowResizer, slickService);
}
}
previous code with SlickService
now throws this error
ERROR [app-router] Error: Error invoking SlickService. Check the inner error for details.
------------------------------------------------
Inner Error:
Message: key/value cannot be null or undefined. Are you trying to inject/register something that doesn't exist with DI?
"resources": ["**/*.html"]
after your"main": "index"
entry. – Clinicjquery
instead ofbootstrap
. I wonder if this is a bug with the aurelia-cli. Have you tried using the plugin in one of the skeleton projects? – Goraud**/*.html
and no differences. @JeremyDanyow I changed the jquery reference and re-published a version and that doesn't fix the issue (also note that it was all working locally). I only triedAurelia-CLI
because I don't know how to loadSASS
inAurelia-Webpack
which my plugin uses – HattenglobalResources()
call, it should only be View/ViewModel pair? Also, does it matter if a js file is named exactly like the plugin name (in my caseaurelia-slickgrid.js
)? – Hattenslick-window-resizer.js
you're exportingSlickWindowResizer
but importingSlickResizer
inslick-service.js
, hence the null or undefined inject error – Cellulitis