Skip to content

How to configure the generation of a server rendering output file? #732

@justin808

Description

@justin808

Need

We need different env specific output configurations for server rendering.

Possible Solution

We can make different configuration options in webpacker.yml and the stub webpack config files that vary based on the Rails/Node Env (production vs. development vs. test).

For server rendering files, could we have some configuration of the entry file (or files) and where they get output, as well as differences in the webpack config?

So rather than having the webpack config named webpack/production.js, could we allow webpack/server/production.js or webpack/production.server.js?

For the webpacker.yml file, could we have a subsection called server under each env, like we have the dev_server section.

Like:

production:
  server:
   # These must be different than the defaults for client rendering. These files are not available 
   # in the view helpers. These are only available in the `Webpacker::Manifest#lookup` method,
   # specifying the option for the server bundle
   source_entry_path: packs
   public_output_path: packs

Server rendering code (for something like React on Rails):

Rails.root.join(File.join("public", Webpacker.manifest.lookup(bundle_name, server: true))).to_s

Note, the choice of an additional option server: true to lookup for server rendering. The option name "server" could be configurable. That being said, in many years of React on Rails, we came to the conclusion that only having ONE server rendering bundle makes sense, while for the client, we need to have lazily loaded small bundles.

Notes

  • We can't have two watch processes writing to the same manifest.json.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions