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/test/command_test.rb
CHANGED
|
@@ -31,3 +31,79 @@ class CommandTest < Minitest::Test
|
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
|
+
|
|
35
|
+
class ClearCommandVersioningTest < Minitest::Test
|
|
36
|
+
def setup
|
|
37
|
+
@now = Time.parse("2021-01-01 12:34:56 UTC")
|
|
38
|
+
# Test assets to be kept and deleted, path and mtime
|
|
39
|
+
@prev_files = {
|
|
40
|
+
# recent versions to be kept with Webpacker.commands.clean(count = 2)
|
|
41
|
+
"js/application-deadbeef.js" => @now - 4000,
|
|
42
|
+
"js/common-deadbeee.js" => @now - 4002,
|
|
43
|
+
"css/common-deadbeed.css" => @now - 4004,
|
|
44
|
+
"media/images/logo-deadbeeb.css" => @now - 4006,
|
|
45
|
+
"js/application-1eadbeef.js" => @now - 8000,
|
|
46
|
+
"js/common-1eadbeee.js" => @now - 8002,
|
|
47
|
+
"css/common-1eadbeed.css" => @now - 8004,
|
|
48
|
+
"media/images/logo-1eadbeeb.css" => @now - 8006,
|
|
49
|
+
# new files to be kept with Webpacker.commands.clean(age = 3600)
|
|
50
|
+
"js/brandnew-0001.js" => @now,
|
|
51
|
+
"js/brandnew-0002.js" => @now - 10,
|
|
52
|
+
"js/brandnew-0003.js" => @now - 20,
|
|
53
|
+
"js/brandnew-0004.js" => @now - 40,
|
|
54
|
+
}.transform_keys { |path| "#{Webpacker.config.public_output_path}/#{path}" }
|
|
55
|
+
@expired_files = {
|
|
56
|
+
# old files that are outside count = 2 or age = 3600 and to be deleted
|
|
57
|
+
"js/application-0eadbeef.js" => @now - 9000,
|
|
58
|
+
"js/common-0eadbeee.js" => @now - 9002,
|
|
59
|
+
"css/common-0eadbeed.css" => @now - 9004,
|
|
60
|
+
"js/brandnew-0005.js" => @now - 3640,
|
|
61
|
+
}.transform_keys { |path| "#{Webpacker.config.public_output_path}/#{path}" }
|
|
62
|
+
@all_files = @prev_files.merge(@expired_files)
|
|
63
|
+
@dir_glob_stub = Proc.new { |arg|
|
|
64
|
+
case arg
|
|
65
|
+
when "#{Webpacker.config.public_output_path}/**/*"
|
|
66
|
+
@all_files.keys
|
|
67
|
+
else
|
|
68
|
+
[]
|
|
69
|
+
end
|
|
70
|
+
}
|
|
71
|
+
@file_mtime_stub = Proc.new { |longpath|
|
|
72
|
+
@all_files[longpath]
|
|
73
|
+
}
|
|
74
|
+
@file_delete_mock = Minitest::Mock.new
|
|
75
|
+
@expired_files.keys.each do |longpath|
|
|
76
|
+
@file_delete_mock.expect(:delete, 1, [longpath])
|
|
77
|
+
end
|
|
78
|
+
@file_delete_stub = Proc.new { |longpath|
|
|
79
|
+
if @prev_files.has_key?(longpath)
|
|
80
|
+
flunk "#{longpath} should not be deleted"
|
|
81
|
+
else
|
|
82
|
+
@file_delete_mock.delete(longpath)
|
|
83
|
+
end
|
|
84
|
+
}
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def time_and_files_stub(&proc)
|
|
88
|
+
Time.stub :now, @now do
|
|
89
|
+
Dir.stub :glob, @dir_glob_stub do
|
|
90
|
+
File.stub :directory?, false do
|
|
91
|
+
File.stub :file?, true do
|
|
92
|
+
File.stub :mtime, @file_mtime_stub do
|
|
93
|
+
File.stub :delete, @file_delete_stub do
|
|
94
|
+
yield proc
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
@file_delete_mock.verify
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def test_clean_command_with_versioned_files
|
|
105
|
+
time_and_files_stub do
|
|
106
|
+
assert Webpacker.commands.clean
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
data/test/compiler_test.rb
CHANGED
|
@@ -23,18 +23,6 @@ class CompilerTest < Minitest::Test
|
|
|
23
23
|
Webpacker.compiler.env = {}
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
def test_default_watched_paths
|
|
27
|
-
assert_equal Webpacker.compiler.send(:default_watched_paths), [
|
|
28
|
-
"app/assets/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}",
|
|
29
|
-
"/etc/yarn/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}",
|
|
30
|
-
"app/elm/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}",
|
|
31
|
-
"app/javascript/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}",
|
|
32
|
-
"yarn.lock",
|
|
33
|
-
"package.json",
|
|
34
|
-
"config/webpack/**/*"
|
|
35
|
-
]
|
|
36
|
-
end
|
|
37
|
-
|
|
38
26
|
def test_freshness
|
|
39
27
|
assert Webpacker.compiler.stale?
|
|
40
28
|
assert !Webpacker.compiler.fresh?
|
data/test/configuration_test.rb
CHANGED
|
@@ -10,17 +10,12 @@ class ConfigurationTest < Webpacker::Test
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def test_source_path
|
|
13
|
-
source_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/
|
|
13
|
+
source_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/packs").to_s
|
|
14
14
|
assert_equal source_path, @config.source_path.to_s
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
def test_source_path_globbed
|
|
18
|
-
assert_equal @config.source_path_globbed,
|
|
19
|
-
"app/javascript/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
17
|
def test_source_entry_path
|
|
23
|
-
source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/
|
|
18
|
+
source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/packs", "entrypoints").to_s
|
|
24
19
|
assert_equal @config.source_entry_path.to_s, source_entry_path
|
|
25
20
|
end
|
|
26
21
|
|
|
@@ -49,26 +44,12 @@ class ConfigurationTest < Webpacker::Test
|
|
|
49
44
|
end
|
|
50
45
|
|
|
51
46
|
def test_cache_path
|
|
52
|
-
cache_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/tmp/
|
|
47
|
+
cache_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/tmp/webpacker").to_s
|
|
53
48
|
assert_equal @config.cache_path.to_s, cache_path
|
|
54
49
|
end
|
|
55
50
|
|
|
56
51
|
def test_additional_paths
|
|
57
|
-
assert_equal @config.additional_paths, ["app/assets", "/etc/yarn", "app/elm"]
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def test_additional_paths_globbed
|
|
61
|
-
assert_equal @config.additional_paths_globbed, [
|
|
62
|
-
"app/assets/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}",
|
|
63
|
-
"/etc/yarn/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}",
|
|
64
|
-
"app/elm/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}"
|
|
65
|
-
]
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def test_extensions
|
|
69
|
-
config_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/config/webpacker.yml").to_s
|
|
70
|
-
webpacker_yml = YAML.load_file(config_path)
|
|
71
|
-
assert_equal @config.extensions, webpacker_yml["default"]["extensions"]
|
|
52
|
+
assert_equal @config.additional_paths, ["app/assets", "/etc/yarn", "some.config.js", "app/elm"]
|
|
72
53
|
end
|
|
73
54
|
|
|
74
55
|
def test_cache_manifest?
|
|
@@ -94,16 +75,4 @@ class ConfigurationTest < Webpacker::Test
|
|
|
94
75
|
assert Webpacker.config.compile?
|
|
95
76
|
end
|
|
96
77
|
end
|
|
97
|
-
|
|
98
|
-
def test_extract_css?
|
|
99
|
-
assert @config.extract_css?
|
|
100
|
-
|
|
101
|
-
with_rails_env("development") do
|
|
102
|
-
refute Webpacker.config.extract_css?
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
with_rails_env("test") do
|
|
106
|
-
refute Webpacker.config.extract_css?
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
78
|
end
|
|
@@ -5,42 +5,72 @@ class DevServerRunnerTest < Webpacker::Test
|
|
|
5
5
|
def setup
|
|
6
6
|
@original_node_env, ENV["NODE_ENV"] = ENV["NODE_ENV"], "development"
|
|
7
7
|
@original_rails_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "development"
|
|
8
|
+
@original_webpacker_config = ENV["WEBPACKER_CONFIG"]
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
def teardown
|
|
11
12
|
ENV["NODE_ENV"] = @original_node_env
|
|
12
13
|
ENV["RAILS_ENV"] = @original_rails_env
|
|
14
|
+
ENV["WEBPACKER_CONFIG"] = @original_webpacker_config
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
def test_run_cmd_via_node_modules
|
|
16
|
-
cmd = ["#{test_app_path}/node_modules/.bin/webpack
|
|
18
|
+
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js"]
|
|
17
19
|
|
|
18
20
|
verify_command(cmd, use_node_modules: true)
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
def test_run_cmd_via_yarn
|
|
22
|
-
cmd = ["yarn", "webpack
|
|
24
|
+
cmd = ["yarn", "webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js"]
|
|
23
25
|
|
|
24
26
|
verify_command(cmd, use_node_modules: false)
|
|
25
27
|
end
|
|
26
28
|
|
|
29
|
+
def test_run_cmd_argv
|
|
30
|
+
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js", "--quiet"]
|
|
31
|
+
|
|
32
|
+
verify_command(cmd, argv: ["--quiet"])
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_run_cmd_argv_with_https
|
|
36
|
+
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js", "--https"]
|
|
37
|
+
|
|
38
|
+
dev_server = Webpacker::DevServer.new({})
|
|
39
|
+
def dev_server.host; "localhost"; end
|
|
40
|
+
def dev_server.port; "3035"; end
|
|
41
|
+
def dev_server.pretty?; false; end
|
|
42
|
+
def dev_server.https?; true; end
|
|
43
|
+
def dev_server.hmr?; false; end
|
|
44
|
+
Webpacker::DevServer.stub(:new, dev_server) do
|
|
45
|
+
verify_command(cmd, argv: ["--https"])
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_environment_variables
|
|
50
|
+
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js"]
|
|
51
|
+
env = Webpacker::Compiler.env.dup
|
|
52
|
+
ENV["WEBPACKER_CONFIG"] = env["WEBPACKER_CONFIG"] = "#{test_app_path}/config/webpacker_other_location.yml"
|
|
53
|
+
env["WEBPACK_SERVE"] = "true"
|
|
54
|
+
verify_command(cmd, env: env)
|
|
55
|
+
end
|
|
56
|
+
|
|
27
57
|
private
|
|
28
58
|
def test_app_path
|
|
29
59
|
File.expand_path("test_app", __dir__)
|
|
30
60
|
end
|
|
31
61
|
|
|
32
|
-
def verify_command(cmd, use_node_modules: true)
|
|
62
|
+
def verify_command(cmd, use_node_modules: true, argv: [], env: Webpacker::Compiler.env)
|
|
33
63
|
cwd = Dir.pwd
|
|
34
64
|
Dir.chdir(test_app_path)
|
|
35
65
|
|
|
36
66
|
klass = Webpacker::DevServerRunner
|
|
37
|
-
instance = klass.new(
|
|
67
|
+
instance = klass.new(argv)
|
|
38
68
|
mock = Minitest::Mock.new
|
|
39
|
-
mock.expect(:call, nil, [
|
|
69
|
+
mock.expect(:call, nil, [env, *cmd])
|
|
40
70
|
|
|
41
71
|
klass.stub(:new, instance) do
|
|
42
72
|
instance.stub(:node_modules_bin_exist?, use_node_modules) do
|
|
43
|
-
Kernel.stub(:exec, mock) { klass.run(
|
|
73
|
+
Kernel.stub(:exec, mock) { klass.run(argv) }
|
|
44
74
|
end
|
|
45
75
|
end
|
|
46
76
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class EngineRakeTasksTest < Minitest::Test
|
|
4
|
+
def setup
|
|
5
|
+
remove_webpack_binstubs
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def teardown
|
|
9
|
+
remove_webpack_binstubs
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_task_mounted
|
|
13
|
+
output = Dir.chdir(mounted_app_path) { `rake -T` }
|
|
14
|
+
assert_includes output, "app:webpacker"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_binstubs
|
|
18
|
+
Dir.chdir(mounted_app_path) { `bundle exec rake app:webpacker:binstubs` }
|
|
19
|
+
webpack_binstub_paths.each { |path| assert File.exist?(path) }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
def mounted_app_path
|
|
24
|
+
File.expand_path("mounted_app", __dir__)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def webpack_binstub_paths
|
|
28
|
+
[
|
|
29
|
+
"#{mounted_app_path}/test/dummy/bin/webpack",
|
|
30
|
+
"#{mounted_app_path}/test/dummy/bin/webpack-dev-server",
|
|
31
|
+
]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def remove_webpack_binstubs
|
|
35
|
+
webpack_binstub_paths.each do |path|
|
|
36
|
+
File.delete(path) if File.exist?(path)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
data/test/helper_test.rb
CHANGED
|
@@ -17,21 +17,27 @@ class HelperTest < ActionView::TestCase
|
|
|
17
17
|
def test_asset_pack_path
|
|
18
18
|
assert_equal "/packs/bootstrap-300631c4f0e0f9c865bc.js", asset_pack_path("bootstrap.js")
|
|
19
19
|
assert_equal "/packs/bootstrap-c38deda30895059837cf.css", asset_pack_path("bootstrap.css")
|
|
20
|
-
|
|
21
|
-
Webpacker.config.stub :extract_css?, false do
|
|
22
|
-
assert_nil asset_pack_path("bootstrap.css")
|
|
23
|
-
assert_equal "/packs/application-k344a6d59eef8632c9d1.png", asset_pack_path("application.png")
|
|
24
|
-
end
|
|
25
20
|
end
|
|
26
21
|
|
|
27
22
|
def test_asset_pack_url
|
|
28
23
|
assert_equal "https://example.com/packs/bootstrap-300631c4f0e0f9c865bc.js", asset_pack_url("bootstrap.js")
|
|
29
24
|
assert_equal "https://example.com/packs/bootstrap-c38deda30895059837cf.css", asset_pack_url("bootstrap.css")
|
|
25
|
+
end
|
|
30
26
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
def test_image_pack_path
|
|
28
|
+
assert_equal "/packs/application-k344a6d59eef8632c9d1.png", image_pack_path("application.png")
|
|
29
|
+
assert_equal "/packs/static/image-c38deda30895059837cf.jpg", image_pack_path("image.jpg")
|
|
30
|
+
assert_equal "/packs/static/image-c38deda30895059837cf.jpg", image_pack_path("static/image.jpg")
|
|
31
|
+
assert_equal "/packs/static/nested/image-c38deda30895059837cf.jpg", image_pack_path("nested/image.jpg")
|
|
32
|
+
assert_equal "/packs/static/nested/image-c38deda30895059837cf.jpg", image_pack_path("static/nested/image.jpg")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_image_pack_url
|
|
36
|
+
assert_equal "https://example.com/packs/application-k344a6d59eef8632c9d1.png", image_pack_url("application.png")
|
|
37
|
+
assert_equal "https://example.com/packs/static/image-c38deda30895059837cf.jpg", image_pack_url("image.jpg")
|
|
38
|
+
assert_equal "https://example.com/packs/static/image-c38deda30895059837cf.jpg", image_pack_url("static/image.jpg")
|
|
39
|
+
assert_equal "https://example.com/packs/static/nested/image-c38deda30895059837cf.jpg", image_pack_url("nested/image.jpg")
|
|
40
|
+
assert_equal "https://example.com/packs/static/nested/image-c38deda30895059837cf.jpg", image_pack_url("static/nested/image.jpg")
|
|
35
41
|
end
|
|
36
42
|
|
|
37
43
|
def test_image_pack_tag
|
|
@@ -39,20 +45,20 @@ class HelperTest < ActionView::TestCase
|
|
|
39
45
|
"<img alt=\"Edit Entry\" src=\"/packs/application-k344a6d59eef8632c9d1.png\" width=\"16\" height=\"10\" />",
|
|
40
46
|
image_pack_tag("application.png", size: "16x10", alt: "Edit Entry")
|
|
41
47
|
assert_equal \
|
|
42
|
-
"<img alt=\"Edit Entry\" src=\"/packs/
|
|
48
|
+
"<img alt=\"Edit Entry\" src=\"/packs/static/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
|
|
43
49
|
image_pack_tag("image.jpg", size: "16x10", alt: "Edit Entry")
|
|
44
50
|
assert_equal \
|
|
45
|
-
"<img alt=\"Edit Entry\" src=\"/packs/
|
|
46
|
-
image_pack_tag("
|
|
51
|
+
"<img alt=\"Edit Entry\" src=\"/packs/static/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
|
|
52
|
+
image_pack_tag("static/image.jpg", size: "16x10", alt: "Edit Entry")
|
|
47
53
|
assert_equal \
|
|
48
|
-
"<img alt=\"Edit Entry\" src=\"/packs/
|
|
54
|
+
"<img alt=\"Edit Entry\" src=\"/packs/static/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
|
|
49
55
|
image_pack_tag("nested/image.jpg", size: "16x10", alt: "Edit Entry")
|
|
50
56
|
assert_equal \
|
|
51
|
-
"<img alt=\"Edit Entry\" src=\"/packs/
|
|
52
|
-
image_pack_tag("
|
|
57
|
+
"<img alt=\"Edit Entry\" src=\"/packs/static/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
|
|
58
|
+
image_pack_tag("static/nested/image.jpg", size: "16x10", alt: "Edit Entry")
|
|
53
59
|
assert_equal \
|
|
54
|
-
"<img srcset=\"/packs/
|
|
55
|
-
image_pack_tag("
|
|
60
|
+
"<img srcset=\"/packs/static/image-2x-7cca48e6cae66ec07b8e.jpg 2x\" src=\"/packs/static/image-c38deda30895059837cf.jpg\" />",
|
|
61
|
+
image_pack_tag("static/image.jpg", srcset: { "static/image-2x.jpg" => "2x" })
|
|
56
62
|
end
|
|
57
63
|
|
|
58
64
|
def test_favicon_pack_tag
|
|
@@ -60,44 +66,17 @@ class HelperTest < ActionView::TestCase
|
|
|
60
66
|
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/application-k344a6d59eef8632c9d1.png\" />",
|
|
61
67
|
favicon_pack_tag("application.png", rel: "apple-touch-icon", type: "image/png")
|
|
62
68
|
assert_equal \
|
|
63
|
-
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/
|
|
69
|
+
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/mb-icon-c38deda30895059837cf.png\" />",
|
|
64
70
|
favicon_pack_tag("mb-icon.png", rel: "apple-touch-icon", type: "image/png")
|
|
65
71
|
assert_equal \
|
|
66
|
-
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/
|
|
67
|
-
favicon_pack_tag("
|
|
72
|
+
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/mb-icon-c38deda30895059837cf.png\" />",
|
|
73
|
+
favicon_pack_tag("static/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
|
|
68
74
|
assert_equal \
|
|
69
|
-
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/
|
|
75
|
+
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/nested/mb-icon-c38deda30895059837cf.png\" />",
|
|
70
76
|
favicon_pack_tag("nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
|
|
71
77
|
assert_equal \
|
|
72
|
-
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/
|
|
73
|
-
favicon_pack_tag("
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def test_javascript_pack_tag
|
|
77
|
-
assert_equal \
|
|
78
|
-
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
|
|
79
|
-
javascript_pack_tag("bootstrap.js")
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def test_javascript_pack_tag_symbol
|
|
83
|
-
assert_equal \
|
|
84
|
-
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
|
|
85
|
-
javascript_pack_tag(:bootstrap)
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def test_javascript_pack_tag_splat
|
|
89
|
-
assert_equal \
|
|
90
|
-
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js" defer="defer"></script>\n) +
|
|
91
|
-
%(<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>),
|
|
92
|
-
javascript_pack_tag("bootstrap.js", "application.js", defer: true)
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def test_javascript_pack_tag_split_chunks
|
|
96
|
-
assert_equal \
|
|
97
|
-
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>\n) +
|
|
98
|
-
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>\n) +
|
|
99
|
-
%(<script src="/packs/application-k344a6d59eef8632c9d1.js"></script>),
|
|
100
|
-
javascript_packs_with_chunks_tag("application")
|
|
78
|
+
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/nested/mb-icon-c38deda30895059837cf.png\" />",
|
|
79
|
+
favicon_pack_tag("static/nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
|
|
101
80
|
end
|
|
102
81
|
|
|
103
82
|
def test_preload_pack_asset
|
|
@@ -116,42 +95,65 @@ class HelperTest < ActionView::TestCase
|
|
|
116
95
|
end
|
|
117
96
|
end
|
|
118
97
|
|
|
119
|
-
def
|
|
120
|
-
assert_equal
|
|
121
|
-
|
|
122
|
-
%(<
|
|
123
|
-
%(<
|
|
98
|
+
def test_javascript_pack_tag
|
|
99
|
+
assert_equal \
|
|
100
|
+
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>\n) +
|
|
101
|
+
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>\n) +
|
|
102
|
+
%(<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>\n) +
|
|
103
|
+
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js" defer="defer"></script>),
|
|
104
|
+
javascript_pack_tag("application", "bootstrap")
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def test_javascript_pack_with_no_defer_tag
|
|
108
|
+
assert_equal \
|
|
109
|
+
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>\n) +
|
|
110
|
+
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>\n) +
|
|
111
|
+
%(<script src="/packs/application-k344a6d59eef8632c9d1.js"></script>\n) +
|
|
112
|
+
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
|
|
113
|
+
javascript_pack_tag("application", "bootstrap", defer: false)
|
|
114
|
+
end
|
|
124
115
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
116
|
+
def test_javascript_pack_tag_splat
|
|
117
|
+
assert_equal \
|
|
118
|
+
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>\n) +
|
|
119
|
+
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>\n) +
|
|
120
|
+
%(<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>),
|
|
121
|
+
javascript_pack_tag("application", defer: true)
|
|
130
122
|
end
|
|
131
123
|
|
|
132
|
-
def
|
|
133
|
-
assert_equal
|
|
134
|
-
%(<
|
|
124
|
+
def test_javascript_pack_tag_symbol
|
|
125
|
+
assert_equal \
|
|
126
|
+
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>\n) +
|
|
127
|
+
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>\n) +
|
|
128
|
+
%(<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>),
|
|
129
|
+
javascript_pack_tag(:application)
|
|
130
|
+
end
|
|
135
131
|
|
|
136
|
-
|
|
137
|
-
]
|
|
132
|
+
def application_stylesheet_chunks
|
|
133
|
+
%w[/packs/1-c20632e7baf2c81200d3.chunk.css /packs/application-k344a6d59eef8632c9d1.chunk.css]
|
|
138
134
|
end
|
|
139
135
|
|
|
140
|
-
def
|
|
141
|
-
|
|
142
|
-
|
|
136
|
+
def hello_stimulus_stylesheet_chunks
|
|
137
|
+
%w[/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css]
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def test_stylesheet_pack_tag
|
|
141
|
+
assert_equal \
|
|
142
|
+
(application_stylesheet_chunks + hello_stimulus_stylesheet_chunks)
|
|
143
|
+
.map { |chunk| stylesheet_link_tag(chunk) }.join("\n"),
|
|
144
|
+
stylesheet_pack_tag("application", "hello_stimulus")
|
|
145
|
+
end
|
|
143
146
|
|
|
144
|
-
|
|
145
|
-
|
|
147
|
+
def test_stylesheet_pack_tag_symbol
|
|
148
|
+
assert_equal \
|
|
149
|
+
(application_stylesheet_chunks + hello_stimulus_stylesheet_chunks)
|
|
150
|
+
.map { |chunk| stylesheet_link_tag(chunk) }.join("\n"),
|
|
151
|
+
stylesheet_pack_tag(:application, :hello_stimulus)
|
|
146
152
|
end
|
|
147
153
|
|
|
148
154
|
def test_stylesheet_pack_tag_splat
|
|
149
|
-
assert_equal
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
%(<link rel="stylesheet" media="all" href="/packs/bootstrap-c38deda30895059837cf.css" />\n) +
|
|
154
|
-
%(<link rel="stylesheet" media="all" href="/packs/application-dd6b1cd38bfa093df600.css" />),
|
|
155
|
-
]), true
|
|
155
|
+
assert_equal \
|
|
156
|
+
(application_stylesheet_chunks).map { |chunk| stylesheet_link_tag(chunk, media: "all") }.join("\n"),
|
|
157
|
+
stylesheet_pack_tag("application", media: "all")
|
|
156
158
|
end
|
|
157
159
|
end
|
data/test/manifest_test.rb
CHANGED
|
@@ -25,6 +25,22 @@ class ManifestTest < Minitest::Test
|
|
|
25
25
|
assert_equal Webpacker.manifest.lookup!("bootstrap.js"), "/packs/bootstrap-300631c4f0e0f9c865bc.js"
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
def test_lookup_with_chunks_without_extension_success!
|
|
29
|
+
assert_equal ["/packs/bootstrap-300631c4f0e0f9c865bc.js"], Webpacker.manifest.lookup_pack_with_chunks!("bootstrap", type: :javascript)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_lookup_with_chunks_with_extension_success!
|
|
33
|
+
assert_equal ["/packs/bootstrap-300631c4f0e0f9c865bc.js"], Webpacker.manifest.lookup_pack_with_chunks!("bootstrap.js", type: :javascript)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_lookup_with_chunks_without_extension_subdir_success!
|
|
37
|
+
assert_equal ["/packs/print/application-983b6c164a47f7ed49cd.css"], Webpacker.manifest.lookup_pack_with_chunks!("print/application", type: :css)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_lookup_with_chunks_with_extension_subdir_success!
|
|
41
|
+
assert_equal ["/packs/print/application-983b6c164a47f7ed49cd.css"], Webpacker.manifest.lookup_pack_with_chunks!("print/application.css", type: :css)
|
|
42
|
+
end
|
|
43
|
+
|
|
28
44
|
def test_lookup_nil
|
|
29
45
|
assert_nil Webpacker.manifest.lookup("foo.js")
|
|
30
46
|
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Note: You must restart bin/webpack-dev-server for changes to take effect
|
|
2
|
+
|
|
3
|
+
default: &default
|
|
4
|
+
source_path: app/packs
|
|
5
|
+
source_entry_path: entrypoints
|
|
6
|
+
public_output_path: packs
|
|
7
|
+
cache_path: tmp/webpacker
|
|
8
|
+
|
|
9
|
+
# Additional paths webpack should look up modules
|
|
10
|
+
# ['app/assets', 'engine/foo/app/assets']
|
|
11
|
+
additional_paths:
|
|
12
|
+
- app/assets
|
|
13
|
+
- /etc/yarn
|
|
14
|
+
|
|
15
|
+
# Reload manifest.json on all requests so we reload latest compiled packs
|
|
16
|
+
cache_manifest: false
|
|
17
|
+
|
|
18
|
+
extensions:
|
|
19
|
+
- .js
|
|
20
|
+
- .sass
|
|
21
|
+
- .scss
|
|
22
|
+
- .css
|
|
23
|
+
- .module.sass
|
|
24
|
+
- .module.scss
|
|
25
|
+
- .module.css
|
|
26
|
+
- .png
|
|
27
|
+
- .svg
|
|
28
|
+
- .gif
|
|
29
|
+
- .jpeg
|
|
30
|
+
- .jpg
|
|
31
|
+
|
|
32
|
+
development:
|
|
33
|
+
<<: *default
|
|
34
|
+
compile: true
|
|
35
|
+
|
|
36
|
+
# Reference: https://webpack.js.org/configuration/dev-server/
|
|
37
|
+
dev_server:
|
|
38
|
+
https: false
|
|
39
|
+
host: localhost
|
|
40
|
+
port: 3035
|
|
41
|
+
public: localhost:3035
|
|
42
|
+
hmr: false
|
|
43
|
+
# Inline should be set to true if using HMR
|
|
44
|
+
inline: true
|
|
45
|
+
overlay: true
|
|
46
|
+
disable_host_check: true
|
|
47
|
+
use_local_ip: false
|
|
48
|
+
|
|
49
|
+
test:
|
|
50
|
+
<<: *default
|
|
51
|
+
compile: true
|
|
52
|
+
|
|
53
|
+
# Compile test packs to a separate directory
|
|
54
|
+
public_output_path: packs-test
|
|
55
|
+
|
|
56
|
+
production:
|
|
57
|
+
<<: *default
|
|
58
|
+
|
|
59
|
+
# Production depends on precompilation of packs prior to booting for performance.
|
|
60
|
+
compile: false
|
|
61
|
+
|
|
62
|
+
# Cache manifest.json for performance
|
|
63
|
+
cache_manifest: true
|
|
64
|
+
|
|
65
|
+
staging:
|
|
66
|
+
<<: *default
|
|
67
|
+
|
|
68
|
+
# Production depends on precompilation of packs prior to booting for performance.
|
|
69
|
+
compile: false
|
|
70
|
+
|
|
71
|
+
# Cache manifest.json for performance
|
|
72
|
+
cache_manifest: true
|
|
73
|
+
|
|
74
|
+
# Compile staging packs to a separate directory
|
|
75
|
+
public_output_path: packs-staging
|