【发布时间】:2015-12-05 11:35:13
【问题描述】:
我对 ionic 和 gulp 有点陌生。
当我第一次运行 ionic serve 时,我能够配置 ionic.project 文件以运行 gulp 任务。
但是现在当我更改文件时,我希望 gulp 任务再次运行..但这不会发生..有没有办法做到这一点?
这是我的ionic.project 文件:
{
"name": "test",
"app_id": "",
"gulpStartupTasks": [
"default"
],
"watchPatterns": [
"src/**/*",
"src/*",
"www/**/*",
"!www/lib/**/*"
]
}
我预计当某些文件更改与wtachPatterns 匹配时
它将调用 gulp watch 任务,但这不会发生(我看到 ionic 看到文件已更改但没有任何反应。)
这是 gulp watch 任务:
gulp.task('watch', function() {
gulp.watch(paths.sass, ['sass']);
gulp.watch(paths.script, ['script']);
});
基本上任务是压缩所有的 JS 文件和所有的 sass/scss 文件
index.html 正在查看缩小的文件。因此,如果未调用 gulp 任务,则缩小文件中没有任何更改,我需要重新运行ionic serve。有没有合适的方法来做到这一点?
更新:
这是完整的 gulpfile
var gulp = require('gulp');
var gutil = require('gulp-util');
var bower = require('bower');
require('require-dir')('./gulp/tasks');
var paths = {
sass: ['./scss/**/*.scss'],
style: ['./src/**/*.scss'],
script: ['./src/app.js'],
html:['./src/*.html']
};
gulp.task('default', ['sass', 'script','watch', 'html', 'style']);
gulp.task('watch', function() {
gulp.watch(paths.sass, ['sass']);
gulp.watch(paths.script, ['script']);
});
gulp.task('install', ['git-check'], function() {
return bower.commands.install()
.on('log', function(data) {
gutil.log('bower', gutil.colors.cyan(data.id), data.message);
});
});
gulp.task('git-check', function(done) {
if (!sh.which('git')) {
console.log(
' ' + gutil.colors.red('Git is not installed.'),
'\n Git, the version control system, is required to download Ionic.',
'\n Download git here:', gutil.colors.cyan('http://git- scm.com/downloads') + '.',
'\n Once git is installed, run \'' + gutil.colors.cyan('gulp install') + '\' again.'
);
process.exit(1);
}
done();
});
这是具有实际任务的文件之一的示例:
var browserify = require('browserify');
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var stringify = require('stringify');
var paths = ['./src/app.js'];
gulp.task('script', function() {
return browserify(paths, {debug: true})
.transform(stringify(['.html']))
.bundle()
.pipe(source('app.js'))
.pipe(gulp.dest('./www/js'));
});
【问题讨论】:
-
显示你的
gulpfile.js -
需要的文件
require('require-dir')('./gulp/tasks');呢? -
@PeteHouston 我添加了其中一个文件。
-
@PeteHouston 你知道吗?
-
你找到解决办法了吗?
标签: ionic gulp gulp-watch