hauleth / vanilla-ujs

UJS without jQuery dependency
MIT License
194 stars 24 forks source link

Use outside of Sprockets #31

Open jarednorman opened 7 years ago

jarednorman commented 7 years ago

Versions after 0.1.0 don't seem to be able to be (reasonably) used outside of Sprockets (within other build tools, like Webpack, for example). Currently installing this package from npm seem kind of pointless since it contains Sprockets directives that don't work outside of Sprockets.

Was this a conscious decision? With Rails moving towards being friendlier to external asset tools with Webpacker and all that, it seems like this project should support that stuff. Thoughts?

hauleth commented 7 years ago

I can check this, however I was hinking about moving to ES2015 and using imports instead of Sprockets.

prem-prakash commented 7 years ago

tried to use as node package + webpack import

import 'vanilla-ujs/lib/assets/javascripts/vanilla-ujs/polyfills.js';
import 'vanilla-ujs/lib/assets/javascripts/vanilla-ujs/confirm.js';
import 'vanilla-ujs/lib/assets/javascripts/vanilla-ujs/csrf.js';
import 'vanilla-ujs/lib/assets/javascripts/vanilla-ujs/disable.js';
import 'vanilla-ujs/lib/assets/javascripts/vanilla-ujs/form.js';
import 'vanilla-ujs/lib/assets/javascripts/vanilla-ujs/liteajax.js';
import 'vanilla-ujs/lib/assets/javascripts/vanilla-ujs/method.js';

but it does not work

it says matches as not defined

jarednorman commented 7 years ago

Now that rails-ujs exists with no dep on jQuery, I just use that. I'm unfollowing this issue, but not closing it since other people seem to want this feature. :heart:

quentindemetz commented 6 years ago

I managed to use this with with webpacker using the following code:

 window.matches = (function(doc) {
   return doc.matchesSelector ||
     doc.webkitMatchesSelector ||
     doc.mozMatchesSelector ||
     doc.oMatchesSelector ||
     doc.msMatchesSelector;
 })(document.documentElement);

import 'vanilla-ujs/lib/assets/javascripts/vanilla-ujs/polyfills.js';
import 'vanilla-ujs/lib/assets/javascripts/vanilla-ujs/confirm.js';
import 'vanilla-ujs/lib/assets/javascripts/vanilla-ujs/csrf.js';
import 'vanilla-ujs/lib/assets/javascripts/vanilla-ujs/disable.js';
import 'vanilla-ujs/lib/assets/javascripts/vanilla-ujs/form.js';
import 'vanilla-ujs/lib/assets/javascripts/vanilla-ujs/liteajax.js';
import 'vanilla-ujs/lib/assets/javascripts/vanilla-ujs/method.js';

UPDATE: This works for some features (confirm) but not for others (LiteAjax is not plublicly exposed...)

AlfonsoUceda commented 6 years ago

I'm going to take advantage of this issue and ask if there is a chance to remove railsties gem and make this gem agnostic.