-
Ok, easiest solution first.
Use prepend to load all jquery, moment, popper.js (you missed it), bootstrap, and tempusdominus-bootstrap-4. use copyFiles to get all css files.
-
The second easiest solution. The best solution in spirit of open source.
Create a PR to tempusdominus-bootstrap-4, support UMD (AMD, commonjs and globals) instead of rely on global namespace.
- The hard way.
Because the way tempusdominus-bootstrap-4 is wrote, it is executed by browser when loading vendor-bundle, not when you do import 'tempusdominus-bootstrap-4';
To delay the executing to time of importing, edit aurelia.json
, add wrapShim config to requirejs.
"loader": {
"type": "require",
// ...
"config": {
"wrapShim": true
}
}
But this only solves part of your issue, it now complains
Tempus Dominus Bootstrap4's requires moment.js. Moment.js must be included before Tempus Dominus Bootstrap4's JavaScript.
Because as of version 2.10.0, Moment no longer exporting global when require.js is present.
To fight it, manually export moment to global namespace.
In main.js
import environment from './environment';
import 'bootstrap';
import moment from 'moment';
window.moment = moment;
export function configure(aurelia) {
In app.js, (you need to import tempusdominus-bootstrap-4 after main.js to make the global moment available)
import 'tempusdominus-bootstrap-4';
export class App {
In app.html
<template>
<require from="bootstrap/css/bootstrap.css"></require>
<require from="tempusdominus-bootstrap-4/css/tempusdominus-bootstrap-4.css"></require>
</template>
Last but not least, cleanup your aurelia.json deps.
- jquery, moment, popper.js, bootstrap all support AMD, get ride of deps and exports.
- popper.js need some config, because current cli has issue when module name has ‘.js’.
- tempusdominus-bootstrap-4 needs popper.js too.
"jquery",
"moment",
{
"name": "popper.js",
"path": "../node_modules/popper.js/dist/umd",
"main": "popper.js"
},
{
"name": "bootstrap",
"path": "../node_modules/bootstrap/dist",
"main": "js/bootstrap.bundle.js",
"resources": [
"css/bootstrap.css"
]
},
{
"name": "tempusdominus-bootstrap-4",
"path": "../node_modules/tempusdominus-bootstrap-4/build",
"main": "js/tempusdominus-bootstrap-4.js",
"deps": [
"jquery",
"bootstrap",
"popper.js",
"moment"
],
"resources": [
"css/tempusdominus-bootstrap-4.css"
]
}