ym-project / gulp-esbuild

gulp plugin for esbuild bundler
MIT License
43 stars 7 forks source link

Task process does not exit #14

Closed Drozerah closed 2 years ago

Drozerah commented 2 years ago

Hi! when import is:

const {createGulpEsbuild} = require('gulp-esbuild')
const gulpEsbuild = createGulpEsbuild({
    incremental: true, // enables the esbuild's incremental build
    piping: true,      // enables piping
})

The gulp task below won't end...

using

const gulpEsbuild = require('gulp-esbuild')

The task will end...

esbuild task

const esbuild = () => {
  const _src = config.js.src
  const _dest = config.js.dest
  const outfile = config.js.outfile
  return src(_src)
    .pipe(gulpEsbuild({
      outfile,
      bundle: true,
      format: 'esm', // 'iife'|'cjs'|'esm'
    }))
    .pipe(dest(_dest))
}

Am I missing something ?

ym-project commented 2 years ago

Hello @Drozerah!

When you use incremental: true feature, you activate esbuild's incremental build. It means esbuild starts the server and automatically rebuilds only the code that have been changed. So you get infinite process.

This feature should be used with gulp's watch API. See example. If you don't use gulp's watch mode, don't use this feature.

In conclusion

This code

const gulpEsbuild = require('gulp-esbuild');

is the same as

const {createGulpEsbuild} = require('gulp-esbuild');
const gulpEsbuild = createGulpEsbuild({
    incremental: false,
    piping: false,
});
Drozerah commented 2 years ago

OK !! thank you @ym-project for your reply and explanation, I'll check the incremental way of doing things - it also means that the build with incremental: true is faster at dev/watch time ?

ym-project commented 2 years ago

it also means that the build with incremental: true is faster at dev/watch time ?

Yep. Incremental builds are more efficient than regular builds because some of the data is cached and can be reused if the original files haven't changed since the last build.