Add option to optimize a single folder #112

Open
millermedeiros opened this Issue Feb 21, 2012 · 4 comments

Comments

Projects
None yet
4 participants
@millermedeiros
Member

millermedeiros commented Feb 21, 2012

Some files may not make sense to be deployed (unit tests, test pages, build scripts, etc...)

maybe a new config option or changing the way the optimizer defines the location of the JS files and baseUrl would be enough.

right now the way to do it is setting the same value for appDir and baseUrl.

moved from jrburke/requirejs#94

@jrburke

This comment has been minimized.

Show comment Hide comment
@jrburke

jrburke Feb 21, 2012

Member

So this is possible today by just setting baseUrl, and not including an 'appDir' config. Just the baseUrl contents and any paths: references are copied to the output area.

I can see where it is not obvious though from the config. In general, the interplay between appDir, baseUrl and doing a single file optimization by using just 'name' at the top level I think is probably not very clear.

Member

jrburke commented Feb 21, 2012

So this is possible today by just setting baseUrl, and not including an 'appDir' config. Just the baseUrl contents and any paths: references are copied to the output area.

I can see where it is not obvious though from the config. In general, the interplay between appDir, baseUrl and doing a single file optimization by using just 'name' at the top level I think is probably not very clear.

@ironsidevsquincy

This comment has been minimized.

Show comment Hide comment
@ironsidevsquincy

ironsidevsquincy Nov 14, 2012

👍 for this, copying the entire baseUrl contents is still an issue, as this could contain third-party libs, with all the associated tests, docs, etc

It seems like we need the flexibility of an whole project build mixed with the specificity of a single-file build

👍 for this, copying the entire baseUrl contents is still an issue, as this could contain third-party libs, with all the associated tests, docs, etc

It seems like we need the flexibility of an whole project build mixed with the specificity of a single-file build

@jrburke

This comment has been minimized.

Show comment Hide comment
@jrburke

jrburke Nov 14, 2012

Member

@ironsidevsquincy I'm not sure I follow the use case, can you give more detail? Looking at this ticket, it is possible to "optimize a directory" by using baseUrl and dir with modules section. I guess I should have closed this ticket a while ago, but let's leave it open in case your use case uncovers something.

Member

jrburke commented Nov 14, 2012

@ironsidevsquincy I'm not sure I follow the use case, can you give more detail? Looking at this ticket, it is possible to "optimize a directory" by using baseUrl and dir with modules section. I guess I should have closed this ticket a while ago, but let's leave it open in case your use case uncovers something.

@k3n

This comment has been minimized.

Show comment Hide comment
@k3n

k3n Feb 20, 2014

Even though this ticket is pretty old, I'm in a similar situation and I'm curious which way I should go.

Given: a directory with lots of AMD modules, which can be seen as a library of sorts, e.g. there is no entrypoint defined within the directory itself -- it's meant for other places of the app to call. Yet, I'd like to bundle these all up under a single file.

So, even though I've been reading all the docs that I can find for several days, I'm still completely naive about whether this is a "single page" or "whole project".

Today, to get the desired result requires a bit of a hack on my part: I create a stub module in the root of said directory, which simply lists all of the directory's modules as dependencies. I assume r.js looks at and then decides to bundle them all up. This is cumbersome though because anytime I add a new module to the library, I have to go and update this dummy file which serves no other purpose.

From reading here, it sounds like I could leverage the dir and modules options to do the same? That seems even more cumbersome, since not only do I have to add the module itself, I need to manually keep track of its dependencies in a 2nd location, which is basically the problem that I was originally solving with RequireJS.

Question: is there a means to optimize the full directory, without having to enumerate each module in some form? My next hacky step that I was going to try would be to populate the modules option programmatically, recursively iterating through all modules in the directory, and then doing string-parsing & matching to determine if the file is a module and should be included, what dependencies it has to populate the exclude and include, etc.

Surely there is a better way?

k3n commented Feb 20, 2014

Even though this ticket is pretty old, I'm in a similar situation and I'm curious which way I should go.

Given: a directory with lots of AMD modules, which can be seen as a library of sorts, e.g. there is no entrypoint defined within the directory itself -- it's meant for other places of the app to call. Yet, I'd like to bundle these all up under a single file.

So, even though I've been reading all the docs that I can find for several days, I'm still completely naive about whether this is a "single page" or "whole project".

Today, to get the desired result requires a bit of a hack on my part: I create a stub module in the root of said directory, which simply lists all of the directory's modules as dependencies. I assume r.js looks at and then decides to bundle them all up. This is cumbersome though because anytime I add a new module to the library, I have to go and update this dummy file which serves no other purpose.

From reading here, it sounds like I could leverage the dir and modules options to do the same? That seems even more cumbersome, since not only do I have to add the module itself, I need to manually keep track of its dependencies in a 2nd location, which is basically the problem that I was originally solving with RequireJS.

Question: is there a means to optimize the full directory, without having to enumerate each module in some form? My next hacky step that I was going to try would be to populate the modules option programmatically, recursively iterating through all modules in the directory, and then doing string-parsing & matching to determine if the file is a module and should be included, what dependencies it has to populate the exclude and include, etc.

Surely there is a better way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment