Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate .yml files into webpacker.yml #403

Merged
merged 27 commits into from
May 22, 2017
Merged

Consolidate .yml files into webpacker.yml #403

merged 27 commits into from
May 22, 2017

Conversation

gauravtiwari
Copy link
Member

@gauravtiwari gauravtiwari commented May 20, 2017

Consolidates and flatten all webpacker settings into one yml file - config/webpacker.yml so we have a single source for configuration of instead multiple files, which made things a bit confusing earlier.

  source_path: app/javascript
  source_entry_path: packs
  public_output_path: packs
  
  development: 
    # Only under development
    dev_server:
      host: 0.0.0.0
      port: 8080
      https: false

This is a breaking change and requires a re-install also don't forget to cleanup old files.

bundle update webpacker
bundle exec rails webpacker:install

# Remove old/unused configuration files
rm config/webpack/paths.yml
rm config/webpack/development.server.yml
rm config/webpack/development.server.js
  • Update ARGV support for webpack-dev-server binstub so you can override dev server host and port from command line. By default 0.0.0.0 is used as host. Also, a new https option is added as well for platforms like cloud9 - https://community.c9.io/t/running-a-rails-app/1615
./bin/webpack-dev-server --host 0.0.0.0
  • Update webpacker:compile task to use stdout and stderr for logging - Related to #395

screen shot 2017-05-22 at 16 43 21

screen shot 2017-05-22 at 16 44 42

  • Add new changes to README
  • Update Changelog

@gauravtiwari gauravtiwari requested a review from javan May 20, 2017 17:46
Setup eager_load

Minor cleanup

Remove behind the scenes

Update template installer

Use filename

Install webpack loader as dependency

Fix spacing

Add watchtoptions

Remove hot

Remove ARGV for dev server

Put back colors

Oops use nil

Use cheap-module-source-map

Minor cleanup

Refactor

Change to default_settings
dev_server = yaml_config["devServer"]

WEBPACK_CONFIG = File.join(APP_PATH, paths["config"], "development.js")
DEV_SERVER_HOST = "http#{"s" if dev_server["https"]}://#{dev_server["host"]}:#{dev_server["port"]}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of dropping ARGV entirely, maybe we should parse it and use the relevant options when supplied. Something along the lines of #{options["host"] || dev_server["host"]}. WDYT?


default: &default
devServer: # https://webpack.js.org/configuration/dev-server/
enabled: true # Enabled by default in development
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we using this option anywhere? What's it supposed to do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, we are not using this anymore after #397. Will remove 👍

end

def fetch(key)
paths.fetch(key, default_paths[key])
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This provided a fallback to the default on a per-key basis. With your change it will only use the default if the entire paths object is absent in an app's webpacker.yml.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh yes, but this will still read from the default config file so this would't be a problem right? Probably missing something

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before, if paths.output was missing in my webpacker.yml file, it would use the default. Now it will only use the default if paths is entirely missing.

- .svg
- .gif
- .jpeg
- .jpg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT about moving extensions out of paths?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense I think 👍

# Note: You must restart bin/webpack-dev-server for changes to take effect

default: &default
devServer: # https://webpack.js.org/configuration/dev-server/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelCase is uncommon in other .yml files. Maybe rename to dev_server?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix 👍

devServer:
host: example.com
port:
https: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for adding this? Seems like it's encouraging use in production.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some folks are using custom domain + https. Perhaps, I will change this to a dev domain.

Related to #319

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#319 is about using https in development mode if I'm reading it correctly. This is the production config.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh yes my bad, mixed it up with this one - #176. Changed it to 0.0.0.0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't think we should provide any different dev_server options in production. Doing so suggests that we encourage running it in production, which probably isn't a good idea. People can customize if needed.

<<: *default

paths:
manifest: manifest-test.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it'd be better to use output: packs-test instead of a different manifest? Then you won't end up with a mix of compiled .js files.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix 👍


paths:
output: packs-test
manifest: manifest-test.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we need a different manifest filename if the files are all in separate dir.

