简体   繁体   中英

JSPM bundle with relative imports

I'm working on converting an existing app to using JSPM. I really appreciate using paths relative to the baseUrl so I don't have to do this ../../../../vendor/... nonsense but I did like being able to import from ./siblingModule to import from something in the same part of the hierarchy. When trying to use jspm bundle that does currently use relative imports I get

    Error: ENOENT: no such file or directory, open '<project path + baseUrl>\siblingModule.js'
     at Error (native)

Is there a way to configure JSPM to use relative paths for module resolution alongside baseUrl resolution?

Ideally -

  • module/submodule checks for any valid paths entries and then checks baseUrl/module/submodule
  • ./module/submodule checks in currentPath/module/submodule
  • /module/submodule checks in baseUrl/module/submodule

As far as I can tell this isn't ambiguous, though please correct me if I'm wrong.

ps using jspm 0.16.45

The baseUrl is used to resolve paths.

You can configure mapping and paths in config.json , to import from these paths.

But nothing prevents you to use these kind of import: import module from './otherModule/file.js';

If you have a problem using import, it is probably something wrong in your configuration.

See documentation: https://github.com/systemjs/systemjs/blob/master/docs/getting-started.md

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM