How to remove global “use strict” added by babel

后端 未结 16 2292
不思量自难忘°
不思量自难忘° 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:11

    For babel 6 instead of monkey patching the preset and/or forking it and publishing it, you can also just wrap the original plugin and set the strict option to false.

    Something along those lines should do the trick:

    const es2015preset = require('babel-preset-es2015');
    const commonjsPlugin = require('babel-plugin-transform-es2015-modules-commonjs');
    
    es2015preset.plugins.forEach(function(plugin) {
      if (plugin.length && plugin[0] === commonjsPlugin) {
        plugin[1].strict = false;
      }
    });
    
    module.exports = es2015preset;
    

提交回复
热议问题