componentjs / component

frontend package manager and build tool for modular web applications
https://github.com/componentjs/guide
MIT License
4.55k stars 306 forks source link

Add "standalone" option to component.json #512

Closed netpoetica closed 10 years ago

netpoetica commented 10 years ago

Based on convo at https://github.com/component/component/issues/511#issuecomment-39485156

When doing

component build -s name-of-lib

or

component build --standalone name-of-lib

component builder should look for a property called "standalone": true, which would make it so you don't have to even specify the option, and look to the name of the component as the name of the exported module.

Additionally, we may want to be able to override the name of the standalone build with a property like standaloneName, outputName, umdName, something along those lines. I would picture it a couple of ways:

/* "component build" will run with -s and name the component MyComponent, or if standaloneName is not specified, it will become mycomponent. If the name is dash-seperated, it becomes camelcase to avoid the issue with dashes as variable names.*/
{
     "name": "mycomponent",
     "standalone": true,
     "standaloneName": "MyComponent"
}
/* In this method, because standalone is set to a name, it acts like "true" would and also because it's typeof String, u can use the name to create it */
{
     "name": "mycomponent",
     "standalone": "MyComponent"
}
/* Worst case scenario, you still have to specify -s or --standalone, but if you provide a String to standaline property, it will become the name */
{
     "name": "mycomponent",
     "standalone": "MyComponent"
}
anthonyshort commented 10 years ago

This has come up a few times in the past and I think the idea has been turned down. The reason being that the builder shouldn't store build options within the manifest because it isn't relevant information about the package. It could create weird cases when building with packages that have dependencies with options like these.

jonathanong commented 10 years ago

oh i don't think you need this property when building your own component. --standalone options is fine. for me, it's more for if we had a CDN or something that automated UMD builds.

netpoetica commented 10 years ago

I get the idea that the component.json file, as it is related to the component and not the build process, probably shouldn't have config info for the component-builder, but I think the need for a that type of config exists and should be considered. I imagine that the absence of this configuration is the reason why we see people putting Makefiles in their repos a lot. I think there should be a more convenient way to manage building considering the frequency with which it is done during development.

Additionally, I think it's a steep enough learning curve to get on board with the philosophy of component let alone ask devs to use Make - I think 1 out of 4 or 5 front-end devs (maybe grim outlook) actually know/understand/have seen Makfiles, it will probably intimidate some

anthonyshort commented 10 years ago

I'd be open to trying it out. But I still think it messes with concerns a bit too much. It could be nice for "boot" components. Maybe open a pull request instead.

@visionmedia and @ianstormtaylor are going to hate this though :)

{
   "builder": {
      "standalone": "myapp"
      ...
   }
}
jonathanong commented 10 years ago

we could also use a .rc file or something, but then we end up with more files... might be useful to specify the installation directory and stuff in the .rc file instead though. supporting --out in every command would be pretty annoying.

jonathanong commented 10 years ago

i'm going to add standalone to the docs, but only for automated standalone builds. for local builds, let's discuss this in https://github.com/component/component/issues/517