Skip to content

Commit 1025987

Browse files
authored
Update webpacker.yml in react:install generator (#1216)
* Update webpacker.yml in install generator The default `config/webpacker.yml` on `shakapacker` version 6.x is set to absolute path of `/` which points to root of the filesystem. This breaks installation process of react-rails. This commit is a workaround for Shakapacker 6.x. Version 7 is expected to resolve this issue. * Update changelog * Update config file if it exists Signed-off-by: Mostafa Ahangarha <[email protected]>
1 parent c54b601 commit 1025987

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#### Deprecation
1111

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

1415
## 2.6.2
1516

lib/generators/react/install_generator.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ class InstallGenerator < ::Rails::Generators::Base
1616
default: false,
1717
desc: "Don't generate server_rendering.js or config/initializers/react_server_rendering.rb"
1818

19+
# For Shakapacker below version 7, we need to set relative path for source_entry_path
20+
def modify_webpacker_yml
21+
webpacker_yml_path = 'config/webpacker.yml'
22+
if webpacker? && Pathname.new(webpacker_yml_path).exist?
23+
gsub_file(
24+
webpacker_yml_path,
25+
"source_entry_path: /\n",
26+
"source_entry_path: packs\n"
27+
)
28+
reloaded_webpacker_config
29+
end
30+
end
31+
1932
# Make an empty `components/` directory in the right place:
2033
def create_directory
2134
components_dir = if webpacker?
@@ -119,6 +132,11 @@ def webpack_source_path
119132
Webpacker::Configuration.source_path.join(Webpacker::Configuration.entry_path) # Webpacker <3
120133
end
121134
end
135+
136+
def reloaded_webpacker_config
137+
Webpacker.instance.instance_variable_set(:@config, nil)
138+
Webpacker.config
139+
end
122140
end
123141
end
124142
end

0 commit comments

Comments
 (0)