ModuleLoader.js 675 B

1234567891011121314151617181920212223242526
  1. /**
  2. * ModuleLoader.js
  3. *
  4. * @author realor
  5. */
  6. class ModuleLoader {
  7. static load(path) {
  8. let fullPath
  9. if (path.startsWith('http:') || path.startsWith('https:')) {
  10. fullPath = path
  11. } else {
  12. let pathname = window.location.pathname
  13. let index = pathname.lastIndexOf('/')
  14. let basePath = pathname.substring(0, index) //+ '/js/'
  15. if (path.indexOf('/js/') == -1) {
  16. fullPath = basePath + '/js/' + path
  17. } else {
  18. fullPath = basePath + path
  19. }
  20. }
  21. return import(fullPath)
  22. }
  23. }
  24. export { ModuleLoader }