与Bower一起安装RequireJS Text Plugin

Jie*_*eng 11 configuration requirejs bower

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

Uli*_*Uli 25

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

requirejs.config({
    paths: {
        "text" : "components/requirejs-text/text"
    }
},
Run Code Online (Sandbox Code Playgroud)

并按照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.
    }
);
Run Code Online (Sandbox Code Playgroud)

您也可以在技术上使用插件而不需要requirejs.config中的路径定义,但这可能不是最佳实践:

require(["your_path_to_the_plugin_from_baseurl/without_js_at_the_end!some/textfile"],
    function(yourTextfile) {
    }
);
Run Code Online (Sandbox Code Playgroud)