2015-04-08 29 views
1

我使用gulpgulp-header和一堆工具將我的scss和coffescript編譯成css和js文件。我gulpfile看起來是這樣的:有沒有一種簡單的方法將標題附加到symfony2的資產生成資產?

gulp = require('gulp') 
pkg = require('./package.json') 
plugins = require('gulp-load-plugins')() 

#... 

banner = [ 
    '/**' 
    ' * ' + pkg.name + ' - ' + pkg.description 
    ' * @version v' + pkg.version 
    ' * @link ' + pkg.homepage 
    ' * @license ' + pkg.license + ' ' + new Date().getFullYear() 
    ' * @generated ' + new Date() 
    ' */' 
    '' 
].join('\n') 

gulp.task 'sass', -> 
    gulp.src(css_dir + '**/*.scss') 
    .pipe(plugins.sourcemaps.init()) 
    .pipe(plugins.sass 
     style: 'compressed' 
    ) 
    .on 'error', plugins.util.log 
    .pipe(plugins.header(banner)) 
    .pipe(gulp.dest(css_dir)) 
    .pipe(plugins.sourcemaps.write()) 
    .pipe plugins.notify('Scss compiling done!') 
    return 

#... (same goes for coffeescript) 

我想用Symfony2's asset management (assetic)來完成相同的。

assetic: 
    debug:   "%kernel.debug%" 
    use_controller: false 
    bundles:  [ AcmeDemoBundle ] 
    #java: /usr/bin/java 
    filters: 
     cssrewrite: ~ 
     sass: ~ 
     coffee: 
      bin: /usr/local/bin/coffee 
      node: /usr/local/bin/node 

我想有一個自定義的註釋頭(請參閱例如gulpfile banner)追加到由assetic產生我的JS和CSS文件當我運行assetic:dump命令:

$ php app/console assetic:dump 

我敢打賭這可以使用custom assetic filters完成。如果有人已經這樣做了,那會很好,否則,如果我找到工作,我會在這裏發帖。

回答

0

我已經做了在服務器應用程序(Apache時,Nginx的...)這個規則的使用所產生的資產僅僅是文件,它們直接擔任了.htaccess文件的文件說

# If the requested filename exists, simply serve it. 
# We only want to let Apache serve files and not directories. 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule .? - [L]