Yeoman vs UrlRouting [英] Yeoman vs UrlRouting

查看:130
本文介绍了Yeoman vs UrlRouting的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了Yeoman如何为单页web应用程序完美工作,但当我尝试使其适用于简单的php网页时,我很困难。

简单的问题:yeoman通过重命名资产来处理缓存,这很酷。

现在让我们假设你的网页使用UrlRouting,所以像/ news / 12 / Puppies将被重定向到index.php文件。



我们还假设您有一个函数,它将为资产设置正确的绝对url ,根据项目的根:absoluteUrl()。



然后您的标题可以有以下几行:

 <! -  build:css(.tmp)styles / style.css  - > 
< link rel =stylesheethref =<?= absoluteUrl('styles / style1.css')?>>
< link rel =stylesheethref =<?= absoluteUrl('styles / style2.css')?>>
<! - endbuild - >

哪一个当然不适用于yeoman。





我想过的一个解决方案是复制所有相关的html文件,strip absoluteUrl部分,运行这些繁重的任务,然后再添加absoluteUrl回调函数。
但我宁愿不使用这样一种不起眼的技术。

解决方案

自从我发布这个问题后,我有很多与这个问题的时间摔跤。
我为一个解决方案所做的工作是使用一个咕task任务从索引中删除absoluteUrl函数调用,运行资产处理工作任务,然后在一切正常后再将其放回。



它运行良好,但我认为这是有风险的。涉及太多的魔法,很多事情都可能出错。

I see how Yeoman work perfectly for a single-page webapp, but I struggle when I try to make it work for a simple php webpage.

I have a simple problem: yeoman deals with caching, by renaming the assets, which is cool.

Now let's assume, that your webpage is using UrlRouting, so an url like "/news/12/Puppies" would get redirected to the index.php file.

Let's also assume, that you have a function, that will set a correct absolute url to the assets, based on the project root: absoluteUrl().

Your header then could have the following lines:

<!-- build:css(.tmp) styles/style.css -->
    <link rel="stylesheet" href="<?= absoluteUrl('styles/style1.css') ?>">
    <link rel="stylesheet" href="<?= absoluteUrl('styles/style2.css') ?>">
<!-- endbuild -->

Which of course does not work with yeoman.

Is there a way to deal with this issue?

One solution I thought up is to copy all the relevant html files, strip the absoluteUrl part , run the grunt tasks on these, then add the absoluteUrl call back again. But I rather not use such an unelegant technique.

解决方案

Since I posted this question, I had a lot of time wrestling with this question. What I did for a solution is to remove the absoluteUrl function call from the index with a grunt task, running the asset handling yeoman tasks, then place it back after everything is OK.

It worked fine, but I think it's risky. Too much magic involved, a lot of things can go wrong.

这篇关于Yeoman vs UrlRouting的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