From f5c34d4dafee8c3964a356da48b1b0265a582f5e Mon Sep 17 00:00:00 2001 From: Mostafa Ahangarha Date: Wed, 24 Jan 2024 11:03:00 +0330 Subject: [PATCH] Restrict css-minimizer-webpack-plugin version in the generator unless using Node v18+ (#1598) --- lib/generators/react_on_rails/base_generator.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/generators/react_on_rails/base_generator.rb b/lib/generators/react_on_rails/base_generator.rb index 996305386..ed4da51f2 100644 --- a/lib/generators/react_on_rails/base_generator.rb +++ b/lib/generators/react_on_rails/base_generator.rb @@ -91,7 +91,15 @@ def add_yarn_dependencies babel-plugin-macros" puts "Adding CSS handlers" - run "yarn add css-loader css-minimizer-webpack-plugin mini-css-extract-plugin style-loader" + + # css_minimizer_webpack_plugin version 6 only supports Nodejs v18+ + # When we bump our minimum Nodejs version to 18, we can remove this logic + # and install css_minimizer_webpack_plugin directly. + node_major_version = `node -v`.match(/^v(\d{,2})\./)[1]&.to_i + css_minimizer_webpack_plugin_version = node_major_version >= 18 ? "" : "@<6.0.0" + css_minimizer_webpack_plugin = "css-minimizer-webpack-plugin#{css_minimizer_webpack_plugin_version}" + + run "yarn add css-loader '#{css_minimizer_webpack_plugin}' mini-css-extract-plugin style-loader" puts "Adding dev dependencies" run "yarn add -D @pmmmwh/react-refresh-webpack-plugin react-refresh"