itsahappymedium/fec
Composer 安装命令:
composer require itsahappymedium/fec
包简介
A PHP Command Line tool that makes it easy to compile, concat, and minify front-end Javascript and CSS/SCSS dependencies.
README 文档
README
A PHP Command Line tool that makes it easy to compile, concat, and minify front-end Javascript and CSS/SCSS dependencies.
The minify and scssphp packages do all of the heavy lifting, this tool simply combines the two into a single CLI tool with some extra features.
Installation
To a package (local)
composer require-dev itsahappymedium/fec
./vendor/bin/fec help
To your system (global)
composer global require itsahappymedium/fec
fec help
Usage
Running FEC without any arguments will load files from a fec.json file that is structured like so:
{
"compile": {
"css": {
"build/main.min.css": "scss/main.scss",
"build/vendor.min.css": [
"gpm_modules/kazzkiq/balloon.css/src/balloon.scss",
"scss/vendor/*.scss"
]
},
"js": {
"build/main.min.js": "js/*.js",
"build/vendor.min.js": [
"gpm_modules/kraaden/autocomplete/autocomplete.js",
"js/vendor/*.js"
]
}
}
}
Options
File paths can be passed to FEC to compile those specific files.
-
--css--output/-c- Define the path to a single file to concat all CSS/SCSS files into one file, or define a path to a directory to process each file individually with the.min.cssextension. -
--js--output/-j- Define the path to a single file to concat all JS files into one file, or define a path to a directory to process each file individually with the.min.jsextension. -
--no-minify/-n- Don't do any minification, just concat files. -
--path/-p- Defines a path to either a JSON file, or a directory where afec.jsonfile is located. -
--remove-important-comments/-r- Remove all comments, including those that are marked as important. This option also accepts a file name, or the last part of it's file path to only remove important comments from that file. You can also prepend the file name with a!to remove important comments from all files but that file. You can pass multiple files by separating them with a comma (,). -
--scss-import-path/-s- Define an additional path to check for SCSS imports in. You can pass multiple paths by separating them with a comma (,). -
--watcher/-w- Define a path to point the EventSource to that will be injected into your JavaScript so that the page is refreshed when files are updated while running thewatchcommand. (Seewatchcommand section below for more information)
Examples
fec --js-output build/main.min.js js/*.js
fec --css-output build/main.min.css --js-output build/main.min.js scss/*.scss js/*.js
The watch command
Starts a process that watches for file changes and recompiles them as needed. This command will do an initial compile just to make sure everything is up to date.
The Watcher
FEC has the ability to automatically refresh your website while running the watch command (much like how Browsersync works). Simply create a watcher.php (or whatever you want to call it) somewhere that is accessible by your website, and place the following code in there:
<?php require_once('./vendor/autoload.php'); new FEC_Watcher(array( 'build/main.min.js' => 'build/main.min.css' ), 'content/themes/my-theme'); ?>
The FEC_Watcher class accepts two parameters:
-
$files(String/Array) - Should be passed the path to a JavaScript file that FEC will generate or anArrayof JavaScript files. These files will have JavaScript injected into them by FEC to listen for changes. The array can also be multidimensional using the JavaScript file as the keys and additional files to watch for updates as the value (which accepts aStringor anArrayof Strings). -
$path(String) - All paths used in the$filesparameter should be relative to where the watcher script is placed. You can define a path with this parameter to prepend to all files listed in the$filesparameter.
Last, but not least, you will need to set the --watcher option to the path where the watcher script is accessible on the server.
If a watcher is used, your files will be recompiled one last time after you are done to remove the injected JavaScript.
Defining Settings with JSON
You can set most options above by defining them as settings in your JSON file like so:
{
"compile": {
"css": {
"build/main.min.css": "scss/main.scss"
}
},
"settings": {
"fec": {
"compress": true,
"remove-important-comments": true,
"scss-import-path": "gpm_modules",
"watcher": "/watcher.php"
}
}
}
The scss-import-path setting accepts a string or an array of strings, these paths are relative to the location of the JSON file.
Related
- GPM - A PHP Command Line tool that makes it easy to download dependencies from GitHub.
License
MIT. See the license.md file for more info.
itsahappymedium/fec 适用场景与选型建议
itsahappymedium/fec 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.37k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 09 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「javascript」 「cli」 「css」 「JS」 「scss」 「minify」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 itsahappymedium/fec 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 itsahappymedium/fec 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 itsahappymedium/fec 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Generates a Blade directive exporting all of your named Laravel routes. Also provides a nice route() helper function in JavaScript.
A Twig extension to insert css as inline styles with a tag
Caching and compression for Twig assets (JavaScript and CSS).
A pretty nice way to expose your translation messages to your JavaScript.
PHP client for the Google Closure Compiler API in one file.
Yii2 integration for AirBnB Polyglot.js
统计信息
- 总下载量: 1.37k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-09-15