Polymer treats relative URLs as relative to main document. Polymer 3 provides a [[importPath]] value for relative URLs. LitElement does not provide this helper. What is the best way to handle relative paths in LitElement using Polymer CLI build process ?
Asked
Active
Viewed 130 times
0
-
If you are using webpack you can use a loader that will do that for you – Pascal L. Aug 31 '19 at 11:39
-
Thank you. I am using polymer cli build command. – MadeInLagny Sep 02 '19 at 18:14
-
2I ended up with ```src="${new URL('relative/file.js', import.meta.url)}``` as the correct syntax for media src relative path. There seems to be some compatibility issues with Edge though... – MadeInLagny Sep 03 '19 at 13:32
1 Answers
0
Polymer needed [[importPath]]
due to using HTML imports.
Lit uses ES6 modules, so you can get the current path with import.meta.url
.
As there is a built in browser mechanism to access the URL Lit doesn't provide its own (which is core design principle of Lit), but there is a way to shim it - throw and catch an Error
and the stack
property will include the current file. I don't recommend it though as the browser versions that support modules but not import.meta
are extremely obscure.

Keith
- 150,284
- 78
- 298
- 434