简体   繁体   中英

npm does not work with msbuild

I am new to gulp and I am facing problem in integrating it with msbuild. I am trying to run tasks using gulp(eg: minifying files) and even though it works perfectly when I build my project,it fails to run on msbuild. Here is the code for gulpfile.js :

var gulp=require("gulp"),
gutil=require("gulp-util"),
uglify=require("gulp-uglify"),
debug=require("gulp-debug"),
concat=require("gulp-concat");
var uglifycss = require('gulp-uglifycss');
gulp.task("js",function(){
    gulp.src(["./**/*.js","!./**/*.min.*","!./**/gulpfile.js"])
    .pipe(uglify())
    .pipe(debug())
    .pipe(gulp.dest(function(file){return file.base}));

gulp.task('css', function () {
  gulp.src(["./**/*.css","!./**/*.min.*"])
    .pipe(uglifycss())
    .pipe(gulp.dest(function(file){return file.base}));
});
gulp.task("build",["js","css"]);
gulp.task('default', function(){
gulp.run('build'); 
});

this is called by a powershell script file compileClient.ps1:

npm install -g gulp
npm install --save-dev gulp gulp-util
npm install --save-dev gulp-uglify gulp-concat
npm install --save gulp-uglifycss
npm install --save-dev gulp-debug
gulp
npm install -g rimraf
cmd /c $env:APPDATA\npm\rimraf ./node_modules

when I run this command on cmd,

"%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe" -file "$(ProjectDir)compileClient.ps1"

It works fine and minifies the target files. I then tried putting this command in the post build event of my project and when I run it locally on visual studio it works fine too.

however when this project is built by msbuild, the same post-build event does not work,it gives the following message shown in the image below: npm : the term 'npm' is not recognized as the name of a cmdlet..

I checked the PATH variable set by node and it is correct. Also when I do node -v on my cmd I could see the version of node installed, but when I do it on the msbuild command line it fails to identify node.

I used this blog as a reference https://www.niclassahlin.com/2015/04/10/running-gulp-during-tfs-build/

I would appreciate any help/advice on this matter, thanks.

您可以使用Node.js安装程序来安装npm,此后npm将对所有用户可用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM