grails asset-pipeline

介绍

Grails Asset-Pipeline插件用于在Grails应用中管理和处理静态事物,功能包括处理和压缩CSS和JavaScript文件,还支持编译自定义事物,如CoffeeScript或LESS。

配置

1.压缩

Property Value Default
grails.assets.minifyJs trueorfalse true
grails.assets.minifyCss trueorfalse true
grails.assets.enableSourceMaps trueorfalse true
grails.assets.minifyOptions Map (see below)
grails.assets.skipNonDigests trueorfalse true

grails.assets.minifyOptions = [
    languageMode: 'ES5',targetLanguage: 'ES5',//Can go from ES6 to ES5 for those bleeding edgers
    optimizationLevel: 'SIMPLE' //Or ADVANCED or WHITESPACE_ONLY
]

2.Asset Taglib URLs

在很多情况下,可以是要修改包含静态文件的URL,在使用CDN或Nginx时,这特别有用。

grails.assets.url = "http://cdn.example.com/"
命令行

1.asset-clean

清空预编译assets保存的目录(target/assets)

2.asset-compile

编译应用的assets

3.asset-precompile

预编译应用的assets

assetResourceLoacator

这个bean实现了ResourceLocator接口,并且增加一个方法,入参是一个asset的URI,出参是Resource实例。

class ExampleService {
  def assetResourceLocator
  def someMethod() {
    Resource testCssResource = assetResourceLocator.findAssetForURI('test.css')
  }
}
tags

1.assetPath

<link href="${assetPath(src: 'manifest.json')}"/>

属性

(1)src

必需属性,grails-app/assets的路径。

(2)absolute

非必需属性,如果设置为true,返回绝对路径

2.assetPathExistis

如果指定路径 存在asset,这个tag的body会被渲染。

<asset:assetPathExists src="foo/test.js">
This will only be displayed if there is an asset at foo/test.js
</asset:assetPathExists>

3.deferredScripts

标志<asset:script>块需要渲染。

4.img

<asset:image src="example/foo.png" absolute="true"/>

属性

(1)src

必需属性图片路径

(2)absolute

非必需属性,如果设置为true,src需要以绝对路径指定。

5.javascript

<asset:javascript src="home.js"/>

属性

(1)src

必需属性。JS 文件的路径 。

(2)charset

非必需属性文件的字符集。

6.link

<asset:link rel="shortcut icon" type="image/x-icon" href="favicon.ico"/>

属性

(1)href

必需属性,asset的路径 。

(2)ref

非必需属性显示名称

(3)type

非必需属性

7.script

内联的js代码块。

<asset:script>
    console.log('hello world');
</asset:script>

8.stylesheet

<asset:stylesheet href="example/style.css"/>


http://bertramdev.github.io/grails-asset-pipeline/guide/introduction.html

相关文章

迭代器模式(Iterator)迭代器模式(Iterator)[Cursor]意图...
高性能IO模型浅析服务器端编程经常需要构造高性能的IO模型,...
策略模式(Strategy)策略模式(Strategy)[Policy]意图:定...
访问者模式(Visitor)访问者模式(Visitor)意图:表示一个...
命令模式(Command)命令模式(Command)[Action/Transactio...
生成器模式(Builder)生成器模式(Builder)意图:将一个对...