【发布时间】:2015-07-23 08:23:18
【问题描述】:
我想用 grunt 实现这个目标
目标
- 我的主要目标是在将 index.php 放入生产服务器之前缩小它们。
- 如果我有 1 个
index.html,这很简单,但我没有。 - 相反,我有一个
index.php和其他.php文件。 - 每个
<?php ?>部分都是一个 HTML 代码块。
index.php
<!DOCTYPE html>
<?php include '2015/layouts/ie.php'; ?>
<head>
<?php include '2015/layouts/meta.php'; ?>
<title>Title</title>
<?php include '2015/layouts/link.php'; ?>
<?php include '2015/layouts/style.php'; ?>
<?php include '2015/layouts/ie9.php'; ?>
</head>
<body >
<span id="web">
<?php include '2015/layouts/nav-bar.php'; ?>
<?php include '2015/layouts/welcome-sign.php'; ?>
<?php include '2015/layouts/profile.php'; ?>
<?php include '2015/layouts/skill.php'; ?>
<?php include '2015/layouts/education.php'; ?>
<?php include '2015/layouts/experience.php'; ?>
<?php include '2015/layouts/portfolio.php'; ?>
<?php include '2015/layouts/contact.php'; ?>
<?php include '2015/layouts/script.php'; ?>
</span>
<span id="print" style="display: none;" ><img src="2015/img/image.png" width="90%"></span>
</body>
</html>
最后
我想知道将所有 .php 文件连接到一个 php 文件并缩小它的最有效方法是什么。
我更喜欢使用 grunt 来实现这一点,但如果有人对更好的解决方案有其他建议,请随时向我提出建议。
【问题讨论】:
-
请不要标记我的帖子,他没有使用 grunt。我是。
-
您可以将php输出写入模板并缩小它吗?
-
你介意回答一下教我怎么做吗?
-
你好,你可以像
ob_start(); include 'index.php'; file_put_contents('index.html', ob_get_clean());这样使用php函数ob_start()然后使用index.html来缩小 -
用上面的代码创建 php 文件,然后像grunt-tasks.com/grunt-exec 这样在调用 php 文件的地方添加 exec 任务来创建 index.html 文件
标签: php html optimization gruntjs minify