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

Cannot get the plugin to load the sw.js file inside dist folder #84

Open
titanve opened this issue Aug 26, 2018 · 1 comment
Open

Cannot get the plugin to load the sw.js file inside dist folder #84

titanve opened this issue Aug 26, 2018 · 1 comment

Comments

@titanve
Copy link

titanve commented Aug 26, 2018

Hello everyone!

Can you please help me telling me what is the difference between entry: " ..." and filename: " ..."
?

I've been trying since yesterday to config the plugin but it's been impossible.

My sw_cached_pages.js is in the same folder of the index.js and webpack puts the bundles inside /distfolder

What is the right config in order to load my service worker file and get the serviceWorkerOption variable?

My folder structure is:
+- /spa
--> |- /dist
--> --> |- 1.bundle.js
--> --> |- bundle.js
--> --> |- sw.js <--- 'Generated by the plugin with the bundles list'
--> |- index.js
--> |- webpack.config.js
--> |- sw_cached_pages.js

My plugin config:

new ServiceWorkerWebpackPlugin({
      // entry: path.join(__dirname, "/sw.js"),
      entry: "sw_cached_pages.js",
      // entry: "sw.js",
      filename: "sw_cached_pages.js",
      // excludes: ["**/.*", "**/*.map", "*.html"]
      excludes: ["**/.*", "**/*.map", "*.html"],
      publicPath: "/application/single_pages/visitas/"
    })

Thank you in advance!

@Arseniy-II
Copy link

Hello @titanve!
entry: "./pass/to/your/sw/on/project/befor/compilation" - it is where webpack will try to find your file. in Your case it should be entry: path.join(__dirname, 'sw_cached_pages.js') (don't forget to const path = require('path'))

filename: 'name-of-the-file-after-webpack-compilation' - after webpack compilation it create file wit name you presented here.

You can check my answer on stack overflow for mor explanation on how to register sw.js correctly. :)

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

No branches or pull requests

2 participants