Skip to content

Update webpacker.yml in react:install generator #1216

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

Merged
merged 3 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#### Deprecation

#### Bug Fixes
- Fix installation crash caused by absolute path for `source_entry_path` in default `config/webpacker.yml` coming from `shakapacker` version 6.x - #1216

## 2.6.2

Expand Down
18 changes: 18 additions & 0 deletions lib/generators/react/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ class InstallGenerator < ::Rails::Generators::Base
default: false,
desc: "Don't generate server_rendering.js or config/initializers/react_server_rendering.rb"

# For Shakapacker below version 7, we need to set relative path for source_entry_path
def modify_webpacker_yml
webpacker_yml_path = 'config/webpacker.yml'
if webpacker? && Pathname.new(webpacker_yml_path).exist?
gsub_file(
webpacker_yml_path,
"source_entry_path: /\n",
"source_entry_path: packs\n"
)
reloaded_webpacker_config
end
end

# Make an empty `components/` directory in the right place:
def create_directory
components_dir = if webpacker?
Expand Down Expand Up @@ -119,6 +132,11 @@ def webpack_source_path
Webpacker::Configuration.source_path.join(Webpacker::Configuration.entry_path) # Webpacker <3
end
end

def reloaded_webpacker_config
Webpacker.instance.instance_variable_set(:@config, nil)
Webpacker.config
end
end
end
end