Does r.js optimizer look at how javascript file is required from html when concatenating?

StackOverflow https://stackoverflow.com/questions/22857616

  •  27-06-2023
  •  | 
  •  

Domanda

I'm trying to concatenate a 'common' library javascripts, and exlude those common files when concatenating individual apps.
(Idea presented here: http://tech.pro/blog/1639/using-rjs-to-optimize-your-requirejs-project)


I have an html file which has

<script>

require("common"), function() {
  require(["some_app"], function(SomeApp) {
  });
});

</script>

SomeApp.js depends on some library files

define(['jquery', 'backbone'], function($, Backbone) {
..
return SomeApp;
});

common.js include library files

define(['jquery', 'backbone'], function() {});

my build.js for r.js optimizer looks like

{
  name: "SomeApp"
  exclude: ['common']  // intent: do not include common library files
}

When I run the optimizer, 'common' is indeed excluded from the concatenated SomeApp.js!
The result is exactly what I want, but I'm perplexed because r.js seems to inspect the html which requires javascript files.

Is it true? What's going on here?

È stato utile?

Soluzione

The result is exactly what I want, but I'm perplexed because r.js seems to inspect the html which requires javascript files.

r.js does not inspect HTML files. The result you describe getting is consistent with r.js operating purely on the JavaScript files and the build configuration you describe in your question.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top