entry: packs # ~/:source/:entry
output: packs # ~/public/:output
manifest: manifest.json # ~/public/:output/:manifest
config: config/webpack # ~/:config
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to propose a flattened set of options that drops paths entirely and helps clarifies each option's meaning (the fact that I added the ~ legend is a smell):

 source_path: app/javascript
 source_entry_path: packs
 public_output_path: packs

In doing so, we'd drop the manifest and config options. I'm not sure why you'd want/need to change those, but I'm open to keeping them if there's a compelling reason to.

Copy link
Member Author

@gauravtiwari gauravtiwari May 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense and since the output directory can be modified the manifest can remain same 👍 Yep, was thinking same for config option - can't think of a scenario this will need changing in any app.

Copy link
Member Author

@gauravtiwari gauravtiwari May 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In regards to removing paths, I feel it's much nicer to keep it under some namespace like we have for dev-server - keeps it consistent and clean. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we should probably flatten all of the namespaces. They don't merge into the environments like you'd expect:

>> config = YAML.load_file("webpacker.yml")

>> config["default"]["paths"]
=> {"source"=>"app/javascript", "entry"=>"packs", "output"=>"packs", "manifest"=>"manifest.json", "config"=>"config/webpack"}

>> config["test"]["paths"]
=> {"output"=>"packs-test"}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the dev server options should be flattened to dev_server_host: ..., dev_server_port: ..., etc. if we want to pick and choose options to override within each env.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yepp, that would work 👍 Although a bit repetitive and verbose if we start to have many options, especially for the dev server -dev_server-host, dev_server_port, dev_server_hot, dev_server_https. Namespace gives a bit flexibility on the JS side too - it's easy to extract objects using - { dev_server, paths }

default: &default
  dev_server_host: localhost           
  dev_server_port: 8080
  dev_server_https: false
  dev_server_hot: false
                
  source_path: app/javascript  
  source_entry_path: packs        
  public_output_path: packs     

VS

default: &default
  dev_server:                 # https://webpack.js.org/configuration/dev-server/
    host: localhost           # Dev server host
    port: 8080
    https: false
    hot: false

  paths:                       # ~ = Rails.root
    source: app/javascript     # ~/:source
    entry: packs               # ~/:source/:entry
    output: packs              # ~/public/:output

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more important part is that those namespaces won't work if you want to change part of them in an environment. For example:

