4

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>

只要'debug' => true启用了config/app.php(在开发环境中),我就可以选择不合并我的资产。

我知道如果我在单独的脚本标签中将资产添加到我的布局中,我可以让十月 CMS 单独提供我的资产。但这也将分别为他们提供生产服务。例子:

<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 中创建一个插件,它会根据配置设置(调试真/假)将资产注入布局。但据我所知,从插件中注入资产,需要将资产放在插件目录而不是主题目录中。

4

2 回答 2

1

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

其他解决方案需要.env在 OctoberCMS 的根目录中创建文件。默认情况下,此文件位于 .env 中,.gitignore因此您可以在生产和开发中使用不同的 .env 文件(文档片段

该文件的内容应为:

APP_ENV=dev

然后您可以访问树枝中的变量:

{% 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 %}
于 2016-03-19T09:26:44.183 回答
0

尝试在您的配置文件(app/config/cms.php)中关闭它

/*
|--------------------------------------------------------------------------
| Determines if the asset minifcation is enabled.
|--------------------------------------------------------------------------
|
| If the minifcation is enabled, combined assets are compressed (minified).
| It is recommended to disable the minification during the development, and
| enable it in the production mode.
|
*/

'enableAssetMinify' => true,
于 2016-04-09T11:39:46.227 回答