Skip to content

Unable to concatenate all module to single file #1009

Open

Description

@sohandash

Hello,

My project workspace looks like this.

Modules/
|--> Src/
| |--> Application/
| | |--> Application.js
| |--> Home/
| | |--> Home.js
| |--> Utils/
| | |--> Utils.js
|--> Vendors/
| |--> Underscore/
| | |--> Underscore.js
| |--> jQuery/
| | |--> jQuery.js
| |--> Require/
| | |--> require.js
|--> r.js

I am trying to minify all above files and concatenate them to a single file (main.min.js), like shown below.

(function(){ define('underscore', [], (){ /* Content */ }); define('Home', [], (){ /* Content */ }); define('Utils', [], (){ /* Content */ }); define('Application', [], (){ /* Content */ }); }());

I tried with r.js to achieve this, but didn't work out for me.

Can someone please explain whether this can be achieved by r.js or not ?

Thanks

Activity

  1. prantlf commented on Apr 23, 2023

    @prantlf

    Yes, it can.

    Use the paths object in require.config to declare aliases like Utils for Utils/Utils.js and the use these aliases in the define statements to specify your dependencies. When you run r.js, these aliases will be used as module names.

    Insert the prefix (function(){ and suffix }()); after running r.js, which will only concatenate the modules. But it doesn't make sense, because the only global identifier, which will be used in the output bundle, will be define from require.js.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions