gpt4 book ai didi

javascript - 我正在与 requirejs 优化器和非 AMD 模块作斗争

转载 作者:可可西里 更新时间:2023-11-01 01:45:21 25 4
gpt4 key购买 nike

我正在努力使用 requirejs 优化器。如果我只是将它加载到浏览器中而不进行优化,那么这段代码将起作用。如果我运行优化器,我会得到

: ENOENT, no such file or directory 'C:\Users\dev\checkout\src\main\webapp\resources\scripts\
json2.js'

In module tree: main

这是代码

requirejs.config({
paths : {
jquery : "lib/jquery",
bootstrap : "lib/bootstrap",
modals : "lib/modals",
tablesort : "lib/tablesort",
json2 : "lib/json2"
},

shim : {
"bootstrap" : [ "jquery" ],
"modals" : [ "jquery" ],
"tablesort" : [ "jquery" ],
"json2" : [ "jquery" ]
}
});

require([ "jquery", "json2","bootstrap", "modals", "tablesort", "registermodule", "personsmodule" ], function($) {

要让优化器正常工作需要做什么?我试着把 lib/json2 放在 require 中。然后我遇到 jQuery 问题,因为它不是 AMD 模块。

编辑:仍在为这个问题苦苦挣扎。尝试了最简单的例子。在浏览器中工作正常,但优化器提示找不到文件。 lib/jquery.js 和 lib/modal.js。

requirejs.config({
paths : {
jquery : "lib/jquery",
modals : "lib/modals"
},

shim : {
"bootstrap" : [ "jquery" ],
"modals" : [ "jquery" ]
}
});

require([ "jquery", "modals" ], function($) {

console.log($("#leverandor_span").text());
$("#register_modal").modal("show");

});

最佳答案

参见 mainConfigFile .这已经到位,因此您不必将您的需求配置复制到运行时/优化时间文件中,保持您的构建干燥:

//By default all the configuration for optimization happens from the command
//line or by properties in the config file, and configuration that was
//passed to requirejs as part of the app's runtime "main" JS file is *not*
//considered. However, if you prefer the "main" JS file configuration
//to be read for the build so that you do not have to duplicate the values
//in a separate configuration, set this property to the location of that
//main JS file. The first requirejs({}), require({}), requirejs.config({}),
//or require.config({}) call found in that file will be used.
mainConfigFile: '../some/path/to/main.js',

关于javascript - 我正在与 requirejs 优化器和非 AMD 模块作斗争,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11323414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com