-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Import scripts in Service Worker #2714
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
@@ -48,6 +48,10 @@ function getServedPath(appPackageJson) { | |||
return ensureSlash(servedUrl, true); | |||
} | |||
|
|||
const sWPrecacheImportScript = fs.existsSync(resolveApp('public/service-worker-import.js')) | |||
? 'service-worker-import.js' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We generally use camelCase
convention for filenames.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an abbreviation and as such I thought sWPrecacheImportScript
should be fine. Are you suggesting sWprecacheImportScript
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
He's suggesting serviceWorkerImport.js
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build script is creating a service-worker.js
file - that's why I decided to use service-worker-import.js
.
I guess there is such naming convention for files which are served from public directory.
Unlike the testsSetup.js
which is located in src
dir, this one should be placed in public
and is just copied over as it is into build
by build script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a blocking issue/preventing further review?
I'd prefer if the import script would be located in the |
What's the reason that this is not getting implemented? Would be convenient to be able to customize service worker without ejecting. |
Hi! Any news about it? Thanks! |
Hi all! Please, any info on this? |
Hello! I'm a bot that helps facilitate testing pull requests. Your pull request (commit c566e73) has been released on npm for testing purposes. npm i [email protected]
# or
yarn add [email protected]
# or
create-react-app [email protected] folder/ Note that the package has not been reviewed or vetted by the maintainers. Only install it at your own risk! Thanks for your contribution! |
When I run it with [email protected] and then
|
Hmm, it seems Sorry @uniquename, but this released cut won't work -- I can look into fixing this for future cuts. |
Hi! Is there any chance this would get implemented? Or should I just eject |
We had a similar problem while working on a project recently and we didn't want to "eject". Instead, we created a little tool that allows you to append custom service worker code to the one generated by CRA. It's not an ideal solution but worked well for us. Have a look here: https://github.com/bbhlondon/cra-append-sw |
Any news?, i dont want to eject |
@Eder87rh try out our tool that @tszarzynski mentioned above (https://github.com/bbhlondon/cra-append-sw) - this PR has been open almost 4 months now and it's an easy way to avoid ejecting if that's your only reason to do it. |
Would be cool to have this feature! btw https://github.com/bbhlondon/cra-append-sw rains with errors for me |
It might be possible, that there is not much going on here, because workbox will replace swprecache sooner or later #2340 (comment) |
@jamland could you post an issue please? Sorry it didn't work for you, we built it as we were using it on a project ourselves |
@marcelkornblum sure I will! |
Can we get this merged? I'm in dire need :) |
Any updates? |
I have no idea why this is still pending. |
can we custom sw code in cra without ejecting now? |
Closing in favor of #4169 which will make the service worker fully configurable. |
This PR adds an ability to use
importScripts
option ofSWPrecacheWebpackPlugin
.How-to:
public/service-worker-import.js
npm run build
File is being imported only on service worker install/ update.
Downsides:
Fixes: #2253