下面的重命名(s / cldr / cldrjs)会破坏加载功能。
require.config({
paths: {
- cldr: "./bower_components/cldrjs/dist/cldr"
+ cldrjs: "./bower_components/cldrjs/dist/cldr"
}
});
require([
- "cldr",
- "cldr/supplemental"
+ "cldrjs",
+ "cldrjs/supplemental"
], function( Cldr ) {
console.log( "Cldr instance", new Cldr( "en" ) );
}, function() {
安装库。
bower install cldrjs requirejs
你应该得到:
cldrjs /tmp/cldrjs
├── cldrjs#0.3.2 extraneous
└── requirejs#2.1.11 extraneous
打开index.html
(https://gist.github.com/rxaviers/10194312处提供)。 Require.js应该加载Cldr,你的控制台应该记录它的实例,例如:
Cldr instance Object { attributes={...}, locale="en", supplemental=function(), more...}
为什么重命名会破坏它?
为了方便您,我已经放置了两个主要文件(https://gist.github.com/rxaviers/10194312处提供)。只需更改参考即可进行测试。
--- a/index.html
+++ b/index.html
@@ -4,7 +4,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<body>
- <script data-main="main.cldr.js" src="bower_components/requirejs/require.js"></script>
+ <script data-main="main.cldrjs.js" src="bower_components/requirejs/require.js"></script>
</body>
</html>
值得了解的信息......
cldr.js的标题:(可在https://gist.github.com/rxaviers/10194312获得)
define(function() {
// implementation... Yeap, no dependencies.
})
cldr / supplemental.js的标题:(可在https://gist.github.com/rxaviers/10194312获得)
define(["../cldr"], function() {
// implementation... Dependency is the above cldr.js file.
})
答案 0 :(得分:0)
https://github.com/jrburke/requirejs/issues/1084#issuecomment-40112805
我在IRC上与@jrburke聊过,他指出
`../ cldr'首先相对于'补充'作为ID解析,最后在ID中以'cldr'结束,然后转换为路径 但由于该路径已用于名为'cldrjs'的模块,这是一个问题,因此在其中找不到'cldr'模块 在我设置项目之后更多 但我认为最终的结果是你要使用地图或包装配置
解决方案:
一般的经验法则是:如果包只包含一个JS模块,那么路径配置就足够了。如果它包含多个模块(如本例所示),则包配置通常更合适 除非包管理器知道前端模块
谢谢@jrburke