>> config = YAML.load("
default: &default
  paths:
    source: app/javascript
    entry: packs
    output: packs

production:
  <<: *default

  paths:
    output: foo
")
=> {"default"=>{"paths"=>{"source"=>"app/javascript", "entry"=>"packs", "output"=>"packs"}}, "production"=>{"paths"=>{"output"=>"foo"}}}
>> config["production"]["paths"]["source"]
=> nil
>> config["production"]["paths"]["entry"]
=> nil
>> config["production"]["paths"]["output"]
=> "foo"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh I see 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this ?

# Note: You must restart bin/webpack-dev-server for changes to take effect

dev_server_defaults: &dev_server_defaults  # https://webpack.js.org/configuration/dev-server/
  host: localhost                          # Dev server host
  port: 8080
  https: false

paths_defaults: &paths_defaults  # ~ = Rails.root
  source: app/javascript        # ~/:source
  entry: packs                  # ~/:source/:entry
  output: packs                 # ~/public/:output

default: &default
  dev_server:
    <<: *dev_server_defaults

  paths:
    <<: *paths_defaults

  extensions:
    - .coffee
    - .js
    - .jsx
    - .ts
    - .vue
    - .sass
    - .scss
    - .css
    - .png
    - .svg
    - .gif
    - .jpeg
    - .jpg

development:
  <<: *default

test:
  <<: *default

  paths:
    <<: *paths_defaults
    output: packs-test

production:
  <<: *default

  dev_server:
    <<: *dev_server_defaults
    host: 0.0.0.0 # Cloud9
    port: 8080
    https: true

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking again - feels like it will be much better if we just flatten it 👍

devServer: {
clientLogLevel: 'none',
host: dev_server.host,
port: dev_server.port,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add the https config here too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh it was there, will fix 👍

@gauravtiwari
Copy link
Member Author

@javan Pushed updates. Please take a look when you get a chance.

// Ref - #372


dev_server_host: 0.0.0.0
dev_server_port: 8080
dev_server_https: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My vote is to remove these alternate dev server settings from production. People can add them if they're using the dev server in production (for some reason). Also, if 0.0.0.0 works more broadly, let's use it in the default settings instead of localhost.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good 👍


module.exports = merge(sharedConfig, {
devtool: 'sourcemap',
devtool: 'cheap-module-source-map',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a necessary change or just better source map option?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommended source map option in development

default: &default
dev_server_host: 0.0.0.0
dev_server_port: 8080
dev_server_https: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking more.. Maybe we should move these options to the development config only since bin/webpack-dev-server exclusive loads config/webpack/development.js (which is the only config file containing devServer).

default: &default
  source_path: app/javascript
  source_entry_path: packs
  public_output_path: packs
  ...
  
development:
  <<: *default

  dev_server:
    host: 0.0.0.0
    port: 8080
    https: false
...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless someone wanna override it in other environment - cloud9? I guess then we would enter into the same problem we discussed earlier right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never used cloud9, but I gather that the issue in #176 in wasn't about using a different environment, just configuring the host and port. It looks like apps on cloud9 run in development mode: https://community.c9.io/t/running-a-rails-app/1615

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me neither 😄 Alright, makes sense so lets move the dev server to development only.

@gauravtiwari
Copy link
Member Author

Guess this is good to go 😄

@javan
Copy link
Contributor

javan commented May 22, 2017

Looks great! 👍

Not a new problem, but the "upgrade" process is pretty rough. Running rails webpacker:install leaves the old (and now unused) .yml / .js files lingering in config/webpack. Fixing that is for a separate PR, but might be worth mentioning in the changelog.

@javan
Copy link
Contributor

javan commented May 22, 2017

Mind adding a more detailed description of the changes to the PR?

@gauravtiwari
Copy link
Member Author

Yepp I have been thinking about that. Sure 👍

@guilleiguaran
Copy link
Member

Loving this change <3

@gauravtiwari
Copy link
Member Author

@javan Over to you 😄 👍


namespace :webpacker do
desc "Compile javascript packs using webpack for production with digests"
task compile: ["webpacker:verify_install", :environment] do
puts "Compiling webpacker assets 🎉"
new_line = "\n\n"
puts "[Webpacker] Compiling assets 🎉" + new_line
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

puts implicitly adds a newline. Do we really want 3 total? I'd prefer to drop the new_line var and just use puts on its own line where we want spacing.

@gauravtiwari
Copy link
Member Author

Just removed the whole thing - thought it would look better but think it looks alright anyway 😄

@javan
Copy link
Contributor

javan commented May 22, 2017

lgtm, merge away!

@gauravtiwari gauravtiwari merged commit 158987a into rails:master May 22, 2017
@gauravtiwari gauravtiwari deleted the consolidate-yml-files branch May 22, 2017 16:23
@gauravtiwari
Copy link
Member Author

And merged 🎉 Thanks @javan 👍 Now will update the README so @dhh can make a new release

@jfly
Copy link
Contributor

jfly commented Jul 21, 2017

This is a breaking change and requires a re-install also don't forget to cleanup old files.

bundle update webpacker
bundle exec rails webpacker:install

# Remove old/unused configuration files
rm config/paths.yml
rm config/development.server.yml
rm config/development.server.js

I don't have any files called config/paths.yml, config/development.server.yml, or config/development.server.js. I assume these are actually the files in the config/webpack directory.

@gauravtiwari
Copy link
Member Author

@jfly Yepp that's correct - https://github.com/rails/webpacker/blob/master/CHANGELOG.md#breaking-change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants