Here is what I came up with last week when I did some playing around with v1 loading custom elements from other modules in a yarn workspace.
It sounds like you’ve already worked out that the aurelia webpack plugin cannot load your components via conventions when they are outside the app root. It took me far too long to grasp this
.
In my example app, the page component is in @timfish/module and it loads the html and scss like this:
import { inlineView, customElement } from 'aurelia-framework';
import html from './page.html';
import './page.scss';
@customElement('page')
@inlineView(html)
export class Page {
public something: string = 'Loaded from Module!';
}
The build for the @timfish/module simply builds the TypeScript and copies the html/scss files to the output directory too. With the right declarations, TypeScript doesn’t complain about the html and scss imports
.
When you want to use the page component in the app, <require from="..."> in html does not work. You have to either load it via globalResources or load it manually using the viewResources decorator:
import { viewResources } from 'aurelia-framework';
import { Page } from '@timfish/module';
@viewResources(Page)
export class App {
}
With a few keys bit in the webpack config, it’ll resolve your modules symlinked in the root node_modules and finds the html and scss where they are expected too:
resolve: {
extensions: ['.ts', '.js'],
modules: ['src', 'node_modules', '../../node_modules'].map((p) =>
resolve(__dirname, '..', p)
),
symlinks: false,
},