Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better way to use require fallback? #2026

Merged
merged 3 commits into from
Apr 4, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/html-manager/src/libembed-amd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,17 @@ function requireLoader(moduleName: string, moduleVersion: string) {
let failedId = err.requireModules && err.requireModules[0];
if (failedId) {
console.log(`Falling back to unpkg.com for ${moduleName}@${moduleVersion}`);
return requirePromise([moduleNameToCDNUrl(moduleName, moduleVersion)]);
let require = (window as any).requirejs;
if (require === undefined) {
throw new Error("Requirejs is needed, please ensure it is loaded on the page.");
}
require.config({
paths: {
moduleName: moduleNameToCDNUrl(moduleName, moduleVersion)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will add a key 'moduleName', I think you need to do sth like

            let config = {paths: {}}
            config.paths[moduleName] = moduleNameToCDNUrl(moduleName, moduleVersion)

You should be able to put [] around moduleName, but the resulting js was without that, so I wouldn't rely on that.

}
});

return requirePromise([`${moduleName}`]);
}
});
}
Expand Down