Coder Social home page Coder Social logo

Comments (11)

justin808 avatar justin808 commented on May 18, 2024

I'm using jquery-rails because of UJS integration. Possibly post this question at http://forum.railsonmaui.com. You can also submit a PR with an example of how to do this with Webpack. I did this before. While it's straightforward given the webpack docs.

I'd agree that we should breake out the jquery part from the ujs part: https://github.com/rails/jquery-ujs.

@dylangrafmyre if you want to try this, I can help you. Or if anybody else wants to make this PR...should be pretty simple.

from react-webpack-rails-tutorial.

badnorseman avatar badnorseman commented on May 18, 2024

I assume that you don't want to include jQuery in your bundle.js.

Add this to your WebPack configuration file:

externals: {
    // require("jquery") is external and available
    //  on the global var jQuery
    "jquery": "jQuery"
}

More info here: http://webpack.github.io/docs/library-and-externals.html

from react-webpack-rails-tutorial.

justin808 avatar justin808 commented on May 18, 2024

@urbanvikingr we'll put jquery in the package.json file, redo the gemfile, export jquery so rails can see it.

A very old version of the config files might still have this in the version history. I had experimented with this a bit.

from react-webpack-rails-tutorial.

badnorseman avatar badnorseman commented on May 18, 2024

@justin808 Export jQuery to Rails sounds interesting. Is this a manual process outside npm or Rails?

from react-webpack-rails-tutorial.

justin808 avatar justin808 commented on May 18, 2024

@urbanvikingr: Export jQuery to Rails just means that jQuery is exposed as a global variable. like window.jQuery or window.$

References:

http://www.codefornow.com/2015/05/18/webpack-exposing-jquery-as-a-global-variable/

https://github.com/webpack/expose-loader

from react-webpack-rails-tutorial.

alex35mil avatar alex35mil commented on May 18, 2024

My opinion on subject.

I think the most consistent way is to ask rails team to publish jquery_ujs to npm (they've already published it on bower btw) and move it to webpack's bundle, so all JS stuff can be manage from one place.

@geminiyellow
If you want to manage your JS via webpack, inevitably, you’ll end up with renunciation of assets pipeline, because it'll became useless.

from react-webpack-rails-tutorial.

justin808 avatar justin808 commented on May 18, 2024

@jbhatab, we were just discussing this today. Let's get a PR for this.

from react-webpack-rails-tutorial.

jbhatab avatar jbhatab commented on May 18, 2024

I agree with @alexfedoseev. Using jquery_ujs through npm is the cleanest and most consistent way to get jquery_ujs in the project but not make it feel different than all the other assets. I do feel since we have to use the jquery_ujs gem, it's irrelevant how we break out jquery until we solve both of them at once since jquery_ujs is already loading in jquery.

Just looked at the github though and it looks like they don't want to support npm, rails/jquery-ujs#423. I made another comment though.

from react-webpack-rails-tutorial.

jbhatab avatar jbhatab commented on May 18, 2024

What if we package jquery_ujs with the react-webpack-server-rendering gem? Feels a little weird, but its an idea.

from react-webpack-rails-tutorial.

justin808 avatar justin808 commented on May 18, 2024

@jbhatab I looked into this. It's super simple. We need to include only the ujs file in the application.js, and then have the webpack generate file expose jQuery.

from react-webpack-rails-tutorial.

justin808 avatar justin808 commented on May 18, 2024

I've outlined the issues here: http://forum.railsonmaui.com/t/considerations-for-jquery-with-rails-and-webpack/344

from react-webpack-rails-tutorial.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.