nodejs如何获取css?

nodejs可以使用text组件获取css。如果依赖添加了 text!前缀它将会被自动加载。text 文件通过异步的方式进行加载(XHR) , 所以你只能获取同域地下的文件。

nodejs中获取css的方法示例:

require(["some/module", "text!some/module.html", "text!some/module.css"],
    function(module, html, css) {        html 变量是some/module.html 文件的文本形式
        css变量是some/module.css 文件的文本形式 
    }
);

注意.html 和.css 后缀规定了文件的类型。路径"some/module"部分将会根据标准模块名进行解析:它将使用baseUrl和paths configuration options进行查找。

对于 HTML/XML/SVG 文件, 有其他的配置选项。你可以传入一个 !strip, 它将去除XML申明,这样外部的 SVG 和 XML 文件就能安全地加载到 document 中,同样的,如果是 HTML,只有 body 标签内部的部分会被返回。例如:

require(["text!some/module.html!strip"],
function(html) { //the html variable will be the text of the
    //some/module.html file, but only the part
    //inside the body tag.
});

以上就是nodejs如何获取css?的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » Node.js答疑