Practicing platzigram in Javascript

0

I'm doing the Platzigram project of Platzi_ to practice Javascript and so on. When using the package.json to automate tasks with <script> it does not work for me when I execute the npm start command and the gulp watch and tasks are executed > node server.js , only one of them is executed and the one that is first. I will leave the package.json and the gulpfile to tell me if something is wrong and clarify that I am running it in Windows .

>

package.json :

{
  "name": "photogram",
  "version": "0.1.0",
  "description": "Ver y compartir fotos",
  "main": "server.js",
  "keywords": [
    "photogram",
    "javascript",
    "fotos"
  ],
  "author": "Christian Carballo",
  "license": "ISC",
  "dependencies": {
    "express": "^4.15.2",
    "materialize-css": "^0.98.2",
    "page": "^1.7.1",
    "pug": "^2.0.0-rc.1"
  },
  "devDependencies": {
    "babelify": "^7.3.0",
    "browserify": "^14.3.0",
    "gulp": "^3.9.1",
    "gulp-rename": "^1.2.2",
    "gulp-sass": "^3.1.0",
    "vinyl-source-stream": "^1.1.0",
    "watchify": "^3.9.0"
  },
  "scripts":{
    "build": "gulp",
    "start":"gulp watch & node server.js"
  }
}

The gulpfile :

var gulp= require("gulp");
var sass=require("gulp-sass");
var rename=require("gulp-rename");
var babel= require("babelify");
var browserify=require("browserify");
var source=require("vinyl-source-stream");
var watchify= require("watchify")

gulp.task("styles", function(){
    gulp
        .src("index.scss")
        .pipe(sass())
        .pipe(rename("app.css"))
        .pipe(gulp.dest("public"));
})

gulp.task("assets",function(){
    gulp
        .src("assets/*")
        .pipe(gulp.dest("public"));
})

function compile(watch){
    var bundle=watchify(browserify("./src/index.js"));

    function rebundle() {
        bundle
            .transform(babel)
            .bundle()
            .pipe(source("index.js"))
            .pipe(rename("app.js"))
            .pipe(gulp.dest("public"));

    }

    if (watch) {
        bundle.on("update", function(){
            console.log("-->Bundling...");
            rebundle();
        });
    }

    rebundle();
}

gulp.task("build", function(){
    return compile()

});

gulp.task("watch", function(){ return compile(true); });
gulp.task("default", ["styles", "assets","build"]);
    
asked by Christian Gabriel 06.05.2017 в 21:54
source

1 answer

3

Unix-based systems usually use the & symbol to run two or more tasks in parallel as in the case of the script

"start": "gulp watch & node server.js"

but if you are trying to run this code on Windows or want to do something that works the same on multiple operating systems you can try solutions like npm -run-all and replace with

"gulp-watch": "gulp watch" "start-server": "node server.js" "start": "npm-run-all --parallel gulp-watch start-server"

    
answered by 07.05.2017 / 17:01
source