flancer32 / mage2_ext_minify
在 Magento 2 中压缩静态 JS/CSS
0.1.2
2017-03-17 08:32 UTC
Requires
This package is auto-updated.
Last update: 2024-09-06 09:34:36 UTC
README
在 Magento 2 中压缩静态 JS/CSS
概述
在 Magento 2 中进行 JS/CSS 压缩存在一些问题 (一, 二, 三, ...).
此扩展使用 matthiasmullie/minify 模块压缩 ./pub/static/**
文件夹中的所有 JS 和 CSS 文件。所有压缩后的文件都保留在原始文件的位置。所有原始文件都通过扩展名 *.not_minified
进行备份。
示例 Magento 2 应用程序(使用默认的 Luma 主题)在压缩前 Google PageSpeed Insights 得分为 60/100 分,页面大小为 2.4 MB,压缩后得分为 69/100 分,页面大小为 1.5 MB (详细信息)。
注意:在 ./pub/static/**
文件夹中的 JS 和 CSS 文件是 ./vendor/**
文件夹中文件的链接,这些文件将作为结果被压缩。只有在您可以重新部署原始文件的情况下使用此模块。
安装
$ composer require flancer32/mage2_ext_minify
$ ./bin/magento setup:upgrade
使用
在压缩前执行静态内容的编译
$ ./bin/magento setup:static-content:deploy
或切换到生产模式
$ ./bin/magento deploy:mode:set production
然后运行压缩
$ ./bin/magento fl32:minify:make
...
File '/var/www/vhosts/sample_mage2_module/work/pub/static/frontend/Magento/luma/en_US/tiny_mce/themes/simple/skins/o2k7/ui.css' is minified.
Total 2266 JS and 225 CSS files are found in './pub/static/' folder.
Total 2266 JS and 225 CSS files are minified.
Don't forget reset permissions for the files.
要撤销压缩
$ ./bin/magento fl32:minify:revert
...
File '/var/www/vhosts/sample_mage2_module/work/pub/static/frontend/Magento/luma/en_US/tiny_mce/themes/simple/skins/o2k7/ui.css' is reverted.
Total 2266 JS and 225 CSS files are found in './pub/static/' folder.
Total 2266 JS and 225 CSS files are reverted.
Don't forget reset permissions for the files.