webpacker 5.4.4 → 6.0.0.rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.eslintrc.js +1 -1
- data/.github/workflows/jest.yml +7 -15
- data/.github/workflows/js-lint.yml +7 -15
- data/.github/workflows/rubocop.yml +1 -1
- data/.github/workflows/ruby.yml +18 -16
- data/.gitignore +2 -0
- data/.node-version +1 -1
- data/.rubocop.yml +5 -7
- data/CHANGELOG.md +30 -12
- data/CONTRIBUTING.md +20 -1
- data/Gemfile.lock +83 -83
- data/README.md +389 -179
- data/config/README.md +3 -0
- data/config/webpacker.yml +1 -0
- data/docs/deployment.md +9 -11
- data/docs/developing_webpacker.md +29 -0
- data/docs/troubleshooting.md +61 -25
- data/docs/v6_upgrade.md +113 -0
- data/gemfiles/Gemfile-rails.6.1.x +12 -0
- data/lib/install/{javascript/packs/application.js → application.js} +2 -5
- data/lib/install/bin/webpack +4 -7
- data/lib/install/bin/yarn +18 -0
- data/lib/install/config/webpack/base.js +3 -0
- data/lib/install/config/webpack/development.js +2 -2
- data/lib/install/config/webpack/production.js +2 -2
- data/lib/install/config/webpack/test.js +2 -2
- data/lib/install/config/webpacker.yml +21 -49
- data/lib/install/package.json +15 -0
- data/lib/install/template.rb +64 -29
- data/lib/tasks/webpacker/binstubs.rake +6 -4
- data/lib/tasks/webpacker/check_binstubs.rake +4 -4
- data/lib/tasks/webpacker/check_node.rake +3 -0
- data/lib/tasks/webpacker/check_yarn.rake +3 -0
- data/lib/tasks/webpacker/clobber.rake +1 -1
- data/lib/tasks/webpacker/compile.rake +4 -2
- data/lib/tasks/webpacker/info.rake +12 -10
- data/lib/tasks/webpacker/install.rake +6 -4
- data/lib/tasks/webpacker/verify_config.rake +14 -0
- data/lib/tasks/webpacker/verify_install.rake +1 -10
- data/lib/tasks/webpacker/yarn_install.rake +9 -7
- data/lib/tasks/webpacker.rake +2 -11
- data/lib/tasks/yarn.rake +38 -0
- data/lib/webpacker/commands.rb +21 -16
- data/lib/webpacker/compiler.rb +16 -9
- data/lib/webpacker/configuration.rb +8 -32
- data/lib/webpacker/dev_server.rb +6 -0
- data/lib/webpacker/dev_server_runner.rb +28 -4
- data/lib/webpacker/helper.rb +47 -81
- data/lib/webpacker/instance.rb +4 -0
- data/lib/webpacker/manifest.rb +2 -3
- data/lib/webpacker/railtie.rb +8 -2
- data/lib/webpacker/runner.rb +1 -1
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +29 -3
- data/lib/webpacker.rb +1 -1
- data/package/__tests__/config.js +5 -37
- data/package/__tests__/development.js +13 -21
- data/package/__tests__/env.js +16 -4
- data/package/__tests__/index.js +9 -0
- data/package/__tests__/production.js +6 -6
- data/package/__tests__/staging.js +7 -6
- data/package/__tests__/test.js +4 -5
- data/package/babel/preset.js +54 -0
- data/package/config.js +6 -14
- data/package/env.js +13 -4
- data/package/environments/__tests__/base.js +20 -52
- data/package/environments/base.js +68 -128
- data/package/environments/development.js +49 -47
- data/package/environments/production.js +66 -64
- data/package/environments/test.js +2 -2
- data/package/index.js +15 -8
- data/package/inliningCss.js +7 -0
- data/package/rules/babel.js +10 -8
- data/package/rules/coffee.js +6 -0
- data/package/rules/erb.js +15 -0
- data/package/rules/file.js +21 -19
- data/package/rules/index.js +16 -18
- data/package/rules/less.js +22 -0
- data/package/rules/raw.js +5 -0
- data/package/rules/sass.js +9 -10
- data/package/rules/stylus.js +26 -0
- data/package/utils/get_style_rule.js +28 -36
- data/package/utils/helpers.js +28 -35
- data/package.json +18 -38
- data/test/command_test.rb +76 -0
- data/test/compiler_test.rb +0 -12
- data/test/configuration_test.rb +4 -35
- data/test/dev_server_runner_test.rb +36 -6
- data/test/engine_rake_tasks_test.rb +39 -0
- data/test/helper_test.rb +79 -77
- data/test/manifest_test.rb +16 -0
- data/test/mounted_app/Rakefile +4 -0
- data/test/mounted_app/test/dummy/Rakefile +3 -0
- data/test/mounted_app/test/dummy/bin/rails +3 -0
- data/test/mounted_app/test/dummy/bin/rake +3 -0
- data/test/mounted_app/test/dummy/config/application.rb +10 -0
- data/test/mounted_app/test/dummy/config/environment.rb +3 -0
- data/test/mounted_app/test/dummy/config/webpacker.yml +75 -0
- data/test/mounted_app/test/dummy/config.ru +5 -0
- data/test/mounted_app/test/dummy/package.json +7 -0
- data/test/rake_tasks_test.rb +1 -10
- data/test/test_app/app/{javascript/packs → packs/entrypoints}/application.js +1 -1
- data/test/test_app/config/initializers/inspect_autoload_paths.rb +1 -0
- data/test/test_app/config/webpacker.yml +5 -31
- data/test/test_app/config/webpacker_other_location.yml +79 -0
- data/test/test_app/config/webpacker_public_root.yml +0 -1
- data/test/test_app/public/packs/manifest.json +36 -18
- data/test/test_app/some.config.js +0 -0
- data/test/webpack_runner_test.rb +9 -3
- data/test/webpacker_test.rb +21 -0
- data/webpacker.gemspec +2 -2
- data/yarn.lock +1277 -4620
- metadata +63 -92
- data/docs/assets.md +0 -119
- data/docs/cloud9.md +0 -310
- data/docs/css.md +0 -308
- data/docs/docker.md +0 -68
- data/docs/engines.md +0 -213
- data/docs/env.md +0 -63
- data/docs/es6.md +0 -72
- data/docs/folder-structure.md +0 -66
- data/docs/integrations.md +0 -220
- data/docs/misc.md +0 -23
- data/docs/props.md +0 -223
- data/docs/target.md +0 -22
- data/docs/testing.md +0 -136
- data/docs/typescript.md +0 -190
- data/docs/v4-upgrade.md +0 -142
- data/docs/webpack-dev-server.md +0 -92
- data/docs/webpack.md +0 -364
- data/docs/yarn.md +0 -23
- data/lib/install/angular.rb +0 -23
- data/lib/install/coffee.rb +0 -25
- data/lib/install/config/.browserslistrc +0 -1
- data/lib/install/config/babel.config.js +0 -82
- data/lib/install/config/postcss.config.js +0 -12
- data/lib/install/config/webpack/environment.js +0 -3
- data/lib/install/elm.rb +0 -39
- data/lib/install/erb.rb +0 -25
- data/lib/install/examples/angular/hello_angular/app/app.component.ts +0 -9
- data/lib/install/examples/angular/hello_angular/app/app.module.ts +0 -16
- data/lib/install/examples/angular/hello_angular/index.ts +0 -8
- data/lib/install/examples/angular/hello_angular/polyfills.ts +0 -73
- data/lib/install/examples/angular/hello_angular.js +0 -7
- data/lib/install/examples/coffee/hello_coffee.coffee +0 -4
- data/lib/install/examples/elm/Main.elm +0 -55
- data/lib/install/examples/elm/hello_elm.js +0 -16
- data/lib/install/examples/erb/hello_erb.js.erb +0 -6
- data/lib/install/examples/react/babel.config.js +0 -99
- data/lib/install/examples/react/hello_react.jsx +0 -26
- data/lib/install/examples/react/tsconfig.json +0 -21
- data/lib/install/examples/stimulus/application.js +0 -1
- data/lib/install/examples/stimulus/controllers/hello_controller.js +0 -18
- data/lib/install/examples/stimulus/controllers/index.js +0 -9
- data/lib/install/examples/svelte/app.svelte +0 -11
- data/lib/install/examples/svelte/hello_svelte.js +0 -20
- data/lib/install/examples/typescript/hello_typescript.ts +0 -4
- data/lib/install/examples/typescript/tsconfig.json +0 -24
- data/lib/install/examples/vue/app.vue +0 -22
- data/lib/install/examples/vue/hello_vue.js +0 -72
- data/lib/install/loaders/coffee.js +0 -6
- data/lib/install/loaders/elm.js +0 -25
- data/lib/install/loaders/erb.js +0 -11
- data/lib/install/loaders/svelte.js +0 -9
- data/lib/install/loaders/vue.js +0 -6
- data/lib/install/react.rb +0 -18
- data/lib/install/stimulus.rb +0 -12
- data/lib/install/svelte.rb +0 -29
- data/lib/install/typescript.rb +0 -39
- data/lib/install/vue.rb +0 -49
- data/lib/tasks/installers.rake +0 -42
- data/package/config_types/__tests__/config_list.js +0 -118
- data/package/config_types/__tests__/config_object.js +0 -43
- data/package/config_types/config_list.js +0 -75
- data/package/config_types/config_object.js +0 -55
- data/package/config_types/index.js +0 -7
- data/package/rules/module.css.js +0 -3
- data/package/rules/module.sass.js +0 -8
- data/package/rules/node_modules.js +0 -22
- data/package/utils/__tests__/deep_assign.js +0 -32
- data/package/utils/__tests__/deep_merge.js +0 -10
- data/package/utils/__tests__/get_style_rule.js +0 -65
- data/package/utils/__tests__/objectify.js +0 -9
- data/package/utils/deep_assign.js +0 -22
- data/package/utils/deep_merge.js +0 -22
- data/package/utils/objectify.js +0 -3
- /data/test/test_app/app/{javascript/packs → packs/entrypoints}/multi_entry.css +0 -0
- /data/test/test_app/app/{javascript/packs → packs/entrypoints}/multi_entry.js +0 -0
data/lib/install/template.rb
CHANGED
|
@@ -1,29 +1,23 @@
|
|
|
1
1
|
# Install Webpacker
|
|
2
2
|
copy_file "#{__dir__}/config/webpacker.yml", "config/webpacker.yml"
|
|
3
|
+
copy_file "#{__dir__}/package.json", "package.json"
|
|
3
4
|
|
|
4
5
|
say "Copying webpack core config"
|
|
5
6
|
directory "#{__dir__}/config/webpack", "config/webpack"
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
say "Copying babel.config.js to app root directory"
|
|
11
|
-
copy_file "#{__dir__}/config/babel.config.js", "babel.config.js"
|
|
12
|
-
|
|
13
|
-
say "Copying .browserslistrc to app root directory"
|
|
14
|
-
copy_file "#{__dir__}/config/.browserslistrc", ".browserslistrc"
|
|
15
|
-
|
|
16
|
-
if Dir.exist?(Webpacker.config.source_path)
|
|
17
|
-
say "The JavaScript app source directory already exists"
|
|
8
|
+
if Dir.exists?(Webpacker.config.source_path)
|
|
9
|
+
say "The packs app source directory already exists"
|
|
18
10
|
else
|
|
19
|
-
say "Creating
|
|
20
|
-
|
|
11
|
+
say "Creating packs app source directory"
|
|
12
|
+
empty_directory "app/javascript"
|
|
13
|
+
copy_file "#{__dir__}/application.js", "app/javascript/application.js"
|
|
21
14
|
end
|
|
22
15
|
|
|
23
16
|
apply "#{__dir__}/binstubs.rb"
|
|
24
17
|
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
git_ignore_path = Rails.root.join(".gitignore")
|
|
19
|
+
if File.exists?(git_ignore_path)
|
|
20
|
+
append_to_file git_ignore_path do
|
|
27
21
|
"\n" +
|
|
28
22
|
"/public/packs\n" +
|
|
29
23
|
"/public/packs-test\n" +
|
|
@@ -34,24 +28,62 @@ if File.exist?(".gitignore")
|
|
|
34
28
|
end
|
|
35
29
|
end
|
|
36
30
|
|
|
37
|
-
if
|
|
38
|
-
say "
|
|
39
|
-
|
|
31
|
+
if (app_layout_path = Rails.root.join("app/views/layouts/application.html.erb")).exist?
|
|
32
|
+
say "Add JavaScript include tag in application layout"
|
|
33
|
+
insert_into_file app_layout_path.to_s, %(\n <%= javascript_pack_tag "application" %>), before: /\s*<\/head>/
|
|
40
34
|
else
|
|
41
|
-
say "
|
|
42
|
-
|
|
35
|
+
say "Default application.html.erb is missing!", :red
|
|
36
|
+
say %( Add <%= javascript_pack_tag "application" %> within the <head> tag in your custom layout.)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
if (setup_path = Rails.root.join("bin/setup")).exist?
|
|
40
|
+
say "Run bin/yarn during bin/setup"
|
|
41
|
+
insert_into_file setup_path.to_s, <<-RUBY, after: %( system("bundle check") || system!("bundle install")\n)
|
|
42
|
+
|
|
43
|
+
# Install JavaScript dependencies
|
|
44
|
+
system! "bin/yarn"
|
|
45
|
+
RUBY
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
if (asset_config_path = Rails.root.join("config/initializers/assets.rb")).exist?
|
|
49
|
+
say "Add node_modules to the asset load path"
|
|
50
|
+
append_to_file asset_config_path, <<-RUBY
|
|
51
|
+
|
|
52
|
+
# Add node_modules folder to the asset load path.
|
|
53
|
+
Rails.application.config.assets.paths << Rails.root.join("node_modules")
|
|
54
|
+
RUBY
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
if (csp_config_path = Rails.root.join("config/initializers/content_security_policy.rb")).exist?
|
|
58
|
+
say "Make note of webpack-dev-server exemption needed to csp"
|
|
59
|
+
insert_into_file csp_config_path, <<-RUBY, after: %(# Rails.application.config.content_security_policy do |policy|)
|
|
60
|
+
# # If you are using webpack-dev-server then specify webpack-dev-server host
|
|
61
|
+
# policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development?
|
|
62
|
+
RUBY
|
|
43
63
|
end
|
|
44
64
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
65
|
+
results = []
|
|
66
|
+
|
|
67
|
+
Dir.chdir(Rails.root) do
|
|
68
|
+
if Webpacker::VERSION.match?(/^[0-9]+\.[0-9]+\.[0-9]+$/)
|
|
69
|
+
say "Installing all JavaScript dependencies [#{Webpacker::VERSION}]"
|
|
70
|
+
results << run("yarn add @rails/webpacker@#{Webpacker::VERSION}")
|
|
71
|
+
else
|
|
72
|
+
say "Installing all JavaScript dependencies [from prerelease rails/webpacker]"
|
|
73
|
+
results << run("yarn add @rails/webpacker@next")
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
package_json = File.read("#{__dir__}/../../package.json")
|
|
77
|
+
webpack_version = package_json.match(/"webpack": "(.*)"/)[1]
|
|
78
|
+
webpack_cli_version = package_json.match(/"webpack-cli": "(.*)"/)[1]
|
|
48
79
|
|
|
49
|
-
# needed for experimental Yarn 2 support and should not harm Yarn 1
|
|
50
|
-
say "Installing webpack and webpack-cli as direct dependencies"
|
|
51
|
-
run
|
|
80
|
+
# needed for experimental Yarn 2 support and should not harm Yarn 1
|
|
81
|
+
say "Installing webpack and webpack-cli as direct dependencies"
|
|
82
|
+
results << run("yarn add webpack@#{webpack_version} webpack-cli@#{webpack_cli_version}")
|
|
52
83
|
|
|
53
|
-
say "Installing dev server for live reloading"
|
|
54
|
-
run
|
|
84
|
+
say "Installing dev server for live reloading"
|
|
85
|
+
results << run("yarn add --dev webpack-dev-server @webpack-cli/serve")
|
|
86
|
+
end
|
|
55
87
|
|
|
56
88
|
if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
|
|
57
89
|
say "You need to allow webpack-dev-server host as allowed origin for connect-src.", :yellow
|
|
@@ -60,4 +92,7 @@ if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
|
|
|
60
92
|
say "policy.connect_src :self, :https, \"http://localhost:3035\", \"ws://localhost:3035\" if Rails.env.development?", :yellow
|
|
61
93
|
end
|
|
62
94
|
|
|
63
|
-
|
|
95
|
+
unless results.all?
|
|
96
|
+
say "Webpacker installation failed 😭 See above for details.", :red
|
|
97
|
+
exit 1
|
|
98
|
+
end
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
binstubs_template_path = File.expand_path("../../install/binstubs.rb", __dir__).freeze
|
|
2
|
-
bin_path = ENV["BUNDLE_BIN"] || "
|
|
2
|
+
bin_path = ENV["BUNDLE_BIN"] || Rails.root.join("bin")
|
|
3
3
|
|
|
4
4
|
namespace :webpacker do
|
|
5
5
|
desc "Installs Webpacker binstubs in this application"
|
|
6
|
-
task binstubs: [:check_node, :check_yarn] do
|
|
6
|
+
task binstubs: [:check_node, :check_yarn] do |task|
|
|
7
|
+
prefix = task.name.split(/#|webpacker:binstubs/).first
|
|
8
|
+
|
|
7
9
|
if Rails::VERSION::MAJOR >= 5
|
|
8
|
-
exec "#{RbConfig.ruby} #{bin_path}/rails app:template LOCATION
|
|
10
|
+
exec "#{RbConfig.ruby} #{bin_path}/rails #{prefix}app:template LOCATION='#{binstubs_template_path}'"
|
|
9
11
|
else
|
|
10
|
-
exec "#{RbConfig.ruby} #{bin_path}/rake rails:template LOCATION
|
|
12
|
+
exec "#{RbConfig.ruby} #{bin_path}/rake #{prefix}rails:template LOCATION='#{binstubs_template_path}'"
|
|
11
13
|
end
|
|
12
14
|
end
|
|
13
15
|
end
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
namespace :webpacker do
|
|
2
|
-
desc "Verifies that webpack
|
|
2
|
+
desc "Verifies that bin/webpack is present"
|
|
3
3
|
task :check_binstubs do
|
|
4
|
-
unless File.exist?("bin/webpack")
|
|
5
|
-
$stderr.puts "webpack
|
|
4
|
+
unless File.exist?(Rails.root.join("bin/webpack"))
|
|
5
|
+
$stderr.puts "webpack binstub not found.\n"\
|
|
6
6
|
"Have you run rails webpacker:install ?\n"\
|
|
7
|
-
"Make sure the bin directory
|
|
7
|
+
"Make sure the bin directory and bin/webpack are not included in .gitignore\n"\
|
|
8
8
|
"Exiting!"
|
|
9
9
|
exit!
|
|
10
10
|
end
|
|
@@ -3,6 +3,9 @@ namespace :webpacker do
|
|
|
3
3
|
desc "Verifies if Node.js is installed"
|
|
4
4
|
task :check_node do
|
|
5
5
|
begin
|
|
6
|
+
which_command = Gem.win_platform? ? "where" : "which"
|
|
7
|
+
raise Errno::ENOENT if `#{which_command} node || #{which_command} nodejs`.strip.empty?
|
|
8
|
+
|
|
6
9
|
node_version = `node -v || nodejs -v`.strip
|
|
7
10
|
raise Errno::ENOENT if node_version.blank?
|
|
8
11
|
|
|
@@ -3,6 +3,9 @@ namespace :webpacker do
|
|
|
3
3
|
desc "Verifies if Yarn is installed"
|
|
4
4
|
task :check_yarn do
|
|
5
5
|
begin
|
|
6
|
+
which_command = Gem.win_platform? ? "where" : "which"
|
|
7
|
+
raise Errno::ENOENT if `#{which_command} yarn`.strip.empty?
|
|
8
|
+
|
|
6
9
|
yarn_version = `yarn --version`.strip
|
|
7
10
|
raise Errno::ENOENT if yarn_version.blank?
|
|
8
11
|
|
|
@@ -2,7 +2,7 @@ require "webpacker/configuration"
|
|
|
2
2
|
|
|
3
3
|
namespace :webpacker do
|
|
4
4
|
desc "Remove the webpack compiled output directory"
|
|
5
|
-
task clobber: ["webpacker:
|
|
5
|
+
task clobber: ["webpacker:verify_config", :environment] do
|
|
6
6
|
Webpacker.clobber
|
|
7
7
|
$stdout.puts "Removed webpack output path directory #{Webpacker.config.public_output_path}"
|
|
8
8
|
end
|
|
@@ -10,8 +10,10 @@ end
|
|
|
10
10
|
def enhance_assets_precompile
|
|
11
11
|
# yarn:install was added in Rails 5.1
|
|
12
12
|
deps = yarn_install_available? ? [] : ["webpacker:yarn_install"]
|
|
13
|
-
Rake::Task["assets:precompile"].enhance(deps) do
|
|
14
|
-
|
|
13
|
+
Rake::Task["assets:precompile"].enhance(deps) do |task|
|
|
14
|
+
prefix = task.name.split(/#|assets:precompile/).first
|
|
15
|
+
|
|
16
|
+
Rake::Task["#{prefix}webpacker:compile"].invoke
|
|
15
17
|
end
|
|
16
18
|
end
|
|
17
19
|
|
|
@@ -3,17 +3,19 @@ require "webpacker/version"
|
|
|
3
3
|
namespace :webpacker do
|
|
4
4
|
desc "Provide information on Webpacker's environment"
|
|
5
5
|
task :info do
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
Dir.chdir(Rails.root) do
|
|
7
|
+
$stdout.puts "Ruby: #{`ruby --version`}"
|
|
8
|
+
$stdout.puts "Rails: #{Rails.version}"
|
|
9
|
+
$stdout.puts "Webpacker: #{Webpacker::VERSION}"
|
|
10
|
+
$stdout.puts "Node: #{`node --version`}"
|
|
11
|
+
$stdout.puts "Yarn: #{`yarn --version`}"
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
$stdout.puts "\n"
|
|
14
|
+
$stdout.puts "@rails/webpacker: \n#{`npm list @rails/webpacker version`}"
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
$stdout.puts "Is bin/webpack present?: #{File.exist? 'bin/webpack'}"
|
|
17
|
+
$stdout.puts "Is bin/webpack-dev-server present?: #{File.exist? 'bin/webpack-dev-server'}"
|
|
18
|
+
$stdout.puts "Is bin/yarn present?: #{File.exist? 'bin/yarn'}"
|
|
19
|
+
end
|
|
18
20
|
end
|
|
19
21
|
end
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
install_template_path = File.expand_path("../../install/template.rb", __dir__).freeze
|
|
2
|
-
bin_path = ENV["BUNDLE_BIN"] || "
|
|
2
|
+
bin_path = ENV["BUNDLE_BIN"] || Rails.root.join("bin")
|
|
3
3
|
|
|
4
4
|
namespace :webpacker do
|
|
5
5
|
desc "Install Webpacker in this application"
|
|
6
|
-
task install: [:check_node, :check_yarn] do
|
|
6
|
+
task install: [:check_node, :check_yarn] do |task|
|
|
7
|
+
prefix = task.name.split(/#|webpacker:install/).first
|
|
8
|
+
|
|
7
9
|
if Rails::VERSION::MAJOR >= 5
|
|
8
|
-
exec "#{RbConfig.ruby} #{bin_path}/rails app:template LOCATION
|
|
10
|
+
exec "#{RbConfig.ruby} #{bin_path}/rails #{prefix}app:template LOCATION='#{install_template_path}'"
|
|
9
11
|
else
|
|
10
|
-
exec "#{RbConfig.ruby} #{bin_path}/rake rails:template LOCATION
|
|
12
|
+
exec "#{RbConfig.ruby} #{bin_path}/rake #{prefix}rails:template LOCATION='#{install_template_path}'"
|
|
11
13
|
end
|
|
12
14
|
end
|
|
13
15
|
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require "webpacker/configuration"
|
|
2
|
+
|
|
3
|
+
namespace :webpacker do
|
|
4
|
+
desc "Verifies if the Webpacker config is present"
|
|
5
|
+
task :verify_config do
|
|
6
|
+
unless Webpacker.config.config_path.exist?
|
|
7
|
+
path = Webpacker.config.config_path.relative_path_from(Pathname.new(pwd)).to_s
|
|
8
|
+
$stderr.puts "Configuration #{path} file not found. \n"\
|
|
9
|
+
"Make sure webpacker:install is run successfully before " \
|
|
10
|
+
"running dependent tasks"
|
|
11
|
+
exit!
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
require "webpacker/configuration"
|
|
2
|
-
|
|
3
1
|
namespace :webpacker do
|
|
4
2
|
desc "Verifies if Webpacker is installed"
|
|
5
|
-
task verify_install: [:check_node, :check_yarn, :check_binstubs]
|
|
6
|
-
unless Webpacker.config.config_path.exist?
|
|
7
|
-
$stderr.puts "Configuration config/webpacker.yml file not found. \n"\
|
|
8
|
-
"Make sure webpacker:install is run successfully before " \
|
|
9
|
-
"running dependent tasks"
|
|
10
|
-
exit!
|
|
11
|
-
end
|
|
12
|
-
end
|
|
3
|
+
task verify_install: [:verify_config, :check_node, :check_yarn, :check_binstubs]
|
|
13
4
|
end
|
|
@@ -5,12 +5,14 @@ namespace :webpacker do
|
|
|
5
5
|
node_env = ENV.fetch("NODE_ENV") do
|
|
6
6
|
valid_node_envs.include?(Rails.env) ? Rails.env : "production"
|
|
7
7
|
end
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
Dir.chdir(Rails.root) do
|
|
9
|
+
yarn_flags =
|
|
10
|
+
if `yarn --version`.start_with?("1")
|
|
11
|
+
"--no-progress --frozen-lockfile"
|
|
12
|
+
else
|
|
13
|
+
"--immutable"
|
|
14
|
+
end
|
|
15
|
+
system({ "NODE_ENV" => node_env }, "yarn install #{yarn_flags}")
|
|
16
|
+
end
|
|
15
17
|
end
|
|
16
18
|
end
|
data/lib/tasks/webpacker.rake
CHANGED
|
@@ -6,19 +6,10 @@ tasks = {
|
|
|
6
6
|
"webpacker:clobber" => "Removes the webpack compiled output directory",
|
|
7
7
|
"webpacker:check_node" => "Verifies if Node.js is installed",
|
|
8
8
|
"webpacker:check_yarn" => "Verifies if Yarn is installed",
|
|
9
|
-
"webpacker:check_binstubs" => "Verifies that webpack
|
|
9
|
+
"webpacker:check_binstubs" => "Verifies that bin/webpack is present",
|
|
10
10
|
"webpacker:binstubs" => "Installs Webpacker binstubs in this application",
|
|
11
11
|
"webpacker:verify_install" => "Verifies if Webpacker is installed",
|
|
12
|
-
"webpacker:yarn_install" => "Support for older Rails versions. Install all JavaScript dependencies as specified via Yarn"
|
|
13
|
-
"webpacker:install:react" => "Installs and setup example React component",
|
|
14
|
-
"webpacker:install:vue" => "Installs and setup example Vue component",
|
|
15
|
-
"webpacker:install:angular" => "Installs and setup example Angular component",
|
|
16
|
-
"webpacker:install:elm" => "Installs and setup example Elm component",
|
|
17
|
-
"webpacker:install:svelte" => "Installs and setup example Svelte component",
|
|
18
|
-
"webpacker:install:stimulus" => "Installs and setup example Stimulus component",
|
|
19
|
-
"webpacker:install:erb" => "Installs Erb loader with an example",
|
|
20
|
-
"webpacker:install:coffee" => "Installs CoffeeScript loader with an example",
|
|
21
|
-
"webpacker:install:typescript" => "Installs Typescript loader with an example"
|
|
12
|
+
"webpacker:yarn_install" => "Support for older Rails versions. Install all JavaScript dependencies as specified via Yarn"
|
|
22
13
|
}.freeze
|
|
23
14
|
|
|
24
15
|
desc "Lists all available tasks in Webpacker"
|
data/lib/tasks/yarn.rake
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Duplicate of the yarn tasks still present in Rails until Webpacker <5 have been deprecated
|
|
4
|
+
|
|
5
|
+
namespace :yarn do
|
|
6
|
+
desc "Install all JavaScript dependencies as specified via Yarn"
|
|
7
|
+
task :install do
|
|
8
|
+
begin
|
|
9
|
+
# Install only production deps when for not usual envs.
|
|
10
|
+
valid_node_envs = %w[test development production]
|
|
11
|
+
node_env = ENV.fetch("NODE_ENV") do
|
|
12
|
+
valid_node_envs.include?(Rails.env) ? Rails.env : "production"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
yarn_flags =
|
|
16
|
+
if `#{RbConfig.ruby} "#{Rails.root}/bin/yarn" --version`.start_with?("1")
|
|
17
|
+
"--no-progress --frozen-lockfile"
|
|
18
|
+
else
|
|
19
|
+
"--immutable"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
system(
|
|
23
|
+
{ "NODE_ENV" => node_env },
|
|
24
|
+
"#{RbConfig.ruby} \"#{Rails.root}/bin/yarn\" install #{yarn_flags}",
|
|
25
|
+
exception: true
|
|
26
|
+
)
|
|
27
|
+
rescue Errno::ENOENT
|
|
28
|
+
$stderr.puts "bin/yarn was not found."
|
|
29
|
+
$stderr.puts "Please run `bundle exec rails app:update:bin` to create it."
|
|
30
|
+
exit 1
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Run Yarn prior to Sprockets assets precompilation, so dependencies are available for use.
|
|
36
|
+
if Rake::Task.task_defined?("assets:precompile") && File.exist?(Rails.root.join("bin", "yarn"))
|
|
37
|
+
Rake::Task["assets:precompile"].enhance [ "yarn:install" ]
|
|
38
|
+
end
|
data/lib/webpacker/commands.rb
CHANGED
|
@@ -17,20 +17,21 @@ class Webpacker::Commands
|
|
|
17
17
|
#
|
|
18
18
|
def clean(count = 2, age = 3600)
|
|
19
19
|
if config.public_output_path.exist? && config.public_manifest_path.exist?
|
|
20
|
-
|
|
21
|
-
.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
packs
|
|
21
|
+
.map do |paths|
|
|
22
|
+
paths.map { |path| [Time.now - File.mtime(path), path] }
|
|
23
|
+
.sort
|
|
24
|
+
.reject.with_index do |(file_age, _), index|
|
|
25
|
+
file_age < age || index < count
|
|
26
|
+
end
|
|
27
|
+
.map { |_, path| path }
|
|
27
28
|
end
|
|
28
|
-
.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
.flatten
|
|
30
|
+
.compact
|
|
31
|
+
.each do |file|
|
|
32
|
+
if File.file?(file)
|
|
33
|
+
File.delete(file)
|
|
34
|
+
logger.info "Removed #{file}"
|
|
34
35
|
end
|
|
35
36
|
end
|
|
36
37
|
end
|
|
@@ -54,17 +55,21 @@ class Webpacker::Commands
|
|
|
54
55
|
end
|
|
55
56
|
|
|
56
57
|
private
|
|
57
|
-
def
|
|
58
|
+
def packs
|
|
58
59
|
all_files = Dir.glob("#{config.public_output_path}/**/*")
|
|
59
60
|
manifest_config = Dir.glob("#{config.public_manifest_path}*")
|
|
60
61
|
|
|
61
62
|
packs = all_files - manifest_config - current_version
|
|
62
|
-
packs.reject { |file| File.directory?(file) }.group_by
|
|
63
|
+
packs.reject { |file| File.directory?(file) }.group_by do |path|
|
|
64
|
+
base, _, ext = File.basename(path).scan(/(.*)(-[\da-f]+)(\.\w+)/).flatten
|
|
65
|
+
"#{File.dirname(path)}/#{base}#{ext}"
|
|
66
|
+
end.values
|
|
63
67
|
end
|
|
64
68
|
|
|
65
69
|
def current_version
|
|
66
70
|
packs = manifest.refresh.values.map do |value|
|
|
67
|
-
|
|
71
|
+
value = value["src"] if value.is_a?(Hash)
|
|
72
|
+
next unless value.is_a?(String)
|
|
68
73
|
|
|
69
74
|
File.join(config.root_path, "public", "#{value}*")
|
|
70
75
|
end.compact
|
data/lib/webpacker/compiler.rb
CHANGED
|
@@ -28,14 +28,14 @@ class Webpacker::Compiler
|
|
|
28
28
|
record_compilation_digest
|
|
29
29
|
end
|
|
30
30
|
else
|
|
31
|
-
logger.
|
|
31
|
+
logger.debug "Everything's up-to-date. Nothing to do"
|
|
32
32
|
true
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
# Returns true if all the compiled packs are up to date with the underlying asset files.
|
|
37
37
|
def fresh?
|
|
38
|
-
watched_files_digest
|
|
38
|
+
last_compilation_digest&.== watched_files_digest
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
# Returns true if the compiled packs are out of date with the underlying asset files.
|
|
@@ -53,10 +53,11 @@ class Webpacker::Compiler
|
|
|
53
53
|
|
|
54
54
|
def watched_files_digest
|
|
55
55
|
warn "Webpacker::Compiler.watched_paths has been deprecated. Set additional_paths in webpacker.yml instead." unless watched_paths.empty?
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
Dir.chdir File.expand_path(config.root_path) do
|
|
57
|
+
files = Dir[*default_watched_paths, *watched_paths].reject { |f| File.directory?(f) }
|
|
58
|
+
file_ids = files.sort.map { |f| "#{File.basename(f)}/#{Digest::SHA1.file(f).hexdigest}" }
|
|
59
|
+
Digest::SHA1.hexdigest(file_ids.join("/"))
|
|
60
|
+
end
|
|
60
61
|
end
|
|
61
62
|
|
|
62
63
|
def record_compilation_digest
|
|
@@ -64,12 +65,18 @@ class Webpacker::Compiler
|
|
|
64
65
|
compilation_digest_path.write(watched_files_digest)
|
|
65
66
|
end
|
|
66
67
|
|
|
68
|
+
def optionalRubyRunner
|
|
69
|
+
bin_webpack_path = config.root_path.join("bin/webpack")
|
|
70
|
+
first_line = File.readlines(bin_webpack_path).first.chomp
|
|
71
|
+
/ruby/.match?(first_line) ? RbConfig.ruby : ""
|
|
72
|
+
end
|
|
73
|
+
|
|
67
74
|
def run_webpack
|
|
68
75
|
logger.info "Compiling..."
|
|
69
76
|
|
|
70
77
|
stdout, stderr, status = Open3.capture3(
|
|
71
78
|
webpack_env,
|
|
72
|
-
"#{
|
|
79
|
+
"#{optionalRubyRunner} ./bin/webpack",
|
|
73
80
|
chdir: File.expand_path(config.root_path)
|
|
74
81
|
)
|
|
75
82
|
|
|
@@ -90,8 +97,8 @@ class Webpacker::Compiler
|
|
|
90
97
|
|
|
91
98
|
def default_watched_paths
|
|
92
99
|
[
|
|
93
|
-
*config.
|
|
94
|
-
config.
|
|
100
|
+
*config.additional_paths,
|
|
101
|
+
"#{config.source_path}/**/*",
|
|
95
102
|
"yarn.lock", "package.json",
|
|
96
103
|
"config/webpack/**/*"
|
|
97
104
|
].freeze
|
|
@@ -23,16 +23,8 @@ class Webpacker::Configuration
|
|
|
23
23
|
root_path.join(fetch(:source_path))
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
def source_path_globbed
|
|
27
|
-
globbed_path_with_extensions(source_path.relative_path_from(root_path))
|
|
28
|
-
end
|
|
29
|
-
|
|
30
26
|
def additional_paths
|
|
31
|
-
fetch(:additional_paths)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def additional_paths_globbed
|
|
35
|
-
additional_paths.map { |p| globbed_path_with_extensions(p) }
|
|
27
|
+
fetch(:additional_paths)
|
|
36
28
|
end
|
|
37
29
|
|
|
38
30
|
def source_entry_path
|
|
@@ -59,35 +51,23 @@ class Webpacker::Configuration
|
|
|
59
51
|
root_path.join(fetch(:cache_path))
|
|
60
52
|
end
|
|
61
53
|
|
|
62
|
-
def extensions
|
|
63
|
-
fetch(:extensions)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
54
|
def check_yarn_integrity=(value)
|
|
67
|
-
warn
|
|
55
|
+
warn <<~EOS
|
|
56
|
+
Webpacker::Configuration#check_yarn_integrity=(value) is obsolete. The integrity
|
|
57
|
+
check has been removed from Webpacker (https://github.com/rails/webpacker/pull/2518)
|
|
58
|
+
so changing this setting will have no effect.
|
|
59
|
+
EOS
|
|
68
60
|
end
|
|
69
61
|
|
|
70
62
|
def webpack_compile_output?
|
|
71
63
|
fetch(:webpack_compile_output)
|
|
72
64
|
end
|
|
73
65
|
|
|
74
|
-
def
|
|
75
|
-
fetch(
|
|
66
|
+
def fetch(key)
|
|
67
|
+
data.fetch(key, defaults[key])
|
|
76
68
|
end
|
|
77
69
|
|
|
78
70
|
private
|
|
79
|
-
def resolved_paths
|
|
80
|
-
paths = data.fetch(:resolved_paths, [])
|
|
81
|
-
|
|
82
|
-
warn "The resolved_paths option has been deprecated. Use additional_paths instead." unless paths.empty?
|
|
83
|
-
|
|
84
|
-
paths
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def fetch(key)
|
|
88
|
-
data.fetch(key, defaults[key])
|
|
89
|
-
end
|
|
90
|
-
|
|
91
71
|
def data
|
|
92
72
|
@data ||= load
|
|
93
73
|
end
|
|
@@ -121,8 +101,4 @@ class Webpacker::Configuration
|
|
|
121
101
|
HashWithIndifferentAccess.new(config[env])
|
|
122
102
|
end
|
|
123
103
|
end
|
|
124
|
-
|
|
125
|
-
def globbed_path_with_extensions(path)
|
|
126
|
-
"#{path}/**/*{#{extensions.join(',')}}"
|
|
127
|
-
end
|
|
128
104
|
end
|
data/lib/webpacker/dev_server.rb
CHANGED
|
@@ -51,12 +51,18 @@ class Webpacker::DevServer
|
|
|
51
51
|
fetch(:pretty)
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
+
def hmr?
|
|
55
|
+
fetch(:hmr)
|
|
56
|
+
end
|
|
57
|
+
|
|
54
58
|
def env_prefix
|
|
55
59
|
config.dev_server.fetch(:env_prefix, DEFAULT_ENV_PREFIX)
|
|
56
60
|
end
|
|
57
61
|
|
|
58
62
|
private
|
|
59
63
|
def fetch(key)
|
|
64
|
+
return nil unless config.dev_server.present?
|
|
65
|
+
|
|
60
66
|
ENV["#{env_prefix}_#{key.upcase}"] || config.dev_server.fetch(key, defaults[key])
|
|
61
67
|
end
|
|
62
68
|
|