I am trying to make the ui-router work for an angular hybrid application. It works when using JIT compilation, but when I try to make it work with AOT and rollup, the rollup step fails with an error mesaage:
'@uirouter/angular-hybrid' is imported by src\app.module.js, but could not be resolved - treating it as an external dependency
I have opened an issue on the github here. The error can be reproduced by downloading the angular-hybrid minimal example and setting up AOT and rollup on this example the way it is described in angular guidelines, as can be seen in the files from this plunker. The import from '@uirouter/angular-hybrid' is impossible for rollup to resolve.
import { UIRouterUpgradeModule } from '@uirouter/angular-hybrid';
Does anybody have some experience trying to make angular-hybrid work in combination with AOT/rollup? Has somebody succeeded in doing so?
UPDATE
I have managed to make the rollup step work by adding a custom plugin to the rollup-config that resolves the angular-hybrid package. But even so, the application fails in runtime while bootstraping angular and asking for UrlService there. The provider for UrlService is not found with the following call (interestingly, the UrlService exists among the registered providers of the injector, but it is impossible to be found using the UrlService token):
var router = injector.get(UrlService);
Here is the adjusted rollup-config, which I am not sure is proper, since the DI does not work. Still the former question, how to make angular-hybrid compatible with rollup remains.
import nodeResolve from "rollup-plugin-node-resolve"
import commonjs from "rollup-plugin-commonjs";
import uglify from "rollup-plugin-uglify";
import progress from "rollup-plugin-progress";
class UIRouterHybridResolver
{
constructor(options)
{
this.options = options;
}
resolveId(id, from)
{
if (id.startsWith("@uirouter/angular-hybrid"))
{
return `${__dirname}/node_modules/@uirouter/angular-hybrid/lib/angular-hybrid.js`;
}
return null;
}
}
const uIRouterHybridResolver = (config) => new UIRouterHybridResolver(config);
export default {
entry: "src/main.js",
dest: "src/build.js", // output a single application bundle
sourceMap: false,
format: "iife",
onwarn: function (warning) {
// Skip certain warnings
// should intercept ... but doesn't in some rollup versions
if (warning.code === "THIS_IS_UNDEFINED") { return; }
// console.warn everything else
console.warn(warning.message);
},
plugins: [
commonjs({
include: [
"node_modules/rxjs/**",
"node_modules/@uirouter/core/**"
]
}),
nodeResolve({ jsnext: true, module: true }),
uIRouterHybridResolver(),
uglify(),
progress({ clearLine: true })
],
globals: { angular: "angular" },
external: ["angular"]
};