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

Unable to concatenate all module to single file #1009

Open
sohandash opened this issue Jun 27, 2021 · 1 comment
Open

Unable to concatenate all module to single file #1009

sohandash opened this issue Jun 27, 2021 · 1 comment

Comments

@sohandash
Copy link

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

@prantlf
Copy link

prantlf commented Apr 23, 2023

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants