我正在尝试将离线的第一个功能调整到我的laravel 5.4 app.verything工作正常,直到我需要更具体地缓存我的刀片文件我有一个包含通配符的URL的问题。我尝试了几种方法,但没有任何作用/这是我的webpack.mix.js函数触发sw-precache插件
mix.webpackConfig({
plugins: [
new SWPrecacheWebpackPlugin({
cacheId: 'pwa',
filename: 'service-worker.js',
staticFileGlobs: ['public/**/*.{css,eot,svg,ttf,woff,woff2,js,html}'],
minify: true,
stripPrefix: 'public/',
handleFetch: true,
staticFileGlobsIgnorePatterns: [/\.map$/, /mix-manifest\.json$/, /manifest\.json$/, /service-worker\.js$/],
dynamicUrlToDependencies: {
'/'.{slug}.'/projects' : 'resources/views/userProfile.blade.php'
},
navigateFallback: '/',
runtimeCaching: [
{
urlPattern: /^https:\/\/fonts\.googleapis\.com\//,
handler: 'cacheFirst'
},
{
urlPattern: /^https:\/\/www\.thecocktaildb\.com\/images\/media\/drink\/(\w+)\.jpg/,
handler: 'cacheFirst'
}
],
// importScripts: ['./js/push_message.js']
})
]
});
使用此代码,当我运行npm run production
时,它给了我一个意外令牌的语法错误。
我尝试像这个'/{slug}/projects' : 'resources/views/userProfile.blade.php'
一样内联,并且当我执行npm
时没有给我任何错误但是当我在浏览器上测试它时它会制动URL。有谁知道如何使这项工作?任何答案都非常感谢。
你应该使用正则表达式
'/\.*/projects' : 'resources/views/userProfile.blade.php',
PS:你得到一个错误,因为Laravel mix不知道'slug'(应该是一个变量),而laravel mix是js文件你必须使用+作为连接运算符。