In RequireJs, how can I instruct the optimizer to create hash file names?

I run an optimizer like this

sudo /usr/local/bin/node /tmp/rj/r.js -o name=main out=test.js baseUrl=. 

for the test
Now, how can I tell the optimizer to output the file name as a hash of the content (obviously to set max expires) and then rename the dependency to the appropriate call requests?

An example situation would be something like this

 require({ baseUrl: '{{ STATIC_URL }}js', paths: { jquery: 'https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min', jqueryui: 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min' } }, ['order!jquery','order!jqueryui','order!main']); 

requirejs should pull something like 13KUJAW78M.js

Based on the Miller Medeiross Proposal I plan to put all the required calls into one main file. It also means that all such calls must also be optimized.

eg

 switch(document.location.pathName){ case '/foo': require(['sections/foo/main']); break; case '/foo/bar': require(['sections/foo/main', 'core/bar']); break; default: require('sections/home'); } 

required (['sections / foo / main']);

must be optimized for the hash of the file.

Can anyone help?

+7
source share
1 answer

The RequireJS optimizer does not have this option, but you can rename files and use configs config to set an alias for renamed files, see this thread for more information.

In your example, for example, if you rename files to: sections /foo/main.123QWERT.js', 'sections / home.4567ASDFG.js',' core / bar.0284ZXCV.js', you could just add the path configuration in the following way:

 require.config({ paths : { //alias to new files without JS extension 'core/bar': 'core/bar.0284ZXCV', 'sections/home' : 'sections/home.4567ASDFG', 'sections/foo/main' : 'sections/foo/main.123QWERT' } }); 

The path configuration should be in a file that will not be cached, maybe just save the configuration in HTML.

+4
source

All Articles