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"]);