-
Notifications
You must be signed in to change notification settings - Fork 225
How to make elements reusable through Bower #11
Comments
This is something we've been discussing a lot internally and I still don't think there is a great solution. If an element is going to be registered and shared with bower, then it must assume all dependencies will be siblings. So what my-element is doing here is actually incorrect. The correct path to
Because if I run
This means an element boilerplate needs to have two branches: In the This is an annoying way to work but it's the only way that your element will be installable by bower. Take a look at the Polymer elements, they all follow this same technique. There is another wrinkle to think about... If someone does hardcode a path into their import:
Then you'll have to create a folder in your project called |
Today @robdodson and I tried to put together some solution to fix this. You can check the full prototypes here: The basic idea is:
That way you can still develop on master branch and also have a live demo on gh-pages: http://zenorocha.github.io/x-test/src/demo.html The only thing we need to automate in order to make it easier for people to publish live demos is the |
cc @wibblymat for his take on this approach, but it looks legit. |
@wibblymat pointed out that once you install the element it no longer works because it's in Sounds like we might need a build task instead... |
You also shouldn't change the name of the folder as it should be clear it's the folder Bower uses to store components. |
No idea how to solve this one 😔 I wanted to avoid build steps, but I don't think it's possible... |
Because everyone must assume their element will be installed by bower, we have to use the "canonical path" ( Another alternative is for bower to be cool with git repos and other things being dumped into the or, we move the build step to bower itself. Maybe have a comment string that bower can look for in our
(I realize this is stinky, just throwing out ideas) |
I feel sad about having all those dependencies. Instead of focusing on the element authoring itself, a beginner first needs to install NodeJS, install Grunt and Bower globally, then install local dependencies to fetch Polymer/Platform, then run some Grunt command to handle those paths. For us who run those commands everyday it's not a problem. And I'm not saying that those tools are bad either. They are incredibly useful and important to distribute your element for example. But they are blockers for lots of developers who just wants to open their editors, edit two HTML files, and see the magic happen. Unfortunately using a CDN isn't an option for bunch of reasons:
That's why we end up having no alternative but use Bower + Grunt/Gulp. So let me focus in a solution. I don't think Bower will make such changes [soon], and every single day there are people using this boilerplate to create stuff. They are building their projects on top of something that is not distributable at this current state. I'm not familiar with this grunt-targethtml but it seems like it can be a solution. |
Just changed the issue title since this discussion is more about how to make elements reusable through bower then how to name bower's custom install folder. |
Polymer engineering perspective:
Rob you said
But I can't understand what you refer to and I can't figure it out from the repos you pointed to. Can you be more explicit? No polymer material or elements ever need to twiddle paths, this is the point, it all Just Works (tm). |
What we want to achieve @sjmiles is having a single |
I suggest you do not try to achieve that, and accept that the shape of a shareable package is not the same as the shape of a deployment. What we did is automate constructing a [gh-pages] branch from the [master] branch of my component. A simple shell script does the following:
Which results in a fully functional deployment of my components in 30 seconds or less. :) Note that Step 3 is exactly the easiest way a user can do this too. There are virtues to no trying to make one repository serve all masters. Here is just one: a clean component repo can be installed by downloading or cloning via GIT without relying on Bower |
@sjmiles I'm curious, how do you develop using this workflow. Do you work in master, make changes, run the script, and preview the gh-pages branch? |
Exactly, by using this workflow you would need to create a git tag for every single change you make. |
Locally my component sits in a component folder with all it's other dependencies just sitting there. So my demo files, tests, whatever are totally runnable in place. I can run/edit/test in a tight loop. My working folder is a GIT checkout (this is one reason it's best to be able to have hetergeneous The only time you have to update the Again, in my view, any live page about your component is fundamentally different from your shareable component. It's not hard to imagine a gh-pages deployment for a large component that contains a significant amount of other material, including tutorials, sample applications, and so on. |
Does that look like this:
Or is it more like this:
Or something else entirely? 😄 |
Both cases are But since you asked, I have multiple setups. I have one uber setup with a zillion components in multiple folders that I make look like one folder to the client using apache redirects. Because members of Polymer team often need to push to like ... every repository (somebody counted around 180 at some point) we have more advanced needs here. Most users will not be pushing changes to all the components they use (including numerous polyfills, etc). But, whenever I feel like it, I can spawn a new project folder as in your second example. It's really easy with Bower to populate the Btw, the multiple folders thing is not awesome, and I only do that because last time I checked |
so the simple workflow, if you're using bower, is to develop inside of the |
You gotta disconnect from Bower. Bower is a convenience, but it doesn't drive any of this. The intent of components is to have high granularity and reuse. This is what drives having a components folder. How anything gets into that folder is an orthogonal question. I call my components folder Now, I can also use Bower to bring in packages, which will be damn convenient because it will also bring in dependencies. Bower has to know where to install my components. The default folder is not to my liking, but thankfully, Bower is not cranky like NPM and allows me to control this name. I choose the name The key concept is that the use of Bower is for convenience, it's not driving the bus. |
I probably should have just said yes, sorry for long-windedness. I got stuck because of "if you're using bower", and the answer would be yes even if I wasn't. |
I totally get what you're saying about Bower being a convenience, we've just always told people to not put their things in whatever folder bower is installing to and that's why I focus on it. We've specifically said, that folder is sacred, do not touch. From the bower readme:
If the boilerplate goes this route, it requires reeducation which will meet with confusion and possibly resistance. Something akin to telling Node developers "You can put your stuff in the node_modules folder now." It's that confusion that I'm concerned about, not whether or not it's conceptually ok to do it. I concede that you can probably put whatever you want in FWIW, I'm not trying to stir things up. Just looking for the simplest solution for new developers @wibblymat wdyt? |
I hear you, but in my view, the long term good solution trumps concerns Btw, regarding that bit in the readme, this was the very first thing
Sell to whom? As I've said, my understanding from our last Bower-asks Is there any real virtue to having a restricted folder? As far as I can On Wed, Mar 26, 2014 at 11:11 PM, Rob Dodson notifications@github.comwrote:
|
I'm coming around to @sjmiles world view of not trying to shape the shareable package in the same form as what we intend users to deploy to gh-pages. At the same time, I'm woefully aware that the reason we've seen so many custom elements built off the back of the current element-boilerplate has been ease of forkability and & sharability with minimum tooling and configuration. We need to take care here. We're trying to balance lowering the barrier of entry with enabling users to publish packages which are not going to be easily reusable when installed via Bower, which I think we want to avoid. It lowers the value proposition if I have to go editing paths and re-hooking up dependencies once I've installed a component. Especially so if this needs to be done multiple times. Scott mentioned that the Polymer team construct their gh-pages from master using a shell script. Looking at the dependencies required there, this requires git + Bower. It doesn't seem like a big ask for a developer to run a script and we could probably drop an @sjmiles ooi, could you share your script just for interest sake? I'm curious how much push back there would be from introducing this step and share Rob and Zeno's concerns about increasing the barrier of entry, but it seems like this path might work. |
I think, in the short term, rather than defy the Bower documentation, we should use a grunt task to strip out mention of |
PR over here webcomponents/element-boilerplate#12 |
Could you guys check @robdodson's PR #12? I want see if we're all in the same page before adding this solution to other boilerplates. |
FYI See 737d947 for more info. |
I came across this thread from here FWIW, on X-Tag, I went with Bower and Grunt to ease the pain of dealing with dependencies. For our stub and generator you must run Smush-components crawls through |
Interesting. I'll try to give |
When we stopped to use the CDN and started to use Bower we had this default
bower_components
folder commited (which is now calledlib
).We made this decision because we want people to be able to demonstrate their elements right from the
gh-pages
and debug them easily.However this causes reusability problems. They cannot be shared with Bower and used by other apps.
The text was updated successfully, but these errors were encountered: