configuration - 与 Bower 一起安装的 RequireJS 文本插件

标签 configuration requirejs bower

我应该如何使用requirejs-text哪个是通过 bower 安装的?我应该把它放在baseUrl但想知道我是否可以从 components/requirejs-text/ 使用它?最佳做法是什么?

最佳答案

在配置中定义插件的路径:

requirejs.config({
    paths: {
        "text" : "components/requirejs-text/text"
    }
},

并在您的模块中使用它,如 https://github.com/requirejs/text 中所述:
require(["some/module", "text!some/module.html", "text!some/module.css"],
    function(module, html, css) {
        //the html variable will be the text
        //of the some/module.html file
        //the css variable will be the text
        //of the some/module.css file.
    }
);

您也可以在技术上使用在 requirejs.config 中没有路径定义的插件,但这可能不是最佳实践:
require(["your_path_to_the_plugin_from_baseurl/without_js_at_the_end!some/textfile"],
    function(yourTextfile) {
    }
);

关于configuration - 与 Bower 一起安装的 RequireJS 文本插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16514254/

相关文章:

javascript - 与函数和变量的多重Knockout绑定(bind)

javascript - RequireJS 工作不一致

hadoop - 启动 Apache Spark 集群

java - 从 maven 禁用 hibernate 日志记录

javascript - RequireJS/r.js 'baseURL' 属性看似被忽略

git - 阻塞代理后面的私有(private) bower 。需要什么异常(exception)?

c# - Bower 在 Visual Studio 2015 预览版中不工作

npm - spm.js 中的新功能

javascript - 在 window.onload 中传递默认值?

configuration - 在 PhpStorm 中显示 .gitignore 文件