Home > OS >  Initialize requirejs config.paths with relative path
Initialize requirejs config.paths with relative path

Time:01-31

I want to implement some feature to my project. This feature is taken from sample-app in github repo. The way it works is i just using theirs css and js file and uploaded to jsdeliver so i get the cdn instead of static css and js file in my project.

The thing is this github repo is using requirejs.I realize that i need to manually insert the main.js that include the require.js config because it include the paths like this:

paths: {
jquery: 'lib/jquery-3.3.1.min',
dateFns: 'lib/date_fns',
history: 'lib/history.min'
}

to change it like this :

paths: {
jquery: "https://cdn.jsdelivr.net/gh/qiscus/qiscus-chat-sdk-js-sample@master/js/lib/jquery-3.3.1.min.js",
dateFns: "https://cdn.jsdelivr.net/gh/qiscus/qiscus-chat-sdk-js-sample@master/js/lib/date_fns.js",
history: "https://cdn.jsdelivr.net/gh/qiscus/qiscus-chat-sdk-js-sample@master/js/lib/history.min.js"
}

so when it call define['dateFns'], it calls the cdn instead the relative path. but there is some line that using relative paths in define like define['page/login'] etc. and i cant add something like

paths: {
...
page/login: 'some cdn'
}

to the config. So the question, is there is a way i can manage to use relative paths in the requirejs-config?. So i dont need to manually included it in my script

CodePudding user response:

You can quote the keys:

paths: {
...
'page/login': 'some cdn'
}
  • Related