-
Notifications
You must be signed in to change notification settings - Fork 188
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
Resolve main
field as array for Bower
#4
Conversation
main
entry as array for Bower
main
entry as array for Bowermain
field as array for Bower
@@ -53,6 +53,9 @@ DirectoryDescriptionFilePlugin.prototype.apply = function(resolver) { | |||
mainModules.push(content[field]); | |||
continue; | |||
} | |||
if (Array.isArray(content[field])) { | |||
mainModules.push(content[field]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mainModules
is a string array and you push an array to it.
mainModules = mainModules.concat(content[field]);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. Should it not work as it is?
In #3 we check if it's better to not add this behavior to the core, but extract it into a |
This is a small change which
So I don't get it -- why the need for |
The spec says that all files in the Example: https://github.com/danialfarid/angular-file-upload-bower/blob/master/bower.json do really require both files from the main field. |
I don't think the example you referenced makes sense. From the README file: <script src="/bower_components/angular/angular-file-upload-shim.js"></script>
<!--only needed if you support upload progress/abort or non HTML5 FormData browsers.-->
<!-- NOTE: angular.file-upload-shim.js MUST BE PLACED BEFORE angular.js-->
<script src="/bower_components/angular/angular.js"></script>
<script src="/bower_components/angular/angular-file-upload.js"></script> The Futhermore, what if all JS files referenced in // a.js
define([], function() {
return function A() {};
});
// b.js
define([], function() {
return function B() {};
}); Or in ES6: // a.js
export default function A() {};
// b.js
export default function B() {}; In these cases how would webpack resolve the bundle? |
Hey, what's the state of this? I really need this for my bower components to work. |
Because the specs for Bower are not finished yet, For example, main array style might be deprecated, and some WebPack config related features might be added, making a |
DirectoryDescriptionFilePlugin.js cannot parse a the "main" field if it is an array of paths. "main": [
"./dist/jquery.countdown.js",
"./dist/jquery.countdown.min.js"
], While technically not correct according to the bower.js specs, it doesn't stop people from doing that. |
+1 for merging this. I'm not using bower but a custom "plugin" definition which states css/js/... files to load. For this it would be very handy to have the array check in place. |
You can do this: new webpack.ResolverPlugin(
new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin("bower.json", ["main", ["main", 0]])
) |
Thanks @sokra. I think I misunderstood what
I'm having a hard time finding documentation for this, do you have a hint? |
That's not possible by resolving. Resolving means it finds one file for a given request. For your use case you need a loader that generates a artificial module which You can combine it with a plugin to resolve it correctly. That's similar to what the component-webpack-plugin does. |
Awesome, thank you @sokra |
n.b. Webpack will not parse the `main` entry of Bower modules when it is set to an Array: webpack/enhanced-resolve#4 Signed-off-by: Alex Coles <alex@alexbcoles.com>
Why is this still open since november last year? |
@MrJH I don't know but I got away with using this: https://github.com/lpiepiora/bower-webpack-plugin |
@swemaniac i'll give it a try next week, thx |
I tried new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin("bower.json", ["main", ["main", 0]]) and new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin("bower.json", ["main"]) but can't solve the problem. https://github.com/lpiepiora/bower-webpack-plugin help a lot, thx! |
Fixes #3 and webpack/webpack#143