cundd/assetic
Composer 安装命令:
composer require cundd/assetic
包简介
Assetic for TYPO3 CMS
README 文档
README
Integrate the Assetic asset management framework into your TYPO3 CMS installation.
Installation
composer require cundd/assetic- Load the Site Set into the TYPO3 Site
- Configure the assets you want to be loaded
- Include the plugin the
page.headerData// Example: page.headerData.40001 =< plugin.tx_assetic
Usage
Basic
# File: config/sites/my-site/settings.yaml or EXT:site_package/Configuration/Sets/Site/settings.yaml assetic: stylesheets: - file: EXT:site_package/Resources/Private/Stylesheets/main.css
Multiple assets
# File: config/sites/my-site/settings.yaml or EXT:site_package/Configuration/Sets/Site/settings.yaml assetic: stylesheets: - file: EXT:site_package/Resources/Private/Stylesheets/reset.css - file: EXT:site_package/Resources/Private/Stylesheets/style.css
With SASS
If your web server and web user are configured to be able to use the sass command line tool, from within your TYPO3 installation, you could use the following:
# File: config/sites/my-site/settings.yaml or EXT:site_package/Configuration/Sets/Site/settings.yaml assetic: stylesheets: - file: EXT:site_package/Resources/Private/Stylesheets/main.scss
With other CSS preprocessors
Analog you can use other CSS preprocessors. The Assetic Github Page provides a (incomplete) list of all filters provided by the installed Assetic version.
Development mode
To make sure that the assets are compiled each time the frontend page is refreshed, you can enable the development mode:
plugin.tx_assetic {
development = 1
}
By default Cundd Assetic is configured not to compile files if NO backend user is logged in. To allow file compilation without a logged in backend user you can change the allowDeveloperFeaturesWithoutLogin configuration in Site Settings.
Advanced
Configure a filter
Some filters allow further customization. The Sass filter e.g. provides the method addImportPath which allows you to add another path to look for imported Sass files. Cundd Assetic provides an interface to invoke such functions.
# File: config/sites/my-site/settings.yaml or EXT:site_package/Configuration/Sets/Site/settings.yaml assetic: stylesheets: - file: EXT:site_package/Resources/Private/Stylesheets/main.scss functions: # Add functions that will be called on the filter addImportPath: ProjectPath:/vendor/
If you want to invoke a method multiple times you can just add a numeric prefix to the function name:
# File: config/sites/my-site/settings.yaml or EXT:site_package/Configuration/Sets/Site/settings.yaml assetic: stylesheets: - file: EXT:site_package/Resources/Private/Stylesheets/main.scss functions: # Add a numeric prefix to allow the function to called multiple times 0-addImportPath: ProjectPath:/vendor/ 1-addImportPath: EXT:site_package/Resources/Private/Library/
Development flags
To apply functions only in development mode, entries can be added with key developmentFunctions:
# File: config/sites/my-site/settings.yaml or EXT:site_package/Configuration/Sets/Site/settings.yaml assetic: stylesheets: - file: EXT:site_package/Resources/Private/Stylesheets/main.scss functions: setStyle: compressed developmentFunctions: setStyle: expanded
Configure the filter binary paths
In some cases you may have to specify the path to a CSS preprocessor to match your system's configuration. This can be done through the filterBinaries configuration.
The configuration keys are determined by replacing \ with _ and converting
the string to lowercase:
1. \AsseticAdditions\Filter\DartSassFilter
2. AsseticAdditions_Filter_DartSassFilter
3. asseticadditions_filter_dartsassfilter
# File: config/sites/my-site/settings.yaml or EXT:site_package/Configuration/Sets/Site/settings.yaml assetic: settings: filterBinaries: # Change the path to the filter binaries. I.e. if node.js is installed # into /usr/local/bin/ assetic_filter_lessfilter: /usr/local/bin/node # The binary for filter class \AsseticAdditions\Filter\DartSassFilter asseticadditions_filter_dartsassfilter: /usr/local/bin/sass
Command line
Assetic provides three different CLI commands.
assetic:compile
Compiles the assets and exit.
vendor/bin/typo3 assetic:compile
assetic:watch
Watches for file changes in EXT:client and re-compiles the assets if needed.
vendor/bin/typo3 assetic:watch
assetic:livereload
Starts a LiveReload compatible server that watches for file changes in EXT:client and re-compiles the assets if needed. The necessary JavaScript can be loaded be enabling addJavascript in Site Settings.
vendor/bin/typo3 assetic:livereload
LiveReload
Setup
To start the LiveReload server "Add LiveReload JavaScript" (assetic.settings.livereload.addJavascript) must be enabled in site settings and the PHP library "Ratchet" must be installed. For example as a development dependency:
"require-dev": { "cboden/ratchet": "^0.4.x-dev" }
LiveReload & CSP
To use LiveReload with CSP enabled add wss://your-domain.tld:35729/livereload to connect-src in the site's CSP configuration file (config/sites/your-site/csp.yaml).
See the TYPO3 documentation for further details.
Example
mutations: - mode: "extend" directive: "connect-src" sources: - "wss://your-domain.tld:35729/livereload"
Additional tools
Standalone auto-refresh tool
Cundd Assetic provides a JavaScript tool that checks the CSS and JavaScript assets on the page for changes and automatically reloads them. For more information and usage visit /Resources/Public/JavaScript.
Sponsored by
cundd/assetic 适用场景与选型建议
cundd/assetic 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 332 次下载、GitHub Stars 达 2, 最近一次更新时间为 2022 年 07 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「assets」 「compression」 「minification」 「typo3」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cundd/assetic 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cundd/assetic 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cundd/assetic 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Asset Management for PHP
Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.
Caching and compression for Twig assets (JavaScript and CSS).
PHP client for the Google Closure Compiler API in one file.
PHP Code Minifier is a tool that allows you to minify your PHP code.
Asset Management for PHP
统计信息
- 总下载量: 332
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-04