gpt4 book ai didi

php - 如何在OctoberCMS中禁用开发时的 Assets 合并

转载 作者:行者123 更新时间:2023-12-01 21:43:59 24 4
gpt4 key购买 nike

October CMS 提供了方便的功能来组合 js/css 资源。在我的 layouts/default.htm 中,我定义了如下脚本:

<script src="{{ [
'assets/javascript/jquery.js',
'assets/vendor/bootstrap/js/transition.js',
'assets/vendor/bootstrap/js/alert.js',
'assets/vendor/bootstrap/js/button.js',
'assets/vendor/bootstrap/js/carousel.js',
'assets/vendor/bootstrap/js/collapse.js',
'assets/vendor/bootstrap/js/dropdown.js',
'assets/vendor/bootstrap/js/modal.js',
'assets/vendor/bootstrap/js/tooltip.js',
'assets/vendor/bootstrap/js/popover.js',
'assets/vendor/bootstrap/js/scrollspy.js',
'assets/vendor/bootstrap/js/tab.js',
'assets/vendor/bootstrap/js/affix.js',
'assets/javascript/app.js',
'@framework',
'@framework.extras'
]|theme }}"></script>
{% scripts %}

config/cms.php 文件中,我有:

'enableAssetCache' => false,
'enableAssetMinify' => null,

并在config/app.php中:

'debug' => true,

这会合并 twig 数组中定义的所有脚本。在渲染的网站上,我得到一个 javascript 文件

<script src="http://localhost/Test/october/combine/2cdc17b704821cd2ffbd9be8e4d340f9-1457016128"></script>

我希望有一个选项,只要在 config/app.php 中启用了 'debug' => true(因此在开发环境)。

我知道,如果我将 Assets 添加到单独的脚本标记中的布局中,则可以让 October CMS 单独提供 Assets 。但这也将在生产上为他们单独服务。示例:

<script src="{{ 'assets/js/one.js'|theme }}"></script>
<script src="{{ 'assets/js/two.js'|theme }}"></script>

我在 github 上发现了这个 1.5 年前的问题,但没有有用的答案: https://github.com/octobercms/october/issues/289

文档也没有提到关于此事的任何有用信息: https://octobercms.com/docs/markup/filter-theme

你知道如何处理这个问题吗?我也许可以在 OctoberCMS 中创建一个插件,它将根据配置设置(调试 true/false)将 Assets 注入(inject)到布局中。但据我所知,从插件内注入(inject) Assets ,需要将 Assets 放在插件目录中,而不是主题目录中。

最佳答案

好吧,我设法解决了这个问题,但没有使用问题中提到的 config/app.php

其他解决方案需要在OctoberCMS的根目录中创建.env文件。该文件默认位于 .gitignore 中,因此您可以在生产和开发中使用不同的 .env 文件 ( Piece of documentation )

该文件的内容应该是:

APP_ENV=dev

然后你可以访问 Twig 中的变量:

{% if this.environment == 'dev' %}
<script src="{{ 'assets/vendor/jquery.min.js'|theme }}"></script>
<script src="{{ 'assets/semantic/dist/semantic.min.js'|theme }}"></script>
<script src="{{ 'assets/javascript/app.js' | theme }}"></script>
{% framework extras %}
{% else %}
<script src="{{ [
'assets/vendor/jquery.js',
'assets/semantic/dist/semantic.js',
'assets/javascript/app.js',
'@framework',
'@framework.extras'
]|theme }}"></script>
{% endif %}

关于php - 如何在OctoberCMS中禁用开发时的 Assets 合并,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35892560/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com