aozisik / grunt-cache-buster
本包的最新版本(dev-master)没有提供许可证信息。
一个与Grunt协作进行缓存破坏的Laravel 4包。
dev-master
2015-04-29 13:41 UTC
Requires
- php: >=5.4.0
- illuminate/support: 4.2.*
This package is auto-updated.
Last update: 2024-09-10 13:49:02 UTC
README
这是一个简单的Laravel 4框架和Grunt任务管理器的缓存破坏器。此包依赖于grunt-cachebuster npm模块(felthy/grunt-cachebuster)。在安装npm模块和此包后,您只需添加一个服务提供者并配置Gruntfile.js。**无需修改.htaccess或NGINX配置**。
配置Grunt
首先将以下模块添加到您的package.json,并运行npm
"grunt-cachebuster": "^0.1.5"
将此添加到您的grunt.initConfig
cachebuster: {
build: {
options: {
basedir: 'public/',
format: 'php',
banner:
'/**\n' +
' * GENERATED FILE, DO NOT EDIT. This file is simply a collection of generated hashes for static assets in \n' +
' * the project. It is generated by grunt, see Gruntfile.js for details.\n' +
' */'
},
src: ['public/**/*'],
dest: 'app/config/cachebuster.php'
}
}
然后加载npm任务并在需要的地方注册它
grunt.loadNpmTasks('grunt-cachebuster');
//..
//..
grunt.registerTask('buster', ['cachebuster']);
确保缓存破坏任务在所有其他任务之后运行。它默认会在您的app/config目录中生成一个文件。此包依赖于此配置文件以正常工作。在正确设置好一切后,运行grunt并确保它正确生成了"cachebuster.php"文件。
配置Laravel
通过在您的L4项目中添加以下依赖项来安装此包
"aozisik/grunt-cache-buster": "dev-master"
安装后,您需要在app/config/app.php中添加以下服务提供者
'Aozisik\GruntCacheBuster\GruntCacheBusterServiceProvider'
然后您可以在需要缓存破坏资产的任何地方使用以下代码代替默认的asset()
辅助函数
CacheBusted::asset('js/resultsCtrl.js')
上面的代码,代替默认的asset辅助函数,将生成以下URL
http://demo.app/js/resultsCtrl.js?v=23d85993f132d67754489e47f66cf6ac
享受吧!
如果您有任何问题或要报告的错误,请随时联系我...