grape-fluid/asset-loader 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

grape-fluid/asset-loader

Composer 安装命令:

composer require grape-fluid/asset-loader

包简介

README 文档

README

PHP from Packagist Build Status Code coverage Licence Downloads this Month Downloads total Latest stable

Asset Loader for your Nette projects

Dependencies

Require Version
PHP >= 5.6
nette/application ^2.4
nette/di ^2.4
Require-dev Version
nette/tester ^2.0
tracy/tracy ^2.4

Quickstart

  1. Install Asset Loader with composer

    composer require grape-fluid/asset-loader
    
  2. Register extension (in neon)

    extensions:
    	assets: Grapesc\GrapeFluid\AssetLoaderExtension
    
  3. Set your public directory (mostly www) (in neon)

    assets:
    	config:
    		wwwDir: %appDir%/../www
    
  4. Set-up your first package (see all options / features below)

    assets:
    	yourPackage:
    		js:
    			# will create file in wwwDir/assets/yourPackage/js/main.js
    			- %appDir%/modules/WebsiteModule/assets/js/main.js
    		css:
    			# will create file in wwwDir/assets/yourPackage/css/styles.css
    			- %appDir%/modules/StyleModule/assets/css/style.css
    			# you can also use external / remote assets
    			- 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.min.css'
    		copy:
    			# will copy all images from folder into wwwDir/assets/yourPackage/copy/
    			- %appDir%/modules/StyleModule/assets/images/*
    
  5. Inject AssetsControl and create component in your BasePresenter

    /** @var \Grapesc\GrapeFluid\AssetsControl\AssetsControl @inject */
    public $assets;
    
    
    protected function createComponentAssets()
    {
    	return $this->assets;
    }
    
  6. Render your assets in template

    {control assets:css}
    {control assets:js}
    

Multiple files

If you have too many files (for ex. scripts) that you want to include in your templates, or just want to copy whole directory (for ex. with images), you can use asterisk * character.

assets:
	yourPackage:
		js:
			- %appDir%/modules/WebsiteModule/assets/js/scripts/*

Custom destination

If you need, for any reason, copy file into public directory with custom name or custom directory, just specify asset as array. You can use & character that will be replaced with public assets directory folder.

assets:
	yourPackage:
		js:
			# [ source, destination ]
			- [ %appDir%/modules/WebsiteModule/assets/js/main.js, &/my/folder/test.js ]

You can also do the same with whole directories:

assets:
	yourPackage:
		js:
			# [ source, destination ]
			- [ %appDir%/modules/StyleModule/assets/images/*, &/images/ ]

Options

Of course, quickstart doesn't do anything special but copy files and use them in your template files. But it's getting more interesting with these options.

Limits

You can limit assets by Nette-like links. By default all defined assets are enabled everywhere. You can combine multiple limits. By using limits Asset Loader will load only assets that matches your limit. You can easily create assets for backend / frontend, but also for sub-frontend modules, etc.

How to limit asset for module?

assets:
	yourPackage:
		limit:
			- ":Module:.*"

How to limit asset for multiple presenters?

assets:
	yourPackage:
		limit:
			- ":Module:Presenter:.*"
			- ":Module:AnotherPresenter:.*"

Limiting by access rights ($user->isAllowed())

assets:
	yourPackage:
		# Will call $user->isAllowed('homepage')
		- ['link' = ':Module:Presenter.*', 'auth' = 'homepage']

Limiting by custom options

Create and define custom service that implements \Grapesc\GrapeFluid\Options\IAssetOptions interface as written below. We are automatically registering these as services sou you don't have to. Inject through constructor in these services also works. Now you are able to handle limits in any way you want. For example enable / disable assets from your back-office.

assets:
	config:
		options:
			# Must implement \Grapesc\GrapeFluid\Options\IAssetOptions
			- \Your\Class\That\Handles\SomeOptions
			- \Your\Class\That\Handles\AnotherOptions
	yourPackage:
		# Will call $class->getOption('inline.enabled') on every service
		- ['link' = ':Module:Presenter.*', 'option' = 'inline.enabled']

Using negation limit

Use ! in front of limit

assets:
	yourPackage:
		limit:
			- "!:Module:Presenter:.*"

Ordering

Sometimes, especially when using modules, it comes handy to sort / order your packages.

Start / End

assets:
	yourPackage:
		order: [start|end]

Before / After

assets:
	yourPackage:
		order:
			[before|after]: anotherPackageName

or

assets:
	yourPackage:
		order:
			type: [before|after]
			position: anotherPackageName

Disabling

assets:
	yourPackage:
		[disable|disabled]: true

Debug

By default Asset Loader operates in production mode, you can override this with following:

assets:
	config:
		debug: true

When debug mode is one, Asset Loader watch files for changes and deploy them automatically. It also works if you add new files into your packages.

Other

Custom asset folder

assets:
	config:
		assetsDir: customDirectoryName

Directory permissions

assets:
	config:
		dirPerm: 0511

grape-fluid/asset-loader 适用场景与选型建议

grape-fluid/asset-loader 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 934 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 11 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「assets」 「grape-fluid」 「fluid-cms」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 grape-fluid/asset-loader 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 grape-fluid/asset-loader 我们能提供哪些服务?
定制开发 / 二次开发

基于 grape-fluid/asset-loader 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 934
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 8
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2017-11-23