Fix asset path for Rails (#268)

The path to assets should be consistent and not depend on the current script source. There are at least two situations when this assumption fails:
- When running `webpacker-dev-server`, the _pack_ URL doesn't contain `/js/` part.
- In test environment, `/packs-test` is used by default.
This commit is contained in:
Vladimir Dementyev
2020-12-12 19:21:36 +03:00
committed by GitHub
parent 248f494865
commit c7da2f24d5

View File

@@ -36,8 +36,13 @@ import { defineCustomElements, setAssetPath } from '@shoelace-style/shoelace'
// ...
const rootUrl = document.currentScript.src.replace(/\/packs.*$/, '')
// Path to the assets folder (should be independent on the current script source path
// to work correctly in different environments)
setAssetPath(rootUrl + '/packs/js/')
// This enables all web components for the current page
setAssetPath(document.currentScript.src)
defineCustomElements()
```