多租户和语义用户界面

时间:2016-03-12 13:11:05

标签: gulp themes multi-tenant semantic-ui multisite

我正在寻找一种在我的Laravel应用程序中使用多个SUI主题的方法,每个租户(网站)都有一个主题。我将Semantic UI(semantic-ui-less repo)安装为node_module。

不知何故,我需要有多个theme.config文件才能指向不同的site文件夹来覆盖默认主题。同样,每个租户一个。然后,我可以使用Gulp为特定租户构建主题。覆盖theme.config文件每个gulp构建也是一种选择,但我不知道如何解决这个问题。

我能想到的另一个选择是为每个租户提供多个composer.json文件。但是我觉得这对于主题来说太过分了,它可能会导致碰撞问题。

互联网上没有什么可以找到的,除了this未回答的问题。我希望有人可以帮助我!

1 个答案:

答案 0 :(得分: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}

相关问题