-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Consolidate .yml files into webpacker.yml #403
Conversation
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"]}" |
There was a problem hiding this comment.
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?
lib/install/config/webpacker.yml
Outdated
|
||
default: &default | ||
devServer: # https://webpack.js.org/configuration/dev-server/ | ||
enabled: true # Enabled by default in development |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 👍
lib/webpacker/configuration.rb
Outdated
end | ||
|
||
def fetch(key) | ||
paths.fetch(key, default_paths[key]) | ||
end |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
lib/install/config/webpacker.yml
Outdated
- .svg | ||
- .gif | ||
- .jpeg | ||
- .jpg |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense I think 👍
lib/install/config/webpacker.yml
Outdated
# Note: You must restart bin/webpack-dev-server for changes to take effect | ||
|
||
default: &default | ||
devServer: # https://webpack.js.org/configuration/dev-server/ |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix 👍
lib/install/config/webpacker.yml
Outdated
devServer: | ||
host: example.com | ||
port: | ||
https: true |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
lib/install/config/webpacker.yml
Outdated
<<: *default | ||
|
||
paths: | ||
manifest: manifest-test.json |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix 👍
lib/install/config/webpacker.yml
Outdated
|
||
paths: | ||
output: packs-test | ||
manifest: manifest-test.json |
There was a problem hiding this comment.
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.
lib/install/config/webpacker.yml
Outdated
entry: packs # ~/:source/:entry | ||
output: packs # ~/public/:output | ||
manifest: manifest.json # ~/public/:output/:manifest | ||
config: config/webpack # ~/:config |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh I see 👍
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 👍
lib/install/config/webpacker.yml
Outdated
|
||
dev_server_host: 0.0.0.0 | ||
dev_server_port: 8080 | ||
dev_server_https: true |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
lib/install/config/webpacker.yml
Outdated
default: &default | ||
dev_server_host: 0.0.0.0 | ||
dev_server_port: 8080 | ||
dev_server_https: false |
There was a problem hiding this comment.
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
...
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Guess this is good to go 😄 |
Looks great! 👍 Not a new problem, but the "upgrade" process is pretty rough. Running |
Mind adding a more detailed description of the changes to the PR? |
Yepp I have been thinking about that. Sure 👍 |
Loving this change <3 |
@javan Over to you 😄 👍 |
lib/tasks/webpacker/compile.rake
Outdated
|
||
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 |
There was a problem hiding this comment.
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.
Just removed the whole thing - thought it would look better but think it looks alright anyway 😄 |
lgtm, merge away! |
I don't have any files called |
@jfly Yepp that's correct - https://github.com/rails/webpacker/blob/master/CHANGELOG.md#breaking-change |
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.This is a breaking change and requires a re-install also don't forget to cleanup old files.
0.0.0.0
is used as host. Also, a newhttps
option is added as well for platforms like cloud9 - https://community.c9.io/t/running-a-rails-app/1615webpacker:compile
task to usestdout
andstderr
for logging - Related to #395