spatie / laravel-mix-purgecss

Zero-config Purgecss for Laravel Mix
https://spatie.be/en/opensource
MIT License
874 stars 38 forks source link

Fix chaining by using correct `this` reference. #11

Closed tinyfly closed 6 years ago

tinyfly commented 6 years ago

Switch from ES2015 fat arrow function syntax to an anonymous function so that this refers to the mix object and not an empty object.

I tried v1.0.4 and it still wasn't chainable. I would get an error with this:

TypeError: mix.options(...).webpackConfig(...).babelConfig(...).sass(...).copyDirectory(...).js(...).autoload(...).extract(...).purgeCss(...).sourceMaps is not a function

No matter where I put purgeCss in the chain the next function gets the '... is not a function'. It only works if it is the last one in the chain.

The problem was that the this being returned was referencing an empty object. This PR fixes that.

sebastiandedeyne commented 6 years ago

Good call, was an oversight of mine.

I'd rather not use this though, could you update the PR to return mix with an arrow function instead?

If I had full control over the code I wouldn't mind this, but since we're patching a function to an existing object, I'd rather not use something so "dynamic".

tinyfly commented 6 years ago

That makes sense. I've made the change back to an arrow function but returning mix instead.

sebastiandedeyne commented 6 years ago

Thanks!