Skip to content
This repository has been archived by the owner on Nov 20, 2019. It is now read-only.

Get publicPath at runtime with file:// #69

Open
amaury1093 opened this issue Apr 16, 2018 · 2 comments
Open

Get publicPath at runtime with file:// #69

amaury1093 opened this issue Apr 16, 2018 · 2 comments
Labels
needmore Need more information
Milestone

Comments

@amaury1093
Copy link

Config 1

My webpack config is

  plugins: [
    new ServiceWorkerWebpackPlugin({
      entry: path.join(__dirname, 'src/sw.js'),
      publicPath: '/'
    }),
  ],

which ouputs a sw.js file in a build/ folder.

I then run Electron, which loads a .html file via the file:// protocol. The bundled js loads file:///sw.js, and I get a network error saying the service worker file cannot be fetched.

Config 2

I change the webpack config to:

  plugins: [
    new ServiceWorkerWebpackPlugin({
      entry: path.join(__dirname, 'src/sw.js'),
      publicPath: path.join(__dirname, 'build/')
    }),
  ],

When I run electron, the bundled js loads file:///Users/amaurymartiny/path/to/build/sw.js, which is correct, and my service worker is loaded.

However this path is hardcoded into the bundled js, since it's done at compile time, so if I package the electron app and run it on another computer, I get another sw file cannot be fetched error.

Question

Is it possible to set the path of sw.js at runtime?

@woutervanvliet
Copy link
Collaborator

Would you be able to setup a repo that reproduces the issue with the least amount of code necessary?

@woutervanvliet woutervanvliet added the needmore Need more information label Apr 19, 2018
@woutervanvliet woutervanvliet added this to the 2.0 (future) milestone Apr 19, 2018
@jeniljain29392
Copy link

I am working on an electron-vue project and I tried to use this plugin but I am facing the same issue. It works in development mode. But for production it throws a network error saying the service worker file cannot be fetched.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needmore Need more information
Projects
None yet
Development

No branches or pull requests

3 participants