Search code examples
javascriptrequirejsamd

RequireJS require.toUrl('../') does not work as I expect


I have my file structure following:

  • modules/
    • test_module/
      • js/
        • main.js
      • view/
        • view.html

In requireJs configuration I define my test_module.

require.config({
  baseUrl: "./",
  packages: [
    {
      name: 'test_module',
      location: 'modules/test_module/js'
    }
  ]

});

And later i load test_module like:

require(['test_module']);

The problem is when I try to get url of my view.html from main.js module using require.toUrl('../view/view.html'), it returns './view/view.html', but if I try like this require.toUrl('./view/view.html') it returns result as expected './modules/test_module/js/view/view.html'

I created plunker to demonstrate problem I am facing link here.


Solution

  • I figured it out.

    Don't know if it is the best solution, but require.toUrl('./) + '../view/view.html' worked fine for me.