本文介紹了從 gulp 任務運行 npm 腳本的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
如何從 gulp 任務中運行 npm 腳本命令?
How to run a npm script command from inside a gulp task?
package.json
package.json
"scripts":
{
"tsc": "tsc -w"
}
gulpfile.js
gulpfile.js
gulp.task('compile:app', function(){
return gulp.src('src/**/*.ts')
.pipe(/*npm run tsc*/)
.pipe(gulp.dest('./dist'))
.pipe(connect.reload());
});
我想這樣做是因為運行 npm run tsc
不會給我任何錯誤,但如果我使用 gulp-typescript
編譯 .ts
然后我得到一堆錯誤.
I want to do this because running npm run tsc
does not give me any error but if I use gulp-typescript
to compile .ts
then I get bunch of errors.
推薦答案
你可以使用 gulp-typescript
var gulp = require('gulp');
var ts = require('gulp-typescript');
gulp.task('default', function () {
var tsProject = ts.createProject('tsconfig.json');
var result = tsProject.src().pipe(ts(tsProject));
return result.js.pipe(gulp.dest('release'));
});
gulp.task('watch', ['default'], function() {
gulp.watch('src/*.ts', ['default']);
});
然后在你的 package.json
"scripts": {
"gulp": "gulp",
"gulp-watch": "gulp watch"
}
然后運行
npm run gulp-watch
<小時>
或者使用 shell
var gulp = require('gulp');
var shell = require('gulp-shell');
gulp.task('default', function () {
return gulp.src('src/**/*.ts')
.pipe(shell('npm run tsc'))
.pipe(gulp.dest('./dist'))
.pipe(connect.reload());
});
gulp-shell
已經是 被列入黑名單你可以在這里看到原因
另一種選擇是設置 webpack
.
這篇關于從 gulp 任務運行 npm 腳本的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!