Skip to content

Instantly share code, notes, and snippets.

@avicdro
Last active August 23, 2018 00:56
Show Gist options
  • Save avicdro/63171df25262ff68f7405a65f80c36b4 to your computer and use it in GitHub Desktop.
Save avicdro/63171df25262ff68f7405a65f80c36b4 to your computer and use it in GitHub Desktop.
my workflow configuration with (gulp + pug + sass + ts + browserify + browsersync) -dev- static pages

configuration with (gulp + pug + sass + ts + browserify + browsersync) -dev- static pages

my workflow

my workflow configuration with (gulp + pug + sass + ts + browserify + browsersync) -dev- static pages

install - 21/8/2018

--solo 1 vez -- 
npm install -g browser-sync
npm install -g gulp-cli
-- por proyecto --
npm init -y
npm install --save-dev typescript gulp gulp-typescript
npm install --save-dev browserify tsify vinyl-source-stream
npm install --save-dev sass gulp-sass 
npm install --save-dev pug gulp-pug

config

Directory

  • dist
    • css
    • js
  • src
    • pug
    • sass
    • ts

gulpfile.js
package.json
tsconfig.json

tsconfig.json

{
    "compilerOptions": {
        "noImplicitAny": true,
        "removeComments": true,
        "preserveConstEnums": true,
        "target": "es5",
        "outDir": "./dist/js/",
        "sourceMap": true
    },
    "include": [
        "./src/ts/**/*.ts"
    ],
    "exclude": [
        "node_modules",
        "**/*.spec.ts"
    ]
}

gulpfile.js

var gulp = require("gulp");
// typescrip 
var ts = require("gulp-typescript");
var tsProject = ts.createProject("tsconfig.json");
// sass
var sass = require('gulp-sass');
// browserSync
var browserSync = require('browser-sync').create();
// pug
var pug = require("gulp-pug");
// browserify
var browserify = require("browserify");
var source = require('vinyl-source-stream');
var tsify = require("tsify");
// var paths = {
//     modules: ['src/ts/main.ts','' ]
// };

gulp.task('ts', function () {
    return  tsProject.src()
            .pipe(tsProject())
            .js.pipe(gulp.dest("dist/js/"));
});

// Compile sass into CSS & auto-inject into browsers
gulp.task('sass', function(){
    return gulp.src("src/sass/**/*.scss")
        .pipe(sass({outputStyle: 'expanded'}))
        .pipe(gulp.dest("dist/css/"))
        .pipe(browserSync.stream());
});
// compile pug into html
gulp.task('pug', function(){
    return  gulp.src("src/pug/**/*.pug")
            .pipe(pug({
                pretty: true
            }))
            .pipe(gulp.dest("dist/"));
});
//  Bundle 
gulp.task('bundle',function(){
    return browserify({
                basedir: '.',
                debug: true,
                entries: ['src/ts/main.ts'],
                cache: {},
                packageCache: {}
            })
            .plugin(tsify)
            .bundle()
            .pipe(source('bundle.js'))
            .pipe(gulp.dest("dist/js/"));
});
// Static Server + watching scss/html files
gulp.task('serve', [ 'sass', 'pug', 'bundle'], function() {

    browserSync.init({
        server: "./dist"
    });
    
    gulp.watch("src/sass/**/*.scss", ['sass']);
    gulp.watch("src/pug/**/*.pug", ['pug']);
    gulp.watch("src/ts/**/*.ts", ['bundle' , ()=> {browserSync.reload()}]);
    gulp.watch("dist/**/*.html").on('change', browserSync.reload);
});

gulp.task('default', ['serve']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment