-
-
Notifications
You must be signed in to change notification settings - Fork 133
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
feat(build): add support for external modules #814
Conversation
Now you can inject stubs for modules that are only available at runtime and avoid `File not found or not accessible` console logs via `aurelia.json` or cli task. Closes #802
This is the code I've done to solve my issue. It's pretty minimal but allow hooks for modules in two ways. {
"name": "cli-test",
"build": {
"loader": {
"externalModules": {
"my-awesome-module": ["infrastructure/service1", "other"]
} The second one is more powerful because can intercept the requested module and inject dynamic content. To do this you have to edit the function fixModule(defaultRead, id, filePath) {
if (/* some custom logic */) {
return `
define([${/* some dynamic dependency */}], function() {});
`;
}
}
function readProjectConfiguration() {
project.build.loader.externalModules["other"] = fixModule;
return buildCLI.src(project);
} If the provided function returns a falsy value the normal workflow is done, otherwise is used as content. |
great work! |
@DarkHarlock can you please provide another PR to document this as well? |
@Alexander-Taran Yes, I can provide it in the next future. I only need to know where. |
Just found this feature when I am cleaning up #862. This is currently not supported by auto-tracing, but would not be too troublesome to add. Before working on it, I want to ask few questions to clarify my understanding. For feature1,
Why not just define
For feature2, a build-time callback for inject a module, may I know what's your use case for this? If you want runtime behaviour depending on your build env, you could add more flag to @JeroenVinke mentioned electron in #802. I don't know electron much, what's the related use case there? The reason I ask the above questions, is that dynamic injection of modules makes source code very tightly coupled with cli bundler, which I personally feel should be avoid. For example, if one wants to test the source code without using bundler, I mean using tape + babel-register to directly test in nodejs env for logic layer (not ui layer), we cannot because those missing "import" would not work. |
This feature was basically developed to avoid the "File not found" error in the console when a module is imported but not available on filesystem. This happen when you have to require a module that is only available at runtime. The solution you provide:
is not feasible because:
|
Just some other infos:
|
Thx! I kind of get some idea what you are doing. Will contact you on gitter for more details. |
FYI, after discussion with @DarkHarlock, we are going to change the implementation for supporting external package in auto-tracing. Since the current feature is undocumented, we are not going to call it breaking change :-) Instead of using aurelia.json, it's going to be a flexible optional API on Usage in function writeBundles() {
return buildCLI.dest({
onRequiringModule: function(moduleId) {
//...
}
});
}
|
Now you can inject stubs for modules that are only available at runtime and avoid
File not found or not accessible
console logs viaaurelia.json
or cli task.Closes #802