1

My require.js config:

require.config({
    paths: {
        css: "../libs/require-css/css",
    },
    map: {
        "*": {
            less: "../libs/require-less/less",
            css: "../libs/require-css/css"
        }
    }
});

I'm trying to include a css file that has "css" in dir name

require([
    "css!bootstrap/../css/bootstrap"
], function(
) {

Gets interpreted as libs/require-css/css/bootstrap.css because css is in the directory name. How would I get require to treat css in the path a literal

2 Answers 2

3

You'll need to change the path you'd like to use.

Instead of:

paths: {
   css: "../libs/require-css/css",
},

use this

paths: {
   require-css: "../libs/require-css/css",
},

Then reference it as

require([
    "require-css!bootstrap/../css/bootstrap"
], function(
) {

The paths just work as a shortcut or alias to the longer location of the file so you can use any value you like for it.

Sign up to request clarification or add additional context in comments.

Comments

0

Any short module name in paths should not exist in a file path.

For example, if path : {css: 'path/to/require/css'}, and

require(['css!css/style.css'],  function () {});

'css' string in style.css's file path will be replaced with the module css's path. so that equals to

require(['css!path/to/require/css/style.css'],  function () {});

To prevent this problem, you can replace css module name with 'require-css' like Denis did

path : {require-css: 'path/to/require/css'};
require(['require-css!css/style.css'],  function () {});

or replace css directory name 'css' with 'style'

path : {css: 'path/to/require/css'};
require(['css!style/style.css'],  function () {});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.