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

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

  •  27-06-2023
  •  | 
  •  

문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top