GithubHelp home page GithubHelp logo

Comments (12)

justin808 avatar justin808 commented on July 3, 2024

I've got a super simple alternative to start. Let's have a big warning message if the webpack processes are not running when an env starts up:

pgrep -fl webpack

results in this:

41545 node /Users/justin/shakacode/react_on_rails/spec/dummy/client/node_modules/.bin/webpack -w --config webpack.server.js
41546 node /Users/justin/shakacode/react_on_rails/spec/dummy/client/node_modules/.bin/webpack -w --config webpack.client.js

We don't necessarily know the config files from the setup, but we could get that.

@alexfedoseev Would it be desirable to have one webpack file generate different bundles for client and server, rather than separate config files?

@samnang This is a super fast change to make and then we are not supporting functionality that's not part of foreman.

from react_on_rails.

jbhatab avatar jbhatab commented on July 3, 2024

@justin808 I like the idea of one config for webpack.

Also I was looking at forks and it seemed like a way to background tasks while the app is running, but I didn't see how you hook it into the rails server start. Is this possible?

from react_on_rails.

justin808 avatar justin808 commented on July 3, 2024

We got some good info here:
http://parley.rubyrogues.com/t/invoking-subprocess-in-from-ruby/3318/5?u=railsonmaui


tmoore

Tim Moore, incrementalism.net

We've started doing something like this recently on my team at work. We're spawning a node process from the Rails app using the daemon_controller gem and then communicating to it over a pipe.

The code is here:

https://github.com/jsdf/webpack_rails
https://github.com/jsdf/ruby_node_task

It's still early days, and the code isn't heavily documented or used much outside our team, but we have been running with it for a few weeks and it has done a lot to give us the best of both worlds: Sprockets-style convenience and a modern front-end tool chain.

I'd love to see more people using and contributing to this.

from react_on_rails.

justin808 avatar justin808 commented on July 3, 2024

Got more info from the Ruby Rogues forum:

rob1 rob1
September 21
A simple fork should do what you want. Open file handles will be inherited by the child process, so you'll get your "standard output goes to the parent process's standard output" for free.

Something like:

if fork
  exec "webpack -w --config webpack.client.js"
else
  puts "in the parent, carrying on with my normal business"
end

from react_on_rails.

alex35mil avatar alex35mil commented on July 3, 2024

Would it be desirable to have one webpack file generate different bundles for client and server, rather than separate config files?

I'll answer this question in #96 PR (shakacode/react-webpack-rails-tutorial#96).

from react_on_rails.

justin808 avatar justin808 commented on July 3, 2024

@robwise I bet we can apply the logic of ensuring the JS is ready for tests to the problem of just running rails s. Probably pretty easy. So keeping this one open for now.

from react_on_rails.

robwise avatar robwise commented on July 3, 2024

Yep that logic should be re-usable.

from react_on_rails.

justin808 avatar justin808 commented on July 3, 2024

We probably just need the startup code to call this:

https://github.com/shakacode/react_on_rails/blob/master/lib%2Freact_on_rails%2Ftest_helper.rb#L43

    def self.ensure_assets_compiled(webpack_assets_status_checker: nil,
                                    webpack_assets_compiler: nil,
                                    webpack_process_checker: nil,
                                    client_dir: nil,
                                    compiled_dirs: nil)

      if webpack_assets_status_checker.nil?
        client_dir ||= Rails.root.join("client")
        compiled_dirs ||= ReactOnRails.configuration.generated_assets_dirs
        webpack_assets_status_checker ||=
          WebpackAssetsStatusChecker.new(client_dir: client_dir,
                                         compiled_dirs: compiled_dirs)
      end

      webpack_assets_compiler ||= WebpackAssetsCompiler.new
      webpack_process_checker ||= WebpackProcessChecker.new

      ReactOnRails::TestHelper::EnsureAssetsCompiled.new(
        webpack_assets_status_checker: webpack_assets_status_checker,
        webpack_assets_compiler: webpack_assets_compiler,
        webpack_process_checker: webpack_process_checker
      ).call
    end

We should rename the module TestHelper to BundledAssetsHelper to avoid confusion that this is only due to tests.

I'm guessing we would do this here:

https://github.com/shakacode/react_on_rails/blob/master/lib%2Freact_on_rails%2Fconfiguration.rb

module ReactOnRails
  def self.configure
    yield(configuration)
  end

from react_on_rails.

justin808 avatar justin808 commented on July 3, 2024

There's some good comments in #289 on this in regards to how https://github.com/thoughtbot/ember-cli-rails does this.

from react_on_rails.

jbhatab avatar jbhatab commented on July 3, 2024

Can we close this? I think we should just stick with foreman or letting people manually run commands.

from react_on_rails.

justin808 avatar justin808 commented on July 3, 2024

@jbhatab Yes, closing. If anybody wants to help with this, I'm happy to provide guidance.

from react_on_rails.

justin808 avatar justin808 commented on July 3, 2024

Also, for anybody reading this, it's trivial to create your own startup script for working on the non-JS code and having the script create the JS bundles before starting Rails.

from react_on_rails.

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.