One directory level: Working
Assume we have this directory structure:
these modules get bundled into the following file:
The config now looks like this:
System.config({
"package1.js": ["package1/*"]
});
The loader loads the bundle file when accessing package1/module1 or package1/module2.
Deeper directory level: Not working
However, when the package1 directory contains another directory, this does not work:
Bundle:
Config:
System.config({
"package1.js": ["package1/*"]
});
Now, when loading the module package1/directory/module3 it is not loaded from the bundle but loaded from the original location...
Problem
Is there a way to define a wildcard (*) that does also match directories but not only files (/**/* does not work either)?
Yes this is by design in https://github.com/systemjs/systemjs/blob/master/lib/bundles.js#L46. I'm open to considering relaxing the constraint, but there is some risk here as the chances of missing a module that is caught by a bundle config that isn't actually in the bundle start to increase, which will lead to odd bugs.
+1
When you have hammer you can build house, but you can kill man with it, You can't guard people from themselves. All is about structure of app and what you put in bundles. Way not RegExp?
+1 I could use it to load the application modules using
System.config({
bundels: {
聽聽聽 'app-build': [ 'app/**/*']
}
})
+1 I would really like to see that feature, so that i don't have to add every "subfolder" of my libraries by hand.
@guybedford I understand the risk but, IMHO, there should be a way to do it.
I'm not agree with to add glob support, that would increase the size of systemjs.
Perhaps to support a RegExp would be the best choice, for example:
System.config({
bundles: {
'app-build': [
'./vendor',
{ regExp: /^app\/library/ }
]
}
})
But that choice require additional effort when normalize each item in the bundle.
The fastest solution would be accept doble wildcard (**), at the end of string, to include / boundaries, that choice don't affect to the current behavior. Warging: not glob accepted only doble wilcard at the end of string:
System.config({
bundles: {
'app-build': [
'./vendor',
'app/library/**'
]
}
})
I think that implementation is easy, but I do not see myself able to write the tests ... I don't know the project structure and I get lost with so many files.
The implementation should be something like that:
// ...
var curModule = loader.bundles[b][i];
if (curModule == load.name) {
matched = true;
break;
}
if (curModule.endsWith('**')) {
var beginStr = curModule.substring(0, curModule.length - 2);
if (load.name.substring(0, beginStr.length) == beginStr) {
matched = true;
break;
}
} else
// single wildcard in bundles does not include / boundaries
if (curModule.indexOf('*') != -1) {
// ...
What do you think?
Most helpful comment
+1 I could use it to load the application modules using