Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Jared White
    @jaredcwhite
    @fkchang I have a working webpack loader now that can load .js.rb files via imports and put them through babel and all that, so once I get that packaged up you can try that out
    Forrest Chang
    @fkchang
    @jaredcwhite coolio!
    Forrest Chang
    @fkchang
    @rubys so I'm thinking an easy way rubify ViewComponent is to use wunderbar in the call method https://github.com/github/view_component#inline-component
    and then including ruby2js via the filter there, I'm not sure that would work out the way I'd want it, I still favor the lissio syntax, but since ViewComponent is natively supported by Rails 6.1 might consider an add on vs rolling my own
    Forrest Chang
    @fkchang
    @rubys on the whimsy pointers, thanks, so it looks like it's mostly vue.js - are you doing/supporting server side rendering in whimsy?
    Sam Ruby
    @rubys
    @fkchang I ported whimsy applications from Angular to React to Vue, and they currently use Vue. I wasn't happy with Angular, was happy with React until they started playing games with their licensing so I ported to Vue. React changed their licensing back, but at that point the conversion was done.
    Jared White
    @jaredcwhite
    @/all All right, I have a very preliminary package and writeup on GitHub now: https://github.com/whitefusionhq/rb2js-loader
    Basically the idea is to have sidecar .js.rb files alongside your ViewComponent files and use something nice like LitElement to take your server-rendered markup and do something cool with it as a web component on the client
    But all that last part is opinionated—you can use the loader to load anything. I haven't tried it yet but you could probably write Stimulus controllers in Ruby if you wanted to.
    Sam Ruby
    @rubys
    Awesome!
    Jared White
    @jaredcwhite
    Let me know if you run into any snags. Still working on filing a PR for the require -> import syntax…subject to revision…
    Sam Ruby
    @rubys
    Ruby's require can only handle the simplest of JavaScript import cases
    Jared White
    @jaredcwhite
    Yeah, it's not a real require. Maybe it makes sense to stick with import and not alias to require, but I like the idea of having Ruby-familar semantics.
    Jared White
    @jaredcwhite
    I forgot JS also has require for CJS-style imports, aka const path = require("path") type statements. So I'll remove the alias and just use import so there's no conflict.
    Jared White
    @jaredcwhite
    missed a bit in the Webpack loader readme about adding rb2js.config.rb…just updated
    Sam Ruby
    @rubys
    @jaredcwhite your webpack loader could go a long way towards addressing https://twitter.com/t_a_w/status/1314285541177917446
    Jared White
    @jaredcwhite
    @rubys Yeah, I think it'd be awesome if using Ruby-syntax to write JS could become as industry-accepted as a number of other "transpile-to-JS" lanaguages
    BTW, tests are failing now…if I take the es2015 require out of tagged_templates, it passes again. Any suggestions?
    Sam Ruby
    @rubys
    @jaredcwhite I responded in github, definitely take out the require, but consider falling back to a call syntax if es2015 is not enabled.
    Forrest Chang
    @fkchang

    @rubys is there a typo in snowpack-plugin-require-context ? I get this while running yarn start

    
    /Users/fkchang/src/stimulus-starter/node_modules/@rubys/snowpack-plugin-require-context/plugin.js:70
        let recurse = args[1]?.value;
                              ^

    deleting the ? works for me, do I need a node upgrade for that line to work?

    Sam Ruby
    @rubys
    That line requires node 14. I've made a change and pushed out a version that should work with node 12. What version of node are you using?
    Forrest Chang
    @fkchang
    12.10
    Forrest Chang
    @fkchang
    @jaredcwhite so I'm trying to debug ruby2js webpack loader with Rails, how can I see the js that is getting generated? It feels like it is not reading my Rails.root/rb2js.config.rb
    Forrest Chang
    @fkchang
    I think to enable the stimulus filter I just need to require "ruby2js/filter/stimulus" in that file
    Sam Ruby
    @rubys
    @fkchang Have you enabled stimulus in your rails application? See: https://betterprogramming.pub/how-to-add-stimulus-js-to-a-rails-6-application-4201837785f9
    Forrest Chang
    @fkchang
    I have hotwire-rails gem, so I should have stimulus, I suspect that the option for the stimulus filter in my rb2js.config.rb isn't being honored from this error message foo_controller.js.rb:1 Uncaught ReferenceError: Stimulus is not defined at Object../app/javascript/controllers/foo_controller.js.rb (foo_controller.js.rb:1) at __webpack_require__ (bootstrap:63) at webpackContext (controllers sync _controller\.js\.rb$:8)
    where the source map shows
    class FooController < Stimulus::Controller
    Jared White
    @jaredcwhite
    @fkchang Hotwire-Rails doesn't use Webpack, I think? If it's relying on Sprockets, could be a mis-match there
    Forrest Chang
    @fkchang
    @jaredcwhite it does use webpacker (all the new basecamp stuff does). This is in my package.json
    This message was deleted
     "dependencies": {
        "@hotwired/turbo-rails": "^7.0.0-beta.5",
        "@rails/actioncable": "^6.0.0",
        "@rails/activestorage": "^6.0.0",
        "@rails/ujs": "^6.0.0",
        "@rails/webpacker": "5.2.1",
        "@ruby2js/webpack-loader": "^1.3.1",
        "stimulus": "^2.0.0"
      },
    Sam Ruby
    @rubys
    @fkchang can you upgrade to the latest ruby2js (4.0.2) and see if the following works for you: https://www.ruby2js.com/examples/rails/stimulus_sprockets ?
    Forrest Chang
    @fkchang
    So I figured out something, I need to do this in js import Stimulus from "stimulus" and then I don't get that compile error
    I did a js Stimulus controller and note the syntax they tend do is
    import { Controller } from  "stimulus"
    export default class SubfieldController extends Controller {
    ....
    Forrest Chang
    @fkchang
    sorry import * as Stimulus from "stimulus"
    I got a js controller to work with that, but can't seem to associate with the ruby2js controller, though the Stimulus is not defined error is gone -- how can I see the js that gets generated?
    @rubys I'll try it at first opportunity
    Forrest Chang
    @fkchang
    So I think it's getting them to load in the applications. THe way the rails app is setup we do this to load the js stimulus controllers
    import { Application } from "stimulus"
    import { definitionsFromContext } from "stimulus/webpack-helpers"
    
    const application = Application.start()
    const context = require.context("controllers", true, /_controller\.js$/)
    application.load(definitionsFromContext(context))
    Forrest Chang
    @fkchang
    To load the ruby2js, I tried something similar, as well as something from Jared's webpack example, neither worked, alone or together
    const rubyContext = require.context("controllers", true, /_controller\.js\.rb$/)
    
    function importAll(r) {
      r.keys().forEach(r)
    }
    importAll(rubyContext)
    application.load(definitionsFromContext(rubyContext))
    I also note that if I have a js file that includes ruby2js via the require.context.... changed ruby2js doesn't get rebuilt unless I change the js file that calls that - so not certain what the webpacker setup should be, but I'm sort of close
    Sam Ruby
    @rubys
    @fkchang I now have a stimulus webpack example posted: https://www.ruby2js.com/examples/rails/stimulus_webpacker
    Forrest Chang
    @fkchang
    @rubys got your example to work, so maybe I can figure out what's different between that setup and my hotwire app. I'll note that changing the controller.js.rb doesn't cause new js to be built unless I change the index.js
    Forrest Chang
    @fkchang
    got my hotwire app working, I suspect upgrading the webpack loader to 2.0.0 did it, as my other config were largely the same and now my ruby2js stimulus controller is working
    Sam Ruby
    @rubys
    @fkchang glad to hear it. Not being able to see your application, I felt helpless. Ultimately I figured the best I could do was to show you an example that works. I'm glad that helped.
    Jared White
    @jaredcwhite
    I just popped in here to see if @rubys's latest updates did the trick, sounds like that worked for you @fkchang. Yay!
    Forrest Chang
    @fkchang
    @jaredcwhite yeah, it worked, only thing now is to figure out how to get to update the js when the js.rb file is updated. New code only gets loaded if the parent js file that loads the js.rb file gets changed
    Sam Ruby
    @rubys
    @fkchang Try adding .js.rb to config/webpacker.yml in the default.extensions section
    Forrest Chang
    @fkchang
    @rubys that did it, thx