我正在尝试使用 Laravel 和 Vue.js 构建具有离线支持的 PWA。我正在使用 laravel-mix-workbox 插件来设置我的服务工作者,但是我在尝试完成应该是一项简单的任务时遇到了很多麻烦。我有一些从我的应用程序中提供的静态资产(图像、XML 文件等),我无法让工作箱将它们添加到预缓存文件列表中。
我尝试将资产移动到 /resources/img 并添加对 copyDirectory 的调用以尝试将它们包含在内,此外,我尝试了 webpack-copy-plugin,但只包含编译后的资产(js、css、字体等)。这是我的 webpack.mix.js 文件:
const mix = require('laravel-mix');
//mp035 add workbox plugin and copy-webpack-plugin
require('laravel-mix-workbox');
const CopyPlugin = require('copy-webpack-plugin');
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
//mp035 fix issue with laravel-mix outputting bad urls in precache manifest for app.js (//js/app.js) and app.css
// and copy assets into place (so they are in the build tree)
mix.webpackConfig({
output: {
publicPath: ''
},
plugins: [
new CopyPlugin([
{ from: 'resources/img/*', to: 'public/img', flatten:true },
{ from: 'resources/root/*', to: 'public', flatten:true },
]),
],
})
.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css')
.sourceMaps().version()
// mp035 add inject manifest plugin to inject workbox manifest into the service worker.
.injectManifest({
swSrc: './resources/pwa/service-worker.js',
maximumFileSizeToCacheInBytes: 20000000, // ******************************DEBUG ONLY!!!
});
有谁知道如何将我的/resources/img(或/public/img)中的所有文件包含在预缓存文件列表中?