juanca / sprockets-preloader

Webpack pre-loader to easily translate sprockets require directives into npm module requires
6 stars 5 forks source link

Update require.js #17

Closed quinn closed 5 years ago

quinn commented 7 years ago

this is a WIP, untested. curious if this seems like a good change or not. I think it could make require errors more visible while migrating assets to webpack from sprockets.

The current way of quietly logging to STDOUT I don't think is sufficient for compile errors having to do with unresolved sprockets paths. There is also the possibility that simply requiring the path could allow it to get successfully resolved by webpack.

juanca commented 7 years ago

Avoiding webpack bundling errors was useful for our migration because some gems were using .erb files in their require_tree.

Since webpack is unable to parse those file, it will break the webpack bundle.

These warnings are helpful since they indicate which files are needed to be ported manually to some rails served .erb file (such as after_webpack.js.erb)

Perhaps I can expand on the printed message to better describe the intention.

Does this make more sense by chance:

var message = '[sprockets-preloader]: Unresolvable file ' + requireFile + ' referenced in ' + context;
var description = 'If this file is not parseable by webpack (e.g. `.erb` files), ensure to include it in a sprockets served file. Otherwise, this file is missing';
console.log(message, decription);
juanca commented 7 years ago

Actually, perhaps this is a better strategy:

If the file is an .erb file (since those type of files tend by the only non-compatible webpack files) then it should console.log. Otherwise, I think your solution makes sense (allow webpack resolver to blow up).

juanca commented 6 years ago

This might be superseded by https://github.com/mavenlink/sprockets-preloader/pull/21

They both express the same idea but have slightly different configurations.