Closed droplab closed 8 years ago
I actually had the same issue and try-ed several things. However reading the code solved it :)
To make a long story short, when you create a bundle with the GSAP library (a core-bundle.js for instance) and then exclude it from the other bundles, alle dependencies of the core-bundle.js will be excluded from those bundles.
The long answer:
JSPM-Builder (which is used under the hood by aurelia-bundler) supports bundle-arithmetics (see: https://www.npmjs.com/package/systemjs-builder#bundle-arithmetic ).
So lets say you have defined an aurelia-core bundle that contains all aurelia dependencies (in my buildtasks/bundle.js
):
bundles: {
"dist/aurelia-core": {
includes: [
'aurelia-bootstrapper',
'aurelia-http-client',
'aurelia-router',
'aurelia-animator-css',
'aurelia-templating-binding',
'aurelia-templating-resources',
'aurelia-templating-router',
'aurelia-loader-default',
'aurelia-history-browser',
'aurelia-logging-console',
'aurelia-validation',
'aurelia-auth',
'github:atsu85/aurelia-bs-modal',
],
options: {
inject: true,
minify: true
}
},
And you have defined an app-build bundle that contains part of your application:
"dist/app-build": {
includes: [
'**/*',
'**/*.html!text',
],
options: {
inject: true,
minify: true
}
}
Using jspm-builder arithmetics you would write this as: `dist/app-build - dist/aurelia-core``
The aurelia bundler does not support this arithmetics. However it actually builds a module expression by concatenating the entries in the includes-array with a +
and subtracts this with all the modules found in the excludes array.
See lines: https://github.com/aurelia/bundler/blob/master/lib/bundler.js#L23-L30
So adding aurelia-core (without the dist/ path) to the excludes of the dist/app-build bundle actually results in previous mentioned bundle arithmetic.
We have some documentation around this here . Please read "Duplicate Modules in Multiple Bundles" section for more details.
Is there a way to prevent library duplication across bundled files? For example, If I'm using TweenMax in more than one bundle the entire GSAP library gets compiled into each bundle. Would be amazing if there were functionality that would allow shared dependent libraries to be broken off into a commons.js bundle.
I realize this would be possible if I explicitly declared exactly what and what is compiled into each bundle but this defeats the whole lovely automagic dependency tree traversal.
Thank you!