Open minimit opened 9 years ago
Thats how you can do it:
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var del = require('del');
/** Production **/
gulp.task('production', function(cb) {
plugins.runSequence('clean', 'styles-prod', 'scripts-prod', 'clean-tmp', cb);
});
gulp.task('scripts-prod', function() {
var jsFilter = plugins.filter('**/*.js');
var cssFilter = plugins.filter('**/*.css');
var userefAssets = plugins.useref.assets();
return gulp.src('app/index.html')
.pipe(userefAssets)
.pipe(jsFilter)
.pipe(plugins.uglify())
.pipe(jsFilter.restore())
.pipe(cssFilter)
.pipe(cssFilter.restore())
.pipe(plugins.rev())
.pipe(userefAssets.restore())
.pipe(plugins.useref())
.pipe(plugins.revReplace())
.pipe(gulp.dest('distfolder');
});
gulp.task('styles-prod', function () {
return gulp.src(paths.vendorCss.concat('app/less/main.less'))
.pipe(plugins.if(/less$/, plugins.less()))
.pipe(plugins.concat('app.css'))
.pipe(plugins.minifyCss())
.pipe(gulp.dest('tmp/css'));
});
node.js
gulp-rev
gulp-rev-replace
gulp-run-sequence
del
gulp-concat
gulp-less
gulp-useref
index.html
<!doctype html>
<html ng-app="app" lang="en">
<head>
<meta charset="UTF-8">
<title>Angular App</title>
<!-- build:css css/main.css -->
<link rel="stylesheet" href="../tmp/css/app.css"/>
<!-- endbuild -->
</head>
<body>
<aside ng-include="'views/layouts/partials/nav.html'" id="main-header"></aside>
<div ui-view></div>
<!-- build:js js/app.js -->
<script type="text/javascript" src="js/app.js"></script>
<!-- endbuild -->
<!-- build:js js/vendor1.js -->
<script type="text/javascript" src="../vendor/bower_components/angular/angular.js"></script>
<script type="text/javascript" src="../vendor/bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<!-- endbuild -->
</body>
</html>
Hello, I'm using this code, and basically the main.css is a .less file compiled, but also if I generate it in /src and get it useref(), the code gets executed before the .css is generated, and it gives an error. If I put an empty main.css it gets compiled before the preprocessor. Any way to to it? thanks