diff --git a/spec/dummy/.gitignore b/spec/dummy/.gitignore index c09620ca5..0968fbb9b 100644 --- a/spec/dummy/.gitignore +++ b/spec/dummy/.gitignore @@ -21,3 +21,8 @@ /public/webpack/* /spec/examples.txt + +# Webpack v6 installer additions +/yarn-error.log +yarn-debug.log* +.yarn-integrity diff --git a/spec/dummy/bin/webpack b/spec/dummy/bin/webpack index 0f1b9157e..2e30da830 100755 --- a/spec/dummy/bin/webpack +++ b/spec/dummy/bin/webpack @@ -1,19 +1,15 @@ #!/usr/bin/env ruby -ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development" -ENV["NODE_ENV"] ||= "development" - require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - require "bundler/setup" - require "webpacker" require "webpacker/webpack_runner" -APP_ROOT = File.expand_path("..", __dir__) +ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development" +ENV["NODE_ENV"] ||= "development" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath) +APP_ROOT = File.expand_path("..", __dir__) Dir.chdir(APP_ROOT) do Webpacker::WebpackRunner.run(ARGV) end diff --git a/spec/dummy/bin/webpack-dev-server b/spec/dummy/bin/webpack-dev-server index bfd6a9c9f..dd9662737 100755 --- a/spec/dummy/bin/webpack-dev-server +++ b/spec/dummy/bin/webpack-dev-server @@ -2,6 +2,7 @@ ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development" ENV["NODE_ENV"] ||= "development" + require "pathname" ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath) diff --git a/spec/dummy/bin/yarn b/spec/dummy/bin/yarn new file mode 100755 index 000000000..fe7338622 --- /dev/null +++ b/spec/dummy/bin/yarn @@ -0,0 +1,18 @@ +#!/usr/bin/env ruby + +APP_ROOT = File.expand_path("..", __dir__) +Dir.chdir(APP_ROOT) do + yarn = ENV["PATH"].split(File::PATH_SEPARATOR). + select { |dir| File.expand_path(dir) != __dir__ }. + product(["yarn", "yarnpkg", "yarn.cmd", "yarn.ps1"]). + map { |dir, file| File.expand_path(file, dir) }. + find { |file| File.executable?(file) } + + if yarn + exec yarn, *ARGV + else + $stderr.puts "Yarn executable was not detected in the system." + $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" + exit 1 + end +end diff --git a/spec/dummy/config/initializers/assets.rb b/spec/dummy/config/initializers/assets.rb index 1be14d32d..5b722dfa0 100644 --- a/spec/dummy/config/initializers/assets.rb +++ b/spec/dummy/config/initializers/assets.rb @@ -11,3 +11,6 @@ # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. # Rails.application.config.assets.precompile += %w( search.js ) + +# Add node_modules folder to the asset load path. +Rails.application.config.assets.paths << Rails.root.join("node_modules") diff --git a/spec/dummy/package.json b/spec/dummy/package.json index 878b40907..cee2e0c35 100644 --- a/spec/dummy/package.json +++ b/spec/dummy/package.json @@ -8,7 +8,7 @@ "private": true, "dependencies": { "@babel/preset-react": "^7.10.4", - "@rails/webpacker": "6.0.0-rc.6", + "@rails/webpacker": "^6.0.0-rc.6", "babel-plugin-macros": "^3.1.0", "babel-plugin-module-resolver": "^4.0.0", "core-js": "3", @@ -44,11 +44,14 @@ "sass-resources-loader": "^2.1.0", "style-loader": "^3.3.1", "url-loader": "^4.0.0", + "webpack": "^5.53.0", + "webpack-cli": "^4.8.0", "webpack-dev-server": "^4.5.0", "webpack-merge": "^5.1.4" }, "devDependencies": { "@pmmmwh/react-refresh-webpack-plugin": "0.4.2", + "@webpack-cli/serve": "^1.6.0", "react-refresh": "^0.8.1" }, "browser": {