S
S
Sybe2016-02-17 19:45:35
ASP.NET
Sybe, 2016-02-17 19:45:35

How to inject collected scripts and styles into the layout page of an MVC application using gulp?

There are many articles on the Internet on the topic of building a front-end using Gulp, but nowhere is it described how all this will be injected into the layout page, thanks in advance!
I am also interested in the possibility, depending on the environment parameters (production, debug), to change how the files will be added to the layout (for production - glued and minified, for debug - as is)
ASP.NET MVC 5

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Dyrkov, 2016-02-17
@VIKINGVyksa

I can help with the second question. Because gulp config file executes node.js we can use its functionality. We usually write something like this:

var isDev = !process.env.NODE_ENV || process.env.NODE_ENV === 'development';
//переменная true если перменная окружения не установлена или равна development

in order to run build in windows, you will need to type something like this
and use the gulp-if module in the tasks themselves, something like this
var _if = require('gulp-if');

gulp.task('html', function () {
    return gulp.src(path.src.html)
            .pipe(gulp.dest(path.dist.html))
            .pipe(_if(isDebug,_debug({title:'html'})))
            // будем дебажить только если запустили как дебаг
            .pipe(reload({stream: true}));
});

Depending on the variable, we can minify or dump files as is.

T
timfcsm, 2016-02-18
@timfcsm

gulp injection

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question