RobLoach / component-installer

Install Web Components through Composer
https://asset-packagist.org/
Other
280 stars 35 forks source link

"component-baseurl" + CDN URL flexible #41

Open renanbr opened 11 years ago

renanbr commented 11 years ago

nice project @RobLoach,

I didn't found a way to make "component-baseurl" flexible to works on developer machine, staging machines and production at my company. When deployment is running, static files are sent to some CDN servers. CDN hosts change according environment (dev, staging, production). So... baseurl should change as well.

I do not want to change composer.json (or any file else) before run composer install.

RobLoach commented 11 years ago

Interesting idea. Could you use a relative URL from the docroot?

renanbr commented 11 years ago

That's my problem, I can't use relative. Let me try make it readable, my scenario is something like this:

I don't know how to solve it for now... but i'm doing some work on it.

renanbr commented 11 years ago

I have an idea... actually RequireJs is useless (for me), try to make it run isnt easy and I dont see a good solution for now. It would be perfect (for me) if component-installer through processors provides some these files in component root directory:

Users can handle baseurl, It's application responsibility (see first note). component-installer can and should provide a simple way to use only libraries specified in require section (see second note).

It's related to #19, but I think we could implement processors that do the job (js and .css root files).

First note: In my case, when developers write an application, they don't release an application to run in a specific machine, they release a application that require some configuration from environment , for example: application url and CDN url. IMO, it's not a good idea to expose those configurations through application files (composer.json included).

Second note: If an user wants RequireJs, he/she should declare it in composer.json file. For this moment the current component-installer implementation uses RequireJs and I cant use root files, because it's asking me for something I don't have: baseurl.

@RobLoach, what do you think about it?

RobLoach commented 11 years ago

Definitely interesting. Might be something that an additional script might solve, not quite sure how to solve it here. I created the other issue to allow all.js building, which would be nice. What do you think?

renanbr commented 11 years ago

It's a nice solution and It solves my case. :smile: You may keep this issue open if anyone is interested to configure CDN URLs for require.js

till commented 11 years ago

/foo is all you need for the baseUrl. Because if the require.js is loaded from a cdn, it will find all other files on the cdn url as well. At least that would solve your staging and prod URLs. Not sure about the dev — maybe use app.local instead of localhost/app.

RobLoach commented 10 years ago

Maybe have a .composerrc file that would allow overriding the component-baseurl on an environment-basis?

dev/.composerrc

{
    "config": {
        "component-baseurl": "localhost"
    }
}

prod/.composerrc

{
    "config": {
        "component-baseurl": "mywebsite.com"
    }
}