我正在尝试使离线优先功能适应我的laravel 5.4 app.everything,直到我需要缓存我的刀片文件,更具体地说,我在使用包含通配符的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时,它给出了一个意外令牌的语法错误。
我试着像这样做内联,当我执行npm时,它没有给我错误,但当我在浏览器上测试它时,它停止了'/{slug}/projects' : 'resources/views/userProfile.blade.php'。有没有人知道怎么做?任何答案都是非常感谢的。
发布于 2019-04-28 18:11:47
为此,您应该使用正则表达式
'/\.*/projects' : 'resources/views/userProfile.blade.php',PS:你得到一个错误,因为Laravel mix不知道‘slug’(应该是一个变量),而laravel mix是js文件,你必须使用+作为连接运算符。
https://stackoverflow.com/questions/49933073
复制相似问题