【问题标题】:Symfony and RequireJS - How to serve static html files?Symfony 和 RequireJS - 如何提供静态 html 文件?
【发布时间】:2015-02-12 17:47:08
【问题描述】:
RequireJS 文本插件 (https://github.com/requirejs/text) 需要带有 .html 扩展名的文件。看来.html的要求不能改了。
我的 html 文件位于我的 Symfony 项目的 web 文件夹中。
在默认配置下,不可能使用 Symfony 提供任何静态 html 文件。
RequireJS 正在对模板发出 GET 请求,但没有返回 html 内容。
是否有任何已知的解决方法?
【问题讨论】:
标签:
html
apache
symfony
requirejs
requirejs-text
【解决方案1】:
最后,我将后端 (Symfony) 与前端完全分开。
现在,我只渲染 symfony base.html.twig(我在所有页面上使用的主要 twig 模板)来导入包含网站所有模板的 requirejs 文件。
模板以纯 html 开发,然后通过使用 Gulp 转换为 .txt。它们都捆绑在 requirejs 的 .js 文件中。
gulp.task('devTemplates', ['cleanDevTemplates'], function () {
gulp.src(srcPaths.devTemplates) // The folder which contains the templates
.pipe(minifyHtml())
.pipe(rename({suffix: '', extname: '.txt'}))
.pipe(gulp.dest(destPaths.devTemplates))
.pipe(notify({ message: 'devTemplates task complete' }));
});