How to remove global “use strict” added by babel

后端 未结 16 2309
不思量自难忘°
不思量自难忘° 2020-11-27 03:46

I\'m using function form of \"use strict\" and don\'t want global form which Babel adds after transpilation. The problem is I\'m using some libraries that aren\'t using \"us

16条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 04:33

    Personally, I use the gulp-iife plugin and I wrap IIFEs around all my files. I noticed that the babel plugin (using preset es2015) adds a global "use strict" as well. I run my post babel code through the iife stream plugin again so it nullifies what babel did.

    gulp.task("build-js-source-dev", function () {
    	return gulp.src(jsSourceGlob)
          .pipe(iife())
    	  .pipe(plumber())
    	  .pipe(babel({ presets: ["es2015"] }))// compile ES6 to ES5
    	  .pipe(plumber.stop())
          .pipe(iife()) // because babel preset "es2015" adds a global "use strict"; which we dont want
          .pipe(concat(jsDistFile)) // concat to single file
    	  .pipe(gulp.dest("public_dist"))
    });

提交回复
热议问题