如何合并Zend Framework 2模块公共目录 [英] How to merge Zend Framework 2 module public directories
问题描述
某些zf2模块具有用于分发资源(例如js/css/images)的公共目录.使这些资源可供申请人使用的最佳实践是什么?
Some zf2 modules have public directories for distribution of resources such as js/css/images. What is best practice for making these resouces available to the applicaiton?
我希望它可以通过http://mysite.com/[moduleName]/
自动提供这些资源.例如
I would like it so that these resources were automatically available through http://mysite.com/[moduleName]/
. For example,
root/public/js/sitescript.js
-> http:\\mysite.com\js\sitescript.js
root/module/mymodule/public/js/modulescript.js
-> http:\\mysite.com\mymodule\js\modulescript.js
root/vendor/vendormodule/public/js/vendorscript.js
-> http:\\mysite.com\vendormodule\js\vendorscript.js
是否应将这些资源复制到根目录/公共目录?手动复制会很痛苦,而且我怀疑自动合并目录的构建过程是否也很实用.
Should these resources be copied to the root/public directory? Manual copying will be painful, and I doubt an automated build process to merge the directories would be very practial either.
也许有些魔术可以与httpd.conf或.htaccess一起使用?
Perhaps there is some magic that can be worked with httpd.conf or .htaccess?
也许符号链接是解决方案?但是,符号链接并不能直接在Windows平台上运行,而是需要为每个单独的模块手动创建.
Perhaps symlinks are the solution? But, symlinks are not straight forward to get going on a Windows platform, and would need to be created manually for each individual module.
推荐答案
有4种处理方式:
- 在
public/
目录中符号化资产 - 将资产从模块复制粘贴到
public/
目录 - 使用特定的虚拟主机配置(或通常是网络服务器配置) >
-
使用资产管理器模块,例如以下之一:
- Symlinking assets in the
public/
directory - Copy-pasting assets from the modules to the
public/
directory - Using a particular Virtual Host Configuration (or generally web-server configuration)
Use an asset-manager module, such as one of the following:
- AssetManager -由 asset 支持-在运行时合并资产,具有用于生产环境的缓存,以及用于CSS/JS最小化和LESS/SASS转换的过滤器,允许从模块本身的目录中暴露资产.
- zf2-assetic-module -由 BaconAssetLoader -通过在部署时将资源部署在
public/
目录中来暴露模块中的资产
- AssetManager - backed by assetic - merges assets at runtime, has caching for production environments and filters for CSS/JS minification and LESS/SASS conversion, allows exposing of assets from directories in the modules themselves.
- zf2-assetic-module - backed by assetic - handles CSS/JS minification and LESS/SASS conversion at runtime
- BaconAssetLoader - exposes assets from modules by deploying them in the
public/
dir at deploy time
这篇关于如何合并Zend Framework 2模块公共目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!