Giter Site home page Giter Site logo

Gulp watch about gulp-file-include HOT 9 CLOSED

haoxins avatar haoxins commented on August 17, 2024
Gulp watch

from gulp-file-include.

Comments (9)

haoxins avatar haoxins commented on August 17, 2024
var gulp = require('gulp'),
  fileinclude = require('gulp-file-include');

gulp.task('include', function() {
  gulp.src(['some src files ...'])
    .pipe(fileinclude({your options}))
    .pipe(gulp.dest('.'));
});

// if need watch
gulp.task('watch', function() {
  gulp.watch('some files ...', ['include']);
});

from gulp-file-include.

Shonetow avatar Shonetow commented on August 17, 2024

I'm sorry and thank you, I wrote an uncomplete question (I was to tired). Of course this will work, but I have problem with LiveReload.

I'm using yeoman/generator-gulp-webapp and I added gulp-file-include. I set up gulpfile.js to include files on build, but I don't know how to set up for gulp watch.

This is my modified guplfile.js

'use strict';
// generated on 2014-10-27 using generator-gulp-webapp 0.1.0

var gulp = require('gulp');

// load plugins
var $ = require('gulp-load-plugins')();

gulp.task('styles', function () {
    return gulp.src('app/styles/main.scss')
        .pipe($.rubySass({
            style: 'expanded',
            precision: 10
        }))
        .pipe($.autoprefixer('last 1 version'))
        .pipe(gulp.dest('.tmp/styles'))
        .pipe($.size());
});

gulp.task('fileinclude', function () {
    return gulp.src('app/*.html')
        .pipe($.fileInclude())
        .pipe($.size());
})

gulp.task('scripts', function () {
    return gulp.src('app/scripts/**/*.js')
        .pipe($.jshint())
        .pipe($.jshint.reporter(require('jshint-stylish')))
        .pipe($.size());
});

gulp.task('html', ['styles', 'scripts'], function () {
    var jsFilter = $.filter('**/*.js');
    var cssFilter = $.filter('**/*.css');

    return gulp.src(['app/*.html'])
        .pipe($.fileInclude())
        .pipe($.useref.assets({searchPath: '{.tmp,app}'}))
        .pipe(jsFilter)
        .pipe($.uglify())
        .pipe(jsFilter.restore())
        .pipe(cssFilter)
        .pipe($.csso())
        .pipe(cssFilter.restore())
        .pipe($.useref.restore())
        .pipe($.useref())
        .pipe(gulp.dest('dist'))
        .pipe($.size());
});

gulp.task('images', function () {
    return gulp.src('app/images/**/*')
        .pipe($.cache($.imagemin({
            optimizationLevel: 3,
            progressive: true,
            interlaced: true
        })))
        .pipe(gulp.dest('dist/images'))
        .pipe($.size());
});

gulp.task('fonts', function () {
    return $.bowerFiles()
        .pipe($.filter('**/*.{eot,svg,ttf,woff}'))
        .pipe($.flatten())
        .pipe(gulp.dest('dist/fonts'))
        .pipe($.size());
});

gulp.task('extras', function () {
    return gulp.src(['app/*.*', '!app/*.html'], {dot: true})
        .pipe(gulp.dest('dist'));
});

gulp.task('clean', function () {
    return gulp.src(['.tmp', 'dist'], {read: false}).pipe($.clean());
});

gulp.task('cleanafter', function () {
    return gulp.src(['dist/*.tmp.html'], {read: false}).pipe($.clean());
});

gulp.task('build', ['html', 'images', 'fonts', 'extras']);

gulp.task('default', ['clean'], function () {
    gulp.start('build');
});

gulp.task('connect', function () {
    var connect = require('connect');
    var app = connect()
        .use(require('connect-livereload')({port: 35729}))
        .use(connect.static('app'))
        .use(connect.static('.tmp'))
        .use(connect.directory('app'));

    require('http').createServer(app)
        .listen(9000)
        .on('listening', function () {
            console.log('Started connect web server on http://localhost:9000');
        });
});

