Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
420 views
in Technique[技术] by (71.8m points)

main module not beling called when using RequireJS optimizer

I have an existing angularJS app that uses RequireJS as a module loader. All is working fine but I am trying to use the optimizer and having an issue, the first module is not being called!

this is my main.js

define(['lib/IE/isIE', 'lib/IE/isIE8', 'lib/IE/isIE9', 'lib/IE/isIE11', 'util/array', 'util/string', 'util/object', 'util/date'], function (isIE, isIE8, isIE9, isIE11) {
    ...

    if (isIE) {
        require(['xdomain', 'xhook'], init);
    } else {
        init({ slaves: function () { } });
    }
}

and in the html:

<script data-main="main" data-handle-routes="true" data-html-target="document" src="~/Content/App/lib/requirejs.min.js"></script>

I changed it to (added .min) to use the optimizer:

<script data-main="main.min" data-handle-routes="true" data-html-target="document" src="~/Content/App/lib/requirejs.min.js"></script>

When running the website with the main.min I get the following error:

requirejs.min.js:203 Uncaught Error: No define call for main.min http://requirejs.org/docs/errors.html#nodefine at C (requirejs.min.js:203) at Object.completeLoad (requirejs.min.js:296) at HTMLScriptElement.onScriptLoad (requirejs.min.js:302)

Looking at the main.min.js file I can see that the module has the following definition:

define('main',['lib/IE/isIE', 'lib/IE/isIE8', 'lib/IE/isIE9', 'lib/IE/isIE11', 'util/array', 'util/string', 'util/object', 'util/date'], function (isIE, isIE8, isIE9, isIE11) {
   ...
}

So, the module has the 'main' ID. if I replace manually that ID to 'main.min' the application will run. Any idea how I can change the ID? Is this possible to achieve it by changing the build.js?

question from:https://stackoverflow.com/questions/65884791/main-module-not-beling-called-when-using-requirejs-optimizer

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...