我一直在尝试使用Workbox在我的React 16项目中实现缓存。由于页面仍以offline
模式呈现,因此似乎正在缓存某些内容。但是我似乎无法弄清楚,为什么我的缓存版本在元素上不包含任何className。
我已经通过Webpack通过以下代码块实现了Workbox:
new workboxPlugin({
globDirectory: 'build/client',
globPatterns: ['**/*.{html,js,css,png,jpeg}'],
swDest: './build/client/sw.js',
}),
这可能是什么原因?即使也应该缓存图像,也不会加载图像。
编辑:
It seems like the .js
files are not being loaded. The main
& vendor
.js
files contain the content required to assign classNames.
As you can see, the .js
files can't be found. This is in a preload
, but removing them just transfers the error to the <script />
including the files. Also the location of the service worker registration doesn't seem to matter.
Side note: My classnames are generated by using import styles from './index.scss'
=>
<div className={styles.container} />
It seems like my SSR (server.webpack.config
) failed on the CSS loading. I had to modify my server config to match the client config regarding the css
loader.
Because I didn't have this at first, it would read the scss
files as a normal txt
files, which he couldn't recognize, and therefor couldn't use the styles.container
method.
放置适当的scss
文件加载程序可以解决此问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句