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

fix(dev): type module and custom sw not working when not using virtual modules #361

Merged
merged 7 commits into from
Aug 31, 2022

Conversation

ARYX01
Copy link
Contributor

@ARYX01 ARYX01 commented Aug 21, 2022

Description

devOptions.type: 'module' now using it for generating inside the registerSW.js

Linked Issues

closes #359

Additional context

The dev-dist folder is unreachable when running dev vite3.

I suggest not creating this folder and instead add the files inside the ws /@vite-plugin-pwa/ like the pwa-entry-point-loaded and point there the registerPath

@netlify
Copy link

netlify bot commented Aug 21, 2022

Deploy Preview for vite-plugin-pwa ready!

Name Link
🔨 Latest commit 8972c14
🔍 Latest deploy log https://app.netlify.com/sites/vite-plugin-pwa/deploys/63049c171df2730009fdc2f1
😎 Deploy Preview https://deploy-preview-361--vite-plugin-pwa.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@userquin
Copy link
Member

@ARYX01 we use pnpmas package manager: please remove the package-lock-json file

@userquin userquin changed the title Vite3 will not work fix(dev): type module and custom sw stop working whn not using virtual modules Aug 21, 2022
@userquin
Copy link
Member

userquin commented Aug 21, 2022

@antfu it is weird, Vite 2 seems to work properly since it is forcing to use a base (by default /): internally the prefix is being removed and so these lines will work:

The same code with Vite 3 will not work, it seems it is not removing one slash: I think it is because the target project is not using the base entry, and so the plugin will force to use the base / , then https://github.com/antfu/vite-plugin-pwa/blob/main/src/plugins/dev.ts#L40 will have 2 slashes, and so the plugin will not resolve that url.

This PR will just remove the / from the constant, I need to check it with Vite 2: https://github.com/antfu/vite-plugin-pwa/pull/361/files#diff-8fa4b52909f895e8cda060d2035234e0a42ca2c7d3f8f8de1b35a056537bf199R11.

@userquin userquin changed the title fix(dev): type module and custom sw stop working whn not using virtual modules fix(dev): type module and custom sw stop working when not using virtual modules Aug 21, 2022
@userquin
Copy link
Member

userquin commented Aug 23, 2022

I will change the transformIndexHtml hook on dev.ts to include directly the HMR ping/pong content to the script adding a small timeout before the ping, and so we dont need to deal with the base.

EDIT: previous will not work, since we need the module to be processed by Vite.

@@ -37,7 +38,12 @@ export function DevPlugin(ctx: PWAPluginContext): Plugin {

return html.replace(
'</body>',
`<script type="module" src="${options.base}${DEV_SW_VIRTUAL}"></script></body>`,
`
<script type="module">
Copy link
Member

@userquin userquin Aug 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antfu should we check CORS here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could leave it for now, and bring it back if there is really a valid case.

@userquin userquin requested a review from antfu August 23, 2022 09:16
@userquin userquin changed the title fix(dev): type module and custom sw stop working when not using virtual modules fix(dev): type module and custom sw not working when not using virtual modules Aug 23, 2022
@ARYX01
Copy link
Contributor Author

ARYX01 commented Aug 25, 2022

After adding an reload prompt component that uses import { useRegisterSW } from 'virtual:pwa-register/svelte' and setting pwaOptions registerType: 'prompt', the /dev-dist/registerSW.js is not created anymore.
So before was working only with injectRegister: 'inluine', but now it works also with injectRegister: 'script'.

@userquin
Copy link
Member

we only need to fix the SSR: #364

@antfu antfu merged commit 75d044f into vite-pwa:main Aug 31, 2022
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

Successfully merging this pull request may close these issues.

registerSW.js 404s in dev mode with injectManifest strategy
3 participants