将Gavascript文件捆绑在一起观看Gulp和Nodeman

时间:2017-12-07 02:24:40

标签: gulp browserify nodemon watchify

我按照我希望的方式启动和部署任务,但是当我在app.js中进行更改以便可以观察时,我正在试图弄清楚如何更新public / js / bundle.js。

这是我到目前为止所得到的:

var gulp = require('gulp');
var streamify = require('gulp-streamify');
var uglify = require('gulp-uglify');
var transform = require('vinyl-source-stream');
var browserify = require('browserify');
var rename = require('gulp-rename');
var nodemon = require('gulp-nodemon');

var ios = browserify({
   entries:['app.js']
 });

const bundle = () => {

  process.env.NODE_ENV = 'production';

    ios.require('./app-ios.js', {expose:'appalias'})
      .bundle()
      .pipe(transform('bundle-ios.js'))
      .pipe(gulp.dest('./public/js'))
      .pipe(streamify(uglify()))
      .pipe(rename('bundle-ios.min.js'))
      .pipe(gulp.dest('./public/js'));

    return ios;
}

const start = () => {
  return nodemon({
    script: 'server.js',
    watch: ['server.js', 'public/js/*', 'public/index.html', 'public/css/*'],
    ext: 'js html css',
    env: { 'NODE_ENV': 'development' },
  });
}

// Start local server and watch bundles.
gulp.task('start', start);

// Build minified versions for prod.
gulp.task('deploy', bundle);

1 个答案:

答案 0 :(得分:0)

修复是观察所有单独的javascript组件和模型文件,并将一个编译任务添加到启动任务。

// Bundle and minify for development, use development version of libraries.
const compile = () => {

  process.env.NODE_ENV = 'development';

  const bundleAndroidDev = ios.require('./app-ios.js', {expose:'appalias'})
    .bundle()
    .pipe(transform('bundle-ios.js'))
    .pipe(gulp.dest('./public/js'));

  return bundleIosDev;
}

// Start local server and watch for changes in compiled bundles.
const start = () => {
  return nodemon({
    script: 'server.js',
    watch: ['server.js', 'apps/appName/components/*', 'apps/appName/models/*', 'public/index.html', 'public/css/*'],
    ext: 'js html css',
    tasks: ['compile'],
    env: { 'NODE_ENV': 'development' }
  });
}

// Compile bundle's on save.
gulp.task('compile', compile);