Comments (16)
The scope
should do exactly what you want, however, I agree that having it as a separate settings might not be always good and that it may introduce some confusing like here. I am going to mark this for v2, but in mean time, this should work:
// webpack.config.js
module.exports = {
output: {
publicPath: '/myApp/'
},
plugins: [
new OfflinePlugin({
scope: '/myApp/'
})
]
};
Also it should support __webpack_public_path__
in future, I think.
from offline-plugin.
Hi @Pajn,
Yes, offline-plugin
does not uses publicPath
option from webpack config, however, it has scope
option which allows to specify scope for both AppCache
and ServiceWorker
. Key difference here is that publicPath
could be an absolute URL prefix, e.g. http://example.com/test/
, but offline-plugin
needs only path part from the URL for the scope
. It of course can use publicPath
in some way, but scope
should work at the moment.
P.S. I do not see publicPath
in your code here https://github.com/Pajn/Culinam/blob/master/webpack.config.js, so you probably can just specify scope
for offline-plugin
. Your scope at the moment is /
, just change it to what ever you want. If this doesn't work for you, then it's really a bug.
P.S.2. Or you mean runtime global variable __webpack_public_path__
?
from offline-plugin.
@Pajn Does it works for you?
from offline-plugin.
It seemed to me that the path it installs from did not update with scope but I will need to check again
from offline-plugin.
Sorry for not getting to this earlier. Scope does work as I wanted, don't know why I dismissed it earlier.
Personally I have no need for publicPath support, just that I misunderstood scope.
Thank you for this great plugin!
from offline-plugin.
@Pajn Great! You are welcome.
Anyway, it seems to be a good idea to support publicPath
. Not so important, but possible.
from offline-plugin.
I have an app that, in different environments/configurations might mount under different URLs. Webpack just builds a folder and I can drop that folder into the root of my webserver, or under /beta/
, or whatever is needed. I'd really like to see support for __webpack_public_path__
because scope
isn't know by webpack at compile time.
from offline-plugin.
@AsaAyers Yes, this will be very useful.
One thing here is that we cannot have dynamic public path for AppCache
, so it will be done then only for ServiceWorker
and only when AppCache
is disabled (for consistency). Probably should be fine to have anyway.
from offline-plugin.
Hmm, might be possible for AppCache
too with this way:
For path /public/path/appcache/manifest.appcache
part /public/path/
will be treated as public path of the app, e.g. in manifest all paths will be generated relatively to it.
from offline-plugin.
I've been looking over the code trying to figure it out and thought "If we didn't have this leading /
it would work". Then I figured out that it's coming from the default context of /
.
This workaround seems to work for me. Now I have a new set of problems to solve that aren't related to this plugin
new OfflinePlugin({
scope: '',
updateStrategy: 'hash',
AppCache: false,
}),
from offline-plugin.
Hey @AsaAyers, I just added relativePaths
options to the plugin. Just pass relativePaths: true
or scope: ''
to the options and plugin will generate relative paths for the files for both ServiceWorker
and AppCache
.
Can you try it with you case? It's not npm yet since I need to be sure first that it works, so you can install with npm install NekR/offline-plugin
.
Thanks!
from offline-plugin.
Okay, so I assume that it's fixed. Feel free to open another issues if it's not.
from offline-plugin.
My webpack setup is generated by /generator-react-webpack-redux
(example output here).
Basically, index.html
is served from /
, and webpack generated assets are served from /assets
.
When I set scope: /assets
, then there's now way to add /
to the cache. When I leave scope at /
or set it to an ampty string, then sw.js
will not be found.
I've tried a lot of different setups but couldn't get it to work. Do you see a way to configure this correctly without supporting publicPath
?
from offline-plugin.
From: http://www.html5rocks.com/en/tutorials/service-worker/introduction/
One subtlety with the register method is the location of the service worker file. You'll notice in this case that the service worker file is at the root of the domain. This means that the service worker's scope will be the entire origin. In other words, this service worker will receive fetch events for everything on this domain. If we register the service worker file at /example/sw.js, then the service worker would only see fetch events for pages whose URL starts with /example/ (i.e. /example/page1/, /example/page2/).
from offline-plugin.
First of all, yes, SW has to be in a root, e.g. /sw.js
to be able to capture /
request (there is other way though, but requires proper server configuration).
@amiuhle what you need, is generate everything relative to your root, e.g. webpack.config.output.path
is your root and webpack.config.output.chunkFilename
should be something like this assets/[name].js
.
With such config, sw.js
will be places directly in your webpack.config.output.path
and assets will be placed in assets/
subfolder.
If this doesn't work for you, then it would be good to see example of your config so I could suggest fixes to it.
Hope this helps :)
from offline-plugin.
@amiuhle Did you solve this issue? It's preventing webpack from even including my assests
from offline-plugin.
Related Issues (20)
- Question - SW caching all assets site-wide HOT 1
- In Angular 9, files inside directories are not being cached
- Ideas for Documentation to Help with Troubleshooting
- Some files missing in cache on SW first load/install HOT 1
- Caching subpath urls
- Caching fails to download assets in Chrome 85 HOT 1
- Issue with default path
- [question] Having Multiple runtime installations
- Problem with Webpack 5.0 HOT 17
- Micro Front-ends structure with single-spa
- Auto update doesn't work
- After removing redux-offline, how do we ensure that client's who have old versions get the latest update?
- `onInstalling` doesn't seem to be called, because `ignoreInstalling` is always true
- offline-plugin does not serve assets from service worker
- Webpack 5 compatibility HOT 3
- The "path" argument must be of type string. Received undefined HOT 4
- Cache Images from AWS S3
- Pass ServiceWorker version to the install events
- Terser Plugin issue while building with webpack-cli HOT 3
- upgrade ejs package | CVE-2022-29078 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from offline-plugin.