前言:近两天研究AMD规范的requirejs,打算在现在进行的项目中试应用。但用r.js压缩时,CDN路径解析有问题。所以来请各位大大明示。
文档简要结构:
index.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script src="js/require.js"></script>
<script>
require(['js/common'],function(){
alert("test");
})
</script>
</body>
</html>
common.js:
require.config({
baseUrl: "/js",
paths: {
"jquery": "http://localhost:8464/static/Scripts/jquery-1.11.3.min"
}
});
build.js
({
baseUrl: "/js",
dir: "/js-build",
optimize: "uglify",
optimizeCss: "standard.keepLines",
mainConfigFile: "common.js",
removeCombined: true,
})
控制台:
问题:在用node r.js -o build.js
进行压缩时,文件路径会将CDN地址解析成本地子地址。可否在压缩时,模块的地址保持CDN地址?我的配置是否有误?
注:IDE:WebStorm。由于这是做测试的,所以required.config比较简单。
这么写你的
build.js
:当运行
r.js
处理你的项目时,该CDN
路径就被忽略了.让后你的代码里就仍然保留了对CDN
网络地址的引用