0
votes

I'm trying to minify and concatenate require modules together into one file.

For example, if I have a file called article.js like the following:

define(["jquery","flexslider","share_div"],function(){});

I want all of those dependencies to be combined and minified into one file.

I have the following in my build script, but it's not combining files together, just minifying.

This is my build.js file:

{
    "appDir": "../js",
    "baseUrl": "../js",
    "dir": "../www-build",
    "mainConfigFile": "../js/common.js",

    "modules": [
        {
            "name": "common"
        },
        {
            "name": "page/article",
            "exclude": ["common"]
        }
    ],
    "paths": {
        "jquery": "empty:",
        "jquery_ui": "empty:",
        "twitter_bootstrap": "empty:"
    }
}

My understanding of Require and the build script may be wrong, but I envisioned that files would be concatenated together.

Any guidance would be appreciated.

2
Looking at what you show in your question, it seems to me you should get what you are expecting. For further analysis, showing us the contents of the build.txt file that r.js creates would be useful. (It will be located at the root of the output directory.) - Louis

2 Answers

0
votes

To also minify the nested dependencies of the individual modules that are traced as dependencies, specify this additonal property as part of your build file: findNestedDependencies: true. (See line 318-324 of the full RequireJS doc.)

This is if articles.js is a dependency found in common.js and you are tracing through common.js to build a concatenated and minfied file. I am not sure about the lack of concatenation if you are just trying to build the individual module itself.

0
votes

The build.txt file you've included in a comment (the comment I'm referring to has been deleted by Andy after I wrote my answer) is a bit hard to read since it has not been included as preformatted code. From what I can see in the file you've provided, r.js does indeed concatenate the dependencies of article.js into one file. So it appears that you've solved your original question somehow.

As so why your output is not appearing in the right directory, I can only speculate. The build.js file you've shown in your question is set to put everything in ../www-build, however your build.txt file shows the output being stored in ../js. Here's the speculation part: sometimes when we are in the midst of trying to find solutions, we make changes here and there and lost track of where we were. That certainly happened to me. What I do then is clean my development tree (remove the builds), inspect my build configuration to make sure that what I think is used is indeed used and rerun the build.