birdofpreyru/babel-plugin-transform-assets

[Question] Will this plugin point to the Webpack assets?

nsunga opened this issue · 3 comments

nsunga commented

Hello! Its mentioned in the readme that this is a fork to work with the latest version of Webpack file-loader - 6.2.0

My question is - what exactly is the solution that this provides?

Are the transformed assets - the actual assets processed by Webpack file-loader?

I would imagine this is for server side rendering Webpack projects - and not having to bundle server code and just use babel.

Yes, it is for server-side rendering, for projects that use Webpack to bundle their code for the client-side, but only use Babel to compile their code for the server-side execution. This plugin replaces asset imports in JS code by definitions of variables with resulting URLs of those assets assigned to them (the same what Webpack does to JS code with such imports). Obviously, we want asset URLs assigned by this plugin to match exactly URLs generated by Webpack for the client-side code, and it was the problem solved by the fork — in some release of Webpack the exact algo for URLs generation was altered, and it required changes in this plugin to keep URLs matching.

nsunga commented

@birdofpreyru awesome and thank u for breaking it down!

it looks like the majority of open source that solves this problem is unfortunately outdated - so i'll give this a try

one last question - im assuming u have a project with webpack w/ file-loader that uses this. what version of webpack are u running and are there any unsupported versions of webpack that u know of?

if u dont have the time to reply, then thats okay - im sure i'll uncover a lot as i go

It should be compatible with JS bundles generated by any recent version of Webpack — the breaking change was just in one major release of Webpack, I believe, and it is not affected by most of other Webpack releases.