Require vs import?

Hi,

When should you use the html <require from="..."> vs the javascript import?
For example, css files seem to work from both.

Thanks

I think if you want to extract CSS you need to import it from js. When you require from html Aurelia loader still looks for it in the bundle

Should also note that viewResources is the view model’s functional equivalent of <require from="...">

import { viewResources } from 'aurelia-framework';

@viewResources(
   './css/some-styles.css',
   './components/some-aurelia-component'
)
export class SomeVM {}

javascript import is for pulling regular js modules/npm packages etc. while <require> and viewResources(...) are for pulling in html/css/aurelia-components

2 Likes