How to handle embedded code with RequireJS optimization

How do I handle inline code when using RequireJS Optimization ?

Along with a bunch of individual JavaScript files that are loaded via RequireJS, I have an object defined in my ASPX file.

<script> define('PageData', function(){ return { target: <%=_target%>, permissions: <%=_permissions%> }; }); </script> 

This object contains page load data and is required for many of my files.

Of course, when I try to use Optimization, he complains because he can not find either the module that is defined as PageData, or a file named PageData.js.

Is there a way to ignore this dependency?

+6
source share
2 answers

Like @PaulGrime's comments, empty: does the trick.

0
source

Got a response from jrburke and it works for me.

https://github.com/jrburke/requirejs/issues/867

Use the empty: paths configuration option in the assembly to complete the optimization:

http://requirejs.org/docs/optimization.html#empty

+3
source

Source: https://habr.com/ru/post/947872/


All Articles