Search code examples
javascriptnode.jsrequirejscommonjs

how is the not operator in the module require working


I was going through an open source editor project, when i encountered this strange require syntax

var editorCss = require("./requirejs/text!./css/editor.css");

can anybody tell me what this line is doing? what is the !. in the require path? is that acting as some parameter being passed into the file that is getting required from?


Solution

  • The exclamation point makes RequireJS use a plugin to perform the load. What comes before the exclamation point is the plugin, and what comes after is what the plugin must load. The require("./requirejs/text!./css/editor.css"); tells RequireJS "load the plugin ./requirejs/text and, using this plugin, load ./css/editor.css.

    This syntax happens to be part of the AMD spec: RequireJS is compliant and so supports it. Other loaders that support AMD may also support it.