难以将xstyle作为dojo依赖项加载

Difficulty loading xstyle as a dojo dependency

本文关键字:依赖 加载 dojo 作为 xstyle      更新时间:2023-09-26

我正在尝试使用Dojo创建一个简单的自定义小部件,并希望使用xstyle加载CSS。看看github中的参考资料,它说我可以添加

<script src="dojo/dojo.js" data-dojo-config="async: true, deps:['xstyle/main']"></script>

并完成。问题是,我需要在我的dojo模块下已经有xstyle,并且我不确定在哪里可以获得/安装它?

总之,我有这个:

<script type="text/javascript">
        var dojoConfig = {
                async: true,
                parseOnLoad: true,
                packages: [
                    {
                        name: "app",
                        location: location.pathname.replace(/'/[^/]+$/, "") + "/app"
                    }
                ],
                deps: ['xstyle/main']
            };
</script>
<script type="text/javascript" src="app/js/dojo/dojo.js"></script>

并且正在得到错误Cannot find .../app/js/xstyle/main.js,这是有道理的,因为我没有它,也不知道从哪里得到它

我从网站上下载了dojo安装,其中包括dojo、dijit、dojox和&主题。CDN似乎也没有xstyle。我也尝试过kriszyp的另一种方法:

<script src="xstyle/xstyle.js"></script> <!-- or use the minified xstyle.min.js -->

但无济于事。我相信我会得到一些already definednot defined错误,这取决于我是在dojo声明之前还是之后添加它。

如果你能给我指正确的方向,请告诉我!

因此,在深入研究了这个问题之后,我发现了这篇使用bower安装xstyle的博客文章。在使用bower(bower install xstyle)安装之后,我能够链接到dojo-config:中的xstyle包

var dojoConfig = {
    async: true,
    parseOnLoad: true,
    packages: [
        {
            name: "app",
            location: location.pathname.replace(/'/[^/]+$/, "") + "/app"
        },
        {
            name: "xstyle",
            location: location.pathname.replace(/'/[^/]+$/, "") + "/app/bower_components/xstyle"
        },
   ]
};

这是可行的,并且我能够成功地使用'xstyle/css!./css/checkboxTree.css'将CSS加载到我的小部件中。我不确定这是否是最好的方法,但它有效。