2016-03-12 58 views
1

我正在尋找一種在我的Laravel應用程序中使用多個SUI主題的方法,每個租戶(網站)都有一個主題。我將語義UI(semantic-ui-less回購)安裝爲node_module。多租戶和語義UI

不知何故我需要有多個theme.config文件才能指向不同的site文件夾來覆蓋默認主題。再次,每個租戶一個。然後,我可以使用Gulp爲特定租戶構建主題。覆蓋theme.config文件每個gulp構建也是一種選擇,但我不知道如何解決這個問題。

我能想到的另一種選擇是爲每個租戶提供多個composer.json文件。但我認爲這只是主題的矯枉過正,可能會導致碰撞問題。

除了this沒有答案的問題,網上沒有什麼可以找到的。我希望有人能幫助我!

回答

0

我想出了一個非常酷的解決方案,它取代了theme.config中的siteFolder變量指向正確的目錄。之後,我可以編譯較少的文件。

Gulpfile.js

var Elixir = require('laravel-elixir'); 
var gulp = require('gulp'); 
var replace = require('gulp-replace'); 
var rename = require('gulp-rename'); 
var util = require('gulp-util'); 

/* 
|-------------------------------------------------------------------------- 
| Tenants 
|-------------------------------------------------------------------------- 
| 
| Build Semantic UI individually for each tenant. 
| 
*/ 
if (typeof util.env.tenant === 'string') { 

    var tenant = util.env.tenant; 
    var tenantPath = 'storage/tenants/' + tenant + '/assets'; 
    var semanticPath = 'node_modules/semantic-ui-less/'; 

    Elixir.extend('theme', function(tenant) { 

     new Elixir.Task('theme', function() { 
      /** 
      * Perform some magic by pointing the @siteFolder variable 
      * to the current tenant's theme directory in order for each 
      * tenant to have it's own unique Semantic UI theme. 
      */ 
      return gulp.src([semanticPath + 'theme.config.example']) 
       .pipe(replace("'site'", "'../../" + tenantPath + "/theme'")) 
       .pipe(rename('theme.config')) 
       .pipe(gulp.dest(semanticPath)); 
     }); 

    }); 

    Elixir(function(mix) { 
     mix 
      .theme(tenant) 
      .less(semanticPath + '/semantic.less', tenantPath + '/css/semantic.min.css') 
      .scriptsIn(semanticPath . '/definitions', tenantPath + '/js/semantic.min.js') 
      .copy(semanticPath + '/themes/default/assets', tenantPath + '/css/themes/default'); 
    }); 

} 

使用 gulp --tenant {name}