what's mean “!” in require.js

落爺英雄遲暮 提交于 2019-12-19 10:28:29

问题


What's mean "!" in require.js when I included module ? What's syntax ? I what includ dinamic stylesheet in my project and I found https://github.com/martinsb/require-css plugin It's works fine .

require(['css!css/sample.css'], function() {
                        alert('Stylesheet has been loaded');
                    }); 

Why ['css!css/sample.css'] include css.js and css/sample.css ?

Edit:

I know alternative :

    define(["controller", "RequireCSS","marionette"], 
 function (Controller, css,  Marionette) {

        css.load("default.css");

RequireCSS.js

define(function () {
    return {
        load: function (url) {
            var link = document.createElement("link");
            link.type = "text/css";
            link.rel = "stylesheet";
            link.href = url;
            document.getElementsByTagName("head")[0].appendChild(link);
        }
    }

});

回答1:


By default requirejs has support for downloading and loading javascript files only. Any other file which need to be downloaded and parsed accordingly is done by means of plugins. These plugins are separate javascript files which know how to download and parse the respected file.

To tell requirejs that any particular file need to be handled by separate plugin and not default loader. It's plugin is appended with ! between plugin name and file path.




回答2:


! means that css plugin will be used to parse sample.css.

Syntax is <plugin-name>!<file-path>.

css.js file contains css plugin's code.

css/sample.css is file, that should be loaded using that plugin.

See https://github.com/millermedeiros/requirejs-plugins



来源:https://stackoverflow.com/questions/40560475/whats-mean-in-require-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!