swc-project / swc-loader

Moved to https://github.com/swc-project/pkgs
MIT License
394 stars 29 forks source link

Add Webpack 4 Support #52

Closed acao closed 2 years ago

acao commented 2 years ago

This is the only change that is required to support Webpack 4, works great for me

I see peerDependencies for this library goes back to webpack 2, so I wanted to help make that a thing!

I wish the conditional could be evaluated only once for optimal perf, but it needed to be scoped for this. Perhaps I could set a flag the first time the conditional is evaluated:

let webpack5 = true;

function makeLoader() {
    return function (source, inputSourceMap) {
     // cheaper boolean conditional. 
     // if webpack5 is false the first time, don't check again
      if(webpack5 && 'getOptions' in this) {
         webpack5 = false
      }
      let loaderOptions = webpack5 ? this.getOptions() : require('loader-utils').getOptions(this)
    }
}

Do you have a way of benchmarking the webpack loader? Might be a negligible difference but worth considering

Note: Oddly, it looks like github.dev applied some formatting as well when I created this using this new approach, thought I'd try it

CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.

kdy1 commented 2 years ago

Can you sign the CLA?

acao commented 2 years ago

@kdy1 thank you for this awesome project!