Closed jamesg1 closed 2 years ago
Bundler doesn't bundle d.ts file. It could be some .ts file importing "services/*". Can you share a mini repo to demo the issue?
This code is set globally with requireJS modules on the page separately
Sounds like you want bundler to ignore this module. Check doc section: "1. ignore certain moduleId at bundling time, supply it at runtime"
https://aurelia.io/docs/cli/cli-bundler/advanced#onrequiringmodule
The old bundler 0.x doesn't do auto tracing. It was not a full featured bundler, it didn't trace a module unless you explicitly add the module to aurelia.json dependencies.
Cli v1+ (including v2 and v3) does auto tracing (like webpack and parcel), but you can explicitly ignore some module (or perform other tricks).
This code is set globally with requireJS modules on the page separately
Sounds like you want bundler to ignore this module. Check doc section: "1. ignore certain moduleId at bundling time, supply it at runtime"
https://aurelia.io/docs/cli/cli-bundler/advanced#onrequiringmodule
Thanks, Yeah I managed to find that page after some digging too and it's exactly what I need. 🎉
I managed to make the moduleId get checked against the d.ts
file. Working well :)
function checkIfContainsSync(str) {
const filename = '../../node_modules/package-example/dist/example-bundle.d.ts';
const contents = readFileSync(filename, 'utf-8');
const result = contents.includes(`module '${str}'`);
return result;
}
function writeBundles() {
return buildCLI.dest({
onRequiringModule: function(moduleId) {
return !(checkIfContainsSync(moduleId));
}
});
}
I'm submitting a bug report
Please tell us about your environment:
Operating System: OSX
Node Version: 16.14.0
NPM Version: 8.3.1
Browser: all
Language: 4.6.4
Loader/bundler: RequireJS
Current behavior:
Hi I have some aurelia code which is defined in another package (as a plugin which is bundled into one file) and I have some custom typescript code to generate some types for consumer apps.
Example example.d.ts which is imported as a custom type into my consumer aurelia app.
This code is set globally with requireJS modules on the page separately so I don’t need to include it in my app bundle.
How can I exclude these errors from occuring when bundling?
“services” is not an npm package rather a custom ts module. TS passes ok and the code is working when deployed.
What is the expected behavior?
I was using an old cli 0.28.0/0.35.0 which didn't have this
What is the motivation / use case for changing the behavior? Would like to have the option to exclude certain
packageName
from PackageAnalyzer / Bundler so the cli works like it did in old versions.Ref - https://discourse.aurelia.io/t/excluding-packageanalyzer-and-bundling-of-external-lib/4901