How to remove global “use strict” added by babel

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

    I just made a script that runs in the Node and removes "use strict"; in the selected file.

    file: script.js:

    let fs = require('fs');
    let file = 'custom/path/index.js';
    let data = fs.readFileSync(file, 'utf8');
    let regex = new RegExp('"use\\s+strict";');
    if (data.match(regex)){
        let data2 = data.replace(regex, '');
        fs.writeFileSync(file, data2);
        console.log('use strict mode removed ...');
    }
    else {
        console.log('use strict mode is missing .');
    }
    

    node ./script.js

提交回复
热议问题