Skip to content
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

How to split minified file into "my code" part and "libraries" part #798

Closed
gcaini opened this issue Mar 24, 2015 · 1 comment
Closed

How to split minified file into "my code" part and "libraries" part #798

gcaini opened this issue Mar 24, 2015 · 1 comment

Comments

@gcaini
Copy link

gcaini commented Mar 24, 2015

Hello,

My project uses r.js to convert a set of .js files to a single combined file for distribution. I'd like to produce two files instead - one for all of my code, and one for all third party libraries.

Here is the relevant part of my current r.js config:

{
    modules: [
        {
            name: 'my_minified_code',
            include: [ 'almond', 'my_code' ],
            exclude: [ 'lib1', 'lib2', 'lib3/a', 'lib3/b', 'lib3/c', 'lib3/d', 'lib3/e', 'lib3/f', 'lib3/g', 'lib3/h' ]
        },
        {
            name: 'minified_libs',
            include: [ 'my_code' ],
            exclude: [ 'my_minified_code' ]
        },
    ]
}

Here my_minified_code.js and minified_libs.js are empty files I created for the build process. (If there is a simpler way of achieving this, I'd like to know it.)

The problem with the above setup is that lib3 has dozens of modules, with no "master" module that requires all the others, so I need ot list each of its modules in the "exclude" array. When I update the library, I need to remember to update this list, or parts of the library will end up in the wrong place.

One obvious way to fix this is by filtering by directory - e.g. exclude: [ /^lib3// ]. But the closest I found to that in the docs is fileExclusionRegExp, which seems to do something else entirely.

@gcaini gcaini changed the title How to split combined minified file into "my code" part and "libraries" part How to split minified file into "my code" part and "libraries" part Mar 24, 2015
@rjgotten
Copy link

rjgotten commented Jun 21, 2016

Build the other way around; first the libs, then exclude the libs from your own code. The optimizer will transitively exclude all the modules that make up the libs.

E.g.

{
  modules : [{
    name    : 'minified_libs',
    include : [ 'lib1', 'lib2', 'lib3' ]
  }, {
    name    : 'my_minified_code',
    include : [ 'almond', 'my_code' ],
    exclude : [ 'minified_libs' ]
  }]
}

@jrburke jrburke closed this as completed Aug 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants