配置SW-precache webpac插件:它可以在Url中使用吗?

时间:2018-03-05 15:35:54

标签: laravel-5 service-worker progressive-web-apps

现在,在我们的网络应用中,我们的路线是这样的:

Route::get('/{storeName}','HomeController@mainPage');

使用商店的名称,我们使用不同的模板加载商店的信息,具体取决于商店的特色。我们有几个视图,选择要在控制器中加载的视图:

  class HomeController extends Controller
    {
       public function mainPage($storeName)
      {
       (..... Calls to the DB and other things........)
       return view('homePage/'.$store->template,[store-data])
      }
   }

我们一直在考虑迁移到Progressive Web App,并且我一直在研究服务工作者的预防措施。我想知道如何在dynamicUrlToDependencies中做类似的事情。

到目前为止,据我所知,它通过传递url,然后是视图,这是:

module.exports.plugins.push(
    new SWPrecacheWebpackPlugin({
        cacheId: 'pwa',
        filename: 'service-worker.js',
        staticFileGlobs: ['public/**/*.{css,eot,svg,ttf,woff,woff2,js,html}'],
        minify: true,
        stripPrefix: 'public/',
        handleFetch: true,
        dynamicUrlToDependencies: {
            '/': ['resources/views/landing/landing.blade.php'],
            '/planes': ['resources/views/landing/new-precios.blade.php'],
            '/registro': ['resources/views/landing/registro.blade.php'],
            '/politicas-privacidad': ['resources/views/landing/politicas.blade.php'],
            '/articles': ['resources/views/articles.blade.php']
        },
        staticFileGlobsIgnorePatterns: [/\.map$/, /mix-manifest\.json$/, /manifest\.json$/, /service-worker\.js$/],
        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']
    })
);

如何在dynamicToUrlDependencies中添加类似/ {$ storeName}的内容?我可以调用一个视图文件夹,例如[' resources / views / homePagesTemplates / *。blade.php']?它甚至可能吗?

1 个答案:

答案 0 :(得分:0)

我不知道直接的方法,但我希望这会有所帮助..

1- php artisan make:view 你可以得到这个package,它可以制作视图并抓取视图。

此外,它还包括扩展其他模板,这些模板将为您准备好各种商店。

来自您的控制器的2-运行工匠您可以通过多种方式完成此操作,我只需复制粘贴Laravel代码reference

Route::get('/foo', function () {
$exitCode = Artisan::call('email:send', [
    'user' => 1, '--queue' => 'default'
]);

//
});

所以在控制器中将两者结合在一起:

$store1View = \Artisan::call('make:view'['name' => 'store1Variation', '--extends' => 'stores.store1']);