Search code examples
node.jsgulpgulp-uglifygulp-wrap

Gulp-wrap Alternative


I have an existing working project with gulp workflow. Everything runs perfectly fine. My gulp uses this:

  • browser-sync@2.0.1
  • gulp@3.8.11
  • gulp-angular-templatecache@1.5.0
  • gulp-autoprefixer@2.1.0
  • gulp-concat@2.4.3
  • gulp-less@2.0.3
  • gulp-minify-css@0.3.13
  • gulp-minify-html@0.1.8
  • gulp-rename@1.2.0
  • gulp-sourcemaps@1.3.0
  • gulp-uglify@1.1.0
  • gulp-util@3.0.3
  • gulp-watch@4.1.1
  • gulp-wrap@0.10.1
  • minimist@1.1.0

So, I decide it use it on new project for my team. I copy gulpfile.js, package.json to the new project folder and run npm install. Everything is downloaded as usual. But when I try to run my gulp task, I came into this error:

TypeError: Object #<lib$es6$promise$promise$$Promise> has no method 'done'
at DestroyableTransform._transform (E:\www\myproject\node_modules\gulp-less\index.js:68:8)

After some testing I found that that the problem is actually caused by gulp-wrap, which it can be solved by:

  1. Copy the gulp-wrap folder from the old project and override the new one
  2. Comment out / remove all gulp-wrap usage and also the require() of it from gulpfile.js

At first I thought it is caused by new version issue. So, I specifically specify the version in package.json. But after run the npm install, the same problem occur.

So, when I look into my gulpfile, there is only one place that uses gulp-wrap.

wrap('(function(){"use strict"; <%= contents %>\n})();')

Is there anyway I can do the wrapping for this without using gulp-wrap to avoid that problem from occur?


Solution

  • After some research, I found that gulp-insert (https://github.com/rschmukler/gulp-insert) does the job as well and so far I did not experience the problem I am facing with gulp-wrap.

    It can be done with this:

    .pipe(insert.wrap('(function(){"use strict";', '\n})();'))