Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refer asset path inside of javascript file #163

Open
rafaeldev opened this issue Jul 18, 2023 · 1 comment
Open

Refer asset path inside of javascript file #163

rafaeldev opened this issue Jul 18, 2023 · 1 comment

Comments

@rafaeldev
Copy link

I have a servicer worker where I have a list of files to be cached. Previous, I ran using .erb extension to get that, like this:

const CACHE_VERSION = 'v2';
const CACHE_NAME = CACHE_VERSION + ':sw-cache-';

function onInstall(event) {
  console.log('[Serviceworker]', "Installing!", event);

  event.waitUntil(
    caches.open(CACHE_NAME).then(function prefill(cache) {
      return cache.addAll([
        '<%= asset_path "application.js" %>',

        '<%= asset_path "application.css" %>',

        '/offline.html',
      ]);
    })
  );
}

Now I decided to move sw.js to esbuild build flow but I don't know how can I asset application.js file link there.

Thanks!

@risen
Copy link

risen commented Jun 18, 2024

I also would like a way to get the asset_path in javascript.

For example, when I want to use customize the icon library for shoelace.style, I can do this:

registerIconLibrary("default", { resolver: (name) => `https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/icons/${name}.svg` })

… but I can't refer to local assets and do something like:

registerIconLibrary("default", { resolver: (name) => asset_path(`icons/${name}.svg`) })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants