How to access class from an aurelia-plugin module


#1

So, I’m trying to create separate npm module which has all the generic components related to an app UI.

To create the module, I cloned the repo: https://github.com/eriklieben/skeleton-plugin-typescript. After that, I merged my stuff to the repo and installed the module in my aurelia app wich ended up fine. The app worked as before (when the source was inside the app) .

Now I’ve a problem.

I’m trying to import a class of the module from the App, but they aren’t available… (it says that the module is undefined)

What do I need to made them available?

Sorry, I’m a newbie in this “node, npm, etc…” stuff -.-’

Thanks in advance!


#2

If I understand well you are trying to import class of the module installed from npm or…?


#3

Let me try to explain my steps and what I want to achieve:

1 - Cloned the repo (which is a aurelia plugin skeleton) and named it like my-ui;

2 - Created some components inside the src folder (‘nav-bar’, ‘panel’, etc…);

3 - Installed that local my-ui package in my aurelia app using the command like:

npm install /home/xyz/my-ui

4 - Configured the package in the aurelia.json file doing:

au install my-ui

5 - In the main.js file of the app added aurelia.use.plugin("my-ui");

I know that those steps worked because the components are included sucessfully in the main app. (like nav-bar, side-bar… etc)

Now, I want to use some other component/class inside one component of the main app like:

/*
welcome.ts
-------------
*/

import {CustomPanel} from 'my-ui';
//(...)

this.panel = new CustomPanel(document.getElementById('foo'));

But I dont know how to make that possible… :S


#4

Try this: https://www.twilio.com/blog/2017/06/writing-a-node-module-in-typescript.html


#5

if you want to import your classes like that then just export them, from your plugin’s index.

// src/index.ts
export { CustomPanel } from './path/to/panel';
export { CoolButton } from './path/to/button';
export * from './utils';
...

#6

I can highly recommend Dwayne’s great skeleton for a typescript based aurelia-plugin. I’ve written 3 plugins in the discourse of the last two weeks and it worked great so far.