gulp.task('serve', ['connect', 'fileinclude', 'styles'], function () {
    require('opn')('http://localhost:9000');
});

// inject bower components
gulp.task('wiredep', function () {
    var wiredep = require('wiredep').stream;

    gulp.src('app/styles/*.scss')
        .pipe(wiredep({
            directory: 'app/bower_components'
        }))
        .pipe(gulp.dest('app/styles'));

    gulp.src('app/*.html')
        .pipe(wiredep({
            directory: 'app/bower_components'
        }))
        .pipe(gulp.dest('app'));
});

gulp.task('watch', ['connect', 'fileinclude', 'serve'], function () {
    var server = $.livereload();

    // watch for changes

    gulp.watch([
        'app/*.html',
        '.tmp/styles/**/*.css',
        'app/scripts/**/*.js',
        'app/images/**/*'
    ]).on('change', function (file) {
        server.changed(file.path);
    });

    gulp.watch('app/styles/**/*.scss', ['styles']);
    gulp.watch('app/scripts/**/*.js', ['scripts']);
    gulp.watch('app/images/**/*', ['images']);
    gulp.watch('app/*.html', ['fileinclude']);
    gulp.watch('bower.json', ['wiredep']);
});

from gulp-file-include.

haoxins avatar haoxins commented on August 17, 2024

same to #8

I'll try it soon

from gulp-file-include.

haoxins avatar haoxins commented on August 17, 2024

@Shonetow

I change the code

gulp.task('watch', ['connect', 'fileinclude', 'serve'], function () {
    var server = $.livereload();

    // watch for changes

    gulp.watch([
        'app/*.html',
        '.tmp/styles/**/*.css',
        'app/scripts/**/*.js',
        'app/images/**/*'
    ]).on('change', function (file) {
        server.changed(file.path);
    });

    gulp.watch('app/styles/**/*.scss', ['styles']);
    gulp.watch('app/scripts/**/*.js', ['scripts']);
    gulp.watch('app/images/**/*', ['images']);
    gulp.watch('app/*.html', ['fileinclude']);
    gulp.watch('bower.json', ['wiredep']);
});

to

gulp.task('watch', ['connect', 'serve'], function () {
    var server = $.livereload();

    // watch for changes

    gulp.watch([
        'app/*.html',
        '.tmp/styles/**/*.css',
        'app/scripts/**/*.js',
        'app/images/**/*'
    ]).on('change', function (file) {
        server.changed(file.path);
    });

    gulp.watch('app/styles/**/*.scss', ['styles']);
    gulp.watch('app/scripts/**/*.js', ['scripts']);
    gulp.watch('app/images/**/*', ['images']);
    gulp.watch('bower.json', ['wiredep']);
    gulp.watch('app/*.html', ['html']);
});

and the result on dir dist is OK >_<, but livereload just load the origin html
because

.use(connect.static('app'))
.use(connect.static('.tmp'))

from gulp-file-include.

haoxins avatar haoxins commented on August 17, 2024

for the task fileinclude

gulp.task('fileinclude', function () {
    return gulp.src('app/*.html')
        .pipe($.fileInclude())
        .pipe($.size());
});

should be

gulp.task('fileinclude', function () {
    return gulp.src('app/*.html')
        .pipe($.fileInclude())
        .pipe(gulp.dest('somedir'))
        .pipe($.size());
});

from gulp-file-include.

haoxins avatar haoxins commented on August 17, 2024

@Shonetow could you check the dist dir?

from gulp-file-include.

Shonetow avatar Shonetow commented on August 17, 2024

I made this changes.
In dist folder I get everything ok.
LiveReload still nothing... :(

I really hope that you will found the way that it works.

from gulp-file-include.

haoxins avatar haoxins commented on August 17, 2024

@Shonetow change the task connect

.use(connect.static('dist'))
// .use(connect.static('app'))

from gulp-file-include.

Shonetow avatar Shonetow commented on August 17, 2024

Well, this works, but wiredep doesn't.

from gulp-file-include.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.