webpacker 4.3.0 → 6.0.0.rc.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +8 -8
  3. data/.github/workflows/jest.yml +30 -0
  4. data/.github/workflows/js-lint.yml +31 -0
  5. data/.github/workflows/rubocop.yml +39 -0
  6. data/.github/workflows/ruby.yml +48 -0
  7. data/.gitignore +2 -0
  8. data/.node-version +1 -1
  9. data/.rubocop.yml +117 -16
  10. data/CHANGELOG.md +91 -5
  11. data/CONTRIBUTING.md +20 -1
  12. data/Gemfile +1 -0
  13. data/Gemfile.lock +121 -109
  14. data/README.md +365 -387
  15. data/config/README.md +3 -0
  16. data/config/webpacker.yml +1 -0
  17. data/docs/deployment.md +9 -11
  18. data/docs/developing_webpacker.md +29 -0
  19. data/docs/troubleshooting.md +64 -26
  20. data/docs/v6_upgrade.md +113 -0
  21. data/gemfiles/Gemfile-rails-edge +1 -1
  22. data/gemfiles/{Gemfile-rails.4.2.x → Gemfile-rails.6.1.x} +4 -1
  23. data/lib/install/{javascript/packs/application.js → application.js} +2 -5
  24. data/lib/install/bin/webpack +4 -7
  25. data/lib/install/bin/yarn +18 -0
  26. data/lib/install/config/webpack/base.js +3 -0
  27. data/lib/install/config/webpack/development.js +2 -2
  28. data/lib/install/config/webpack/production.js +2 -2
  29. data/lib/install/config/webpack/test.js +2 -2
  30. data/lib/install/config/webpacker.yml +22 -54
  31. data/lib/install/package.json +15 -0
  32. data/lib/install/template.rb +66 -23
  33. data/lib/tasks/webpacker/binstubs.rake +6 -4
  34. data/lib/tasks/webpacker/check_binstubs.rake +4 -4
  35. data/lib/tasks/webpacker/check_node.rake +18 -8
  36. data/lib/tasks/webpacker/check_yarn.rake +19 -10
  37. data/lib/tasks/webpacker/clean.rake +12 -6
  38. data/lib/tasks/webpacker/clobber.rake +9 -5
  39. data/lib/tasks/webpacker/compile.rake +4 -2
  40. data/lib/tasks/webpacker/info.rake +12 -10
  41. data/lib/tasks/webpacker/install.rake +6 -4
  42. data/lib/tasks/webpacker/verify_config.rake +14 -0
  43. data/lib/tasks/webpacker/verify_install.rake +1 -10
  44. data/lib/tasks/webpacker/yarn_install.rake +13 -16
  45. data/lib/tasks/webpacker.rake +2 -11
  46. data/lib/tasks/yarn.rake +38 -0
  47. data/lib/webpacker/commands.rb +40 -11
  48. data/lib/webpacker/compiler.rb +23 -12
  49. data/lib/webpacker/configuration.rb +24 -33
  50. data/lib/webpacker/dev_server.rb +6 -0
  51. data/lib/webpacker/dev_server_proxy.rb +3 -1
  52. data/lib/webpacker/dev_server_runner.rb +34 -10
  53. data/lib/webpacker/env.rb +5 -1
  54. data/lib/webpacker/helper.rb +72 -87
  55. data/lib/webpacker/instance.rb +4 -0
  56. data/lib/webpacker/manifest.rb +6 -7
  57. data/lib/webpacker/railtie.rb +8 -45
  58. data/lib/webpacker/runner.rb +1 -0
  59. data/lib/webpacker/version.rb +1 -1
  60. data/lib/webpacker/webpack_runner.rb +30 -4
  61. data/lib/webpacker.rb +1 -1
  62. data/package/__tests__/config.js +6 -27
  63. data/package/__tests__/dev_server.js +2 -0
  64. data/package/__tests__/development.js +18 -13
  65. data/package/__tests__/env.js +16 -4
  66. data/package/__tests__/index.js +9 -0
  67. data/package/__tests__/production.js +6 -6
  68. data/package/__tests__/staging.js +7 -6
  69. data/package/__tests__/test.js +4 -5
  70. data/package/babel/preset.js +54 -0
  71. data/package/config.js +7 -12
  72. data/package/configPath.js +3 -0
  73. data/package/dev_server.js +1 -1
  74. data/package/env.js +14 -6
  75. data/package/environments/__tests__/base.js +26 -31
  76. data/package/environments/base.js +78 -128
  77. data/package/environments/development.js +47 -43
  78. data/package/environments/production.js +66 -66
  79. data/package/environments/test.js +2 -2
  80. data/package/index.js +15 -8
  81. data/package/inliningCss.js +7 -0
  82. data/package/rules/babel.js +20 -11
  83. data/package/rules/coffee.js +6 -0
  84. data/package/rules/erb.js +15 -0
  85. data/package/rules/file.js +21 -18
  86. data/package/rules/index.js +16 -18
  87. data/package/rules/less.js +22 -0
  88. data/package/rules/raw.js +5 -0
  89. data/package/rules/sass.js +14 -6
  90. data/package/rules/stylus.js +26 -0
  91. data/package/utils/get_style_rule.js +28 -36
  92. data/package/utils/helpers.js +28 -35
  93. data/package.json +26 -46
  94. data/test/command_test.rb +76 -0
  95. data/test/compiler_test.rb +4 -11
  96. data/test/configuration_test.rb +5 -35
  97. data/test/dev_server_runner_test.rb +36 -6
  98. data/test/engine_rake_tasks_test.rb +39 -0
  99. data/test/helper_test.rb +77 -60
  100. data/test/manifest_test.rb +53 -6
  101. data/test/mounted_app/Rakefile +4 -0
  102. data/test/mounted_app/test/dummy/Rakefile +3 -0
  103. data/test/mounted_app/test/dummy/bin/rails +3 -0
  104. data/test/mounted_app/test/dummy/bin/rake +3 -0
  105. data/test/mounted_app/test/dummy/config/application.rb +10 -0
  106. data/test/mounted_app/test/dummy/config/environment.rb +3 -0
  107. data/test/mounted_app/test/dummy/config/webpacker.yml +75 -0
  108. data/test/mounted_app/test/dummy/config.ru +5 -0
  109. data/test/mounted_app/test/dummy/package.json +7 -0
  110. data/test/rake_tasks_test.rb +12 -10
  111. data/test/test_app/app/{javascript/packs → packs/entrypoints}/application.js +1 -1
  112. data/test/test_app/app/packs/entrypoints/multi_entry.css +4 -0
  113. data/test/test_app/app/packs/entrypoints/multi_entry.js +4 -0
  114. data/test/test_app/config/application.rb +0 -1
  115. data/test/test_app/config/initializers/inspect_autoload_paths.rb +1 -0
  116. data/test/test_app/config/webpacker.yml +7 -27
  117. data/test/test_app/config/webpacker_other_location.yml +79 -0
  118. data/test/test_app/config/webpacker_public_root.yml +0 -1
  119. data/test/test_app/public/packs/manifest.json +36 -17
  120. data/test/test_app/some.config.js +0 -0
  121. data/test/webpack_runner_test.rb +10 -4
  122. data/test/webpacker_test.rb +21 -0
  123. data/webpacker.gemspec +5 -4
  124. data/yarn.lock +3387 -6898
  125. metadata +90 -99
  126. data/.travis.yml +0 -57
  127. data/docs/assets.md +0 -119
  128. data/docs/cloud9.md +0 -310
  129. data/docs/css.md +0 -254
  130. data/docs/docker.md +0 -68
  131. data/docs/engines.md +0 -200
  132. data/docs/env.md +0 -65
  133. data/docs/es6.md +0 -72
  134. data/docs/folder-structure.md +0 -66
  135. data/docs/misc.md +0 -23
  136. data/docs/props.md +0 -223
  137. data/docs/testing.md +0 -137
  138. data/docs/typescript.md +0 -126
  139. data/docs/v4-upgrade.md +0 -142
  140. data/docs/webpack-dev-server.md +0 -92
  141. data/docs/webpack.md +0 -364
  142. data/docs/yarn.md +0 -23
  143. data/gemfiles/Gemfile-rails.5.0.x +0 -9
  144. data/gemfiles/Gemfile-rails.5.1.x +0 -9
  145. data/lib/install/angular.rb +0 -23
  146. data/lib/install/coffee.rb +0 -25
  147. data/lib/install/config/.browserslistrc +0 -1
  148. data/lib/install/config/babel.config.js +0 -72
  149. data/lib/install/config/postcss.config.js +0 -12
  150. data/lib/install/config/webpack/environment.js +0 -3
  151. data/lib/install/elm.rb +0 -39
  152. data/lib/install/erb.rb +0 -25
  153. data/lib/install/examples/angular/hello_angular/app/app.component.ts +0 -9
  154. data/lib/install/examples/angular/hello_angular/app/app.module.ts +0 -16
  155. data/lib/install/examples/angular/hello_angular/index.ts +0 -8
  156. data/lib/install/examples/angular/hello_angular/polyfills.ts +0 -73
  157. data/lib/install/examples/angular/hello_angular.js +0 -7
  158. data/lib/install/examples/coffee/hello_coffee.coffee +0 -4
  159. data/lib/install/examples/elm/Main.elm +0 -55
  160. data/lib/install/examples/elm/hello_elm.js +0 -16
  161. data/lib/install/examples/erb/hello_erb.js.erb +0 -6
  162. data/lib/install/examples/react/babel.config.js +0 -87
  163. data/lib/install/examples/react/hello_react.jsx +0 -26
  164. data/lib/install/examples/react/tsconfig.json +0 -20
  165. data/lib/install/examples/stimulus/application.js +0 -1
  166. data/lib/install/examples/stimulus/controllers/hello_controller.js +0 -18
  167. data/lib/install/examples/stimulus/controllers/index.js +0 -9
  168. data/lib/install/examples/svelte/app.svelte +0 -11
  169. data/lib/install/examples/svelte/hello_svelte.js +0 -20
  170. data/lib/install/examples/typescript/hello_typescript.ts +0 -4
  171. data/lib/install/examples/typescript/tsconfig.json +0 -23
  172. data/lib/install/examples/vue/app.vue +0 -22
  173. data/lib/install/examples/vue/hello_vue.js +0 -72
  174. data/lib/install/loaders/coffee.js +0 -6
  175. data/lib/install/loaders/elm.js +0 -25
  176. data/lib/install/loaders/erb.js +0 -11
  177. data/lib/install/loaders/svelte.js +0 -9
  178. data/lib/install/loaders/typescript.js +0 -11
  179. data/lib/install/loaders/vue.js +0 -6
  180. data/lib/install/react.rb +0 -18
  181. data/lib/install/stimulus.rb +0 -12
  182. data/lib/install/svelte.rb +0 -29
  183. data/lib/install/typescript.rb +0 -46
  184. data/lib/install/vue.rb +0 -49
  185. data/lib/tasks/installers.rake +0 -42
  186. data/package/config_types/__tests__/config_list.js +0 -118
  187. data/package/config_types/__tests__/config_object.js +0 -43
  188. data/package/config_types/config_list.js +0 -75
  189. data/package/config_types/config_object.js +0 -55
  190. data/package/config_types/index.js +0 -7
  191. data/package/rules/module.css.js +0 -3
  192. data/package/rules/module.sass.js +0 -8
  193. data/package/rules/node_modules.js +0 -24
  194. data/package/utils/__tests__/deep_assign.js +0 -32
  195. data/package/utils/__tests__/deep_merge.js +0 -10
  196. data/package/utils/__tests__/get_style_rule.js +0 -65
  197. data/package/utils/__tests__/objectify.js +0 -9
  198. data/package/utils/deep_assign.js +0 -22
  199. data/package/utils/deep_merge.js +0 -22
  200. data/package/utils/objectify.js +0 -3
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
- Webpacker.config.stub :extract_css?, false do
32
- assert_nil asset_pack_path("bootstrap.css")
33
- assert_equal "https://example.com/packs/application-k344a6d59eef8632c9d1.png", asset_pack_url("application.png")
34
- end
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,17 +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/media/images/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
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/media/images/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
46
- image_pack_tag("media/images/image.jpg", size: "16x10", alt: "Edit Entry")
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/media/images/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
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/media/images/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
52
- image_pack_tag("media/images/nested/image.jpg", size: "16x10", alt: "Edit Entry")
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")
59
+ assert_equal \
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" })
53
62
  end
54
63
 
55
64
  def test_favicon_pack_tag
@@ -57,44 +66,17 @@ class HelperTest < ActionView::TestCase
57
66
  "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/application-k344a6d59eef8632c9d1.png\" />",
58
67
  favicon_pack_tag("application.png", rel: "apple-touch-icon", type: "image/png")
59
68
  assert_equal \
60
- "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/media/images/mb-icon-c38deda30895059837cf.png\" />",
69
+ "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/mb-icon-c38deda30895059837cf.png\" />",
61
70
  favicon_pack_tag("mb-icon.png", rel: "apple-touch-icon", type: "image/png")
62
71
  assert_equal \
63
- "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/media/images/mb-icon-c38deda30895059837cf.png\" />",
64
- favicon_pack_tag("media/images/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
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")
65
74
  assert_equal \
66
- "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/media/images/nested/mb-icon-c38deda30895059837cf.png\" />",
75
+ "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/nested/mb-icon-c38deda30895059837cf.png\" />",
67
76
  favicon_pack_tag("nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
68
77
  assert_equal \
69
- "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/media/images/nested/mb-icon-c38deda30895059837cf.png\" />",
70
- favicon_pack_tag("media/images/nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
71
- end
72
-
73
- def test_javascript_pack_tag
74
- assert_equal \
75
- %(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
76
- javascript_pack_tag("bootstrap.js")
77
- end
78
-
79
- def test_javascript_pack_tag_symbol
80
- assert_equal \
81
- %(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
82
- javascript_pack_tag(:bootstrap)
83
- end
84
-
85
- def test_javascript_pack_tag_splat
86
- assert_equal \
87
- %(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js" defer="defer"></script>\n) +
88
- %(<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>),
89
- javascript_pack_tag("bootstrap.js", "application.js", defer: true)
90
- end
91
-
92
- def test_javascript_pack_tag_split_chunks
93
- assert_equal \
94
- %(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>\n) +
95
- %(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>\n) +
96
- %(<script src="/packs/application-k344a6d59eef8632c9d1.js"></script>),
97
- 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")
98
80
  end
99
81
 
100
82
  def test_preload_pack_asset
@@ -113,30 +95,65 @@ class HelperTest < ActionView::TestCase
113
95
  end
114
96
  end
115
97
 
116
- def test_stylesheet_pack_tag_split_chunks
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
115
+
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)
122
+ end
123
+
124
+ def test_javascript_pack_tag_symbol
117
125
  assert_equal \
118
- %(<link rel="stylesheet" media="screen" href="/packs/1-c20632e7baf2c81200d3.chunk.css" />\n) +
119
- %(<link rel="stylesheet" media="screen" href="/packs/application-k344a6d59eef8632c9d1.chunk.css" />\n) +
120
- %(<link rel="stylesheet" media="screen" href="/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css" />),
121
- stylesheet_packs_with_chunks_tag("application", "hello_stimulus")
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
131
+
132
+ def application_stylesheet_chunks
133
+ %w[/packs/1-c20632e7baf2c81200d3.chunk.css /packs/application-k344a6d59eef8632c9d1.chunk.css]
134
+ end
135
+
136
+ def hello_stimulus_stylesheet_chunks
137
+ %w[/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css]
122
138
  end
123
139
 
124
140
  def test_stylesheet_pack_tag
125
141
  assert_equal \
126
- %(<link rel="stylesheet" media="screen" href="/packs/bootstrap-c38deda30895059837cf.css" />),
127
- stylesheet_pack_tag("bootstrap.css")
142
+ (application_stylesheet_chunks + hello_stimulus_stylesheet_chunks)
143
+ .map { |chunk| stylesheet_link_tag(chunk) }.join("\n"),
144
+ stylesheet_pack_tag("application", "hello_stimulus")
128
145
  end
129
146
 
130
147
  def test_stylesheet_pack_tag_symbol
131
148
  assert_equal \
132
- %(<link rel="stylesheet" media="screen" href="/packs/bootstrap-c38deda30895059837cf.css" />),
133
- stylesheet_pack_tag(:bootstrap)
149
+ (application_stylesheet_chunks + hello_stimulus_stylesheet_chunks)
150
+ .map { |chunk| stylesheet_link_tag(chunk) }.join("\n"),
151
+ stylesheet_pack_tag(:application, :hello_stimulus)
134
152
  end
135
153
 
136
154
  def test_stylesheet_pack_tag_splat
137
155
  assert_equal \
138
- %(<link rel="stylesheet" media="all" href="/packs/bootstrap-c38deda30895059837cf.css" />\n) +
139
- %(<link rel="stylesheet" media="all" href="/packs/application-dd6b1cd38bfa093df600.css" />),
140
- stylesheet_pack_tag("bootstrap.css", "application.css", media: "all")
156
+ (application_stylesheet_chunks).map { |chunk| stylesheet_link_tag(chunk, media: "all") }.join("\n"),
157
+ stylesheet_pack_tag("application", media: "all")
141
158
  end
142
159
  end
@@ -2,22 +2,45 @@ require "test_helper"
2
2
 
3
3
  class ManifestTest < Minitest::Test
4
4
  def test_lookup_exception!
5
- manifest_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs", "manifest.json").to_s
6
5
  asset_file = "calendar.js"
7
6
 
8
- Webpacker.config.stub :compile?, false do
9
- error = assert_raises Webpacker::Manifest::MissingEntryError do
10
- Webpacker.manifest.lookup!(asset_file)
11
- end
7
+ error = assert_raises_manifest_missing_entry_error do
8
+ Webpacker.manifest.lookup!(asset_file)
9
+ end
10
+
11
+ assert_match "Webpacker can't find #{asset_file} in #{manifest_path}", error.message
12
+ end
12
13
 
13
- assert_match "Webpacker can't find #{asset_file} in #{manifest_path}", error.message
14
+ def test_lookup_with_type_exception!
15
+ asset_file = "calendar"
16
+
17
+ error = assert_raises_manifest_missing_entry_error do
18
+ Webpacker.manifest.lookup!(asset_file, type: :javascript)
14
19
  end
20
+
21
+ assert_match "Webpacker can't find #{asset_file}.js in #{manifest_path}", error.message
15
22
  end
16
23
 
17
24
  def test_lookup_success!
18
25
  assert_equal Webpacker.manifest.lookup!("bootstrap.js"), "/packs/bootstrap-300631c4f0e0f9c865bc.js"
19
26
  end
20
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
+
21
44
  def test_lookup_nil
22
45
  assert_nil Webpacker.manifest.lookup("foo.js")
23
46
  end
@@ -30,6 +53,16 @@ class ManifestTest < Minitest::Test
30
53
  assert_equal Webpacker.manifest.lookup("bootstrap.js"), "/packs/bootstrap-300631c4f0e0f9c865bc.js"
31
54
  end
32
55
 
56
+ def test_lookup_entrypoint_exception!
57
+ asset_file = "calendar"
58
+
59
+ error = assert_raises_manifest_missing_entry_error do
60
+ Webpacker.manifest.lookup_pack_with_chunks!(asset_file, type: :javascript)
61
+ end
62
+
63
+ assert_match "Webpacker can't find #{asset_file}.js in #{manifest_path}", error.message
64
+ end
65
+
33
66
  def test_lookup_entrypoint
34
67
  application_entrypoints = [
35
68
  "/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js",
@@ -39,4 +72,18 @@ class ManifestTest < Minitest::Test
39
72
 
40
73
  assert_equal Webpacker.manifest.lookup_pack_with_chunks!("application", type: :javascript), application_entrypoints
41
74
  end
75
+
76
+ private
77
+
78
+ def assert_raises_manifest_missing_entry_error(&block)
79
+ error = nil
80
+ Webpacker.config.stub :compile?, false do
81
+ error = assert_raises Webpacker::Manifest::MissingEntryError, &block
82
+ end
83
+ error
84
+ end
85
+
86
+ def manifest_path
87
+ File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs", "manifest.json").to_s
88
+ end
42
89
  end
@@ -0,0 +1,4 @@
1
+ require "bundler/setup"
2
+
3
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
@@ -0,0 +1,3 @@
1
+ require_relative "config/application"
2
+
3
+ Rails.application.load_tasks
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path("../config/application", __dir__)
3
+ require "rails/commands"
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require "rake"
3
+ Rake.application.run
@@ -0,0 +1,10 @@
1
+ require "action_controller/railtie"
2
+ require "action_view/railtie"
3
+ require "webpacker"
4
+
5
+ module TestDummyApp
6
+ class Application < Rails::Application
7
+ config.secret_key_base = "abcdef"
8
+ config.eager_load = true
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ require_relative "application"
2
+
3
+ Rails.application.initialize!
@@ -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
@@ -0,0 +1,5 @@
1
+ # This file allows the `Rails.root` to be correctly determined.
2
+
3
+ require_relative "config/environment"
4
+
5
+ run Rails.application
@@ -0,0 +1,7 @@
1
+ {
2
+ "private": true,
3
+ "dependencies": {
4
+ "@rails/webpacker": "file:../../../../"
5
+ },
6
+ "license": "MIT"
7
+ }
@@ -11,21 +11,23 @@ class RakeTasksTest < Minitest::Test
11
11
  assert_includes output, "webpacker:clobber"
12
12
  assert_includes output, "webpacker:compile"
13
13
  assert_includes output, "webpacker:install"
14
- assert_includes output, "webpacker:install:angular"
15
- assert_includes output, "webpacker:install:coffee"
16
- assert_includes output, "webpacker:install:elm"
17
- assert_includes output, "webpacker:install:erb"
18
- assert_includes output, "webpacker:install:react"
19
- assert_includes output, "webpacker:install:svelte"
20
- assert_includes output, "webpacker:install:stimulus"
21
- assert_includes output, "webpacker:install:typescript"
22
- assert_includes output, "webpacker:install:vue"
23
14
  assert_includes output, "webpacker:verify_install"
24
15
  end
25
16
 
26
17
  def test_rake_task_webpacker_check_binstubs
27
18
  output = Dir.chdir(test_app_path) { `rake webpacker:check_binstubs 2>&1` }
28
- refute_includes output, "webpack binstubs not found."
19
+ refute_includes output, "webpack binstub not found."
20
+ end
21
+
22
+ def test_check_node_version
23
+ output = Dir.chdir(test_app_path) { `rake webpacker:check_node 2>&1` }
24
+ refute_includes output, "Webpacker requires Node.js"
25
+ end
26
+
27
+ def test_check_yarn_version
28
+ output = Dir.chdir(test_app_path) { `rake webpacker:check_yarn 2>&1` }
29
+ refute_includes output, "Yarn not installed"
30
+ refute_includes output, "Webpacker requires Yarn"
29
31
  end
30
32
 
31
33
  def test_rake_webpacker_yarn_install_in_non_production_environments
@@ -1,7 +1,7 @@
1
1
  /* eslint no-console:0 */
2
2
  // This file is automatically compiled by Webpack, along with any other files
3
3
  // present in this directory. You're encouraged to place your actual application logic in
4
- // a relevant structure within app/javascript and only use these pack files to reference
4
+ // a relevant structure within app/packs and only use these pack files to reference
5
5
  // that code so it'll be compiled.
6
6
  //
7
7
  // To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
@@ -0,0 +1,4 @@
1
+ /*
2
+ * Dummy file #1 for Multi File Entry points: https://webpack.js.org/guides/entry-advanced/
3
+ * This file must be named the same
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ * Dummy file #2 for Multi File Entry points: https://webpack.js.org/guides/entry-advanced/
3
+ * This file must be named the same
4
+ */
@@ -6,7 +6,6 @@ module TestApp
6
6
  class Application < ::Rails::Application
7
7
  config.secret_key_base = "abcdef"
8
8
  config.eager_load = true
9
- config.webpacker.check_yarn_integrity = false
10
9
  config.active_support.test_order = :sorted
11
10
  end
12
11
  end
@@ -0,0 +1 @@
1
+ $test_app_autoload_paths_in_initializer = ActiveSupport::Dependencies.autoload_paths
@@ -1,25 +1,24 @@
1
1
  # Note: You must restart bin/webpack-dev-server for changes to take effect
2
2
 
3
3
  default: &default
4
- source_path: app/javascript
5
- source_entry_path: packs
4
+ source_path: app/packs
5
+ source_entry_path: entrypoints
6
6
  public_root_path: public
7
7
  public_output_path: packs
8
- cache_path: tmp/cache/webpacker
8
+ cache_path: tmp/webpacker
9
9
  webpack_compile_output: false
10
10
 
11
- # Additional paths webpack should lookup modules
11
+ # Additional paths webpack should look up modules
12
12
  # ['app/assets', 'engine/foo/app/assets']
13
- resolved_paths:
13
+ additional_paths:
14
14
  - app/assets
15
15
  - /etc/yarn
16
+ - some.config.js
17
+ - app/elm
16
18
 
17
19
  # Reload manifest.json on all requests so we reload latest compiled packs
18
20
  cache_manifest: false
19
21
 
20
- # Extract and emit a css file
21
- extract_css: false
22
-
23
22
  static_assets_extensions:
24
23
  - .jpg
25
24
  - .jpeg
@@ -32,17 +31,6 @@ default: &default
32
31
  extensions:
33
32
  - .mjs
34
33
  - .js
35
- - .sass
36
- - .scss
37
- - .css
38
- - .module.sass
39
- - .module.scss
40
- - .module.css
41
- - .png
42
- - .svg
43
- - .gif
44
- - .jpeg
45
- - .jpg
46
34
 
47
35
  development:
48
36
  <<: *default
@@ -55,8 +43,6 @@ development:
55
43
  port: 3035
56
44
  public: localhost:3035
57
45
  hmr: false
58
- # Inline should be set to true if using HMR
59
- inline: true
60
46
  overlay: true
61
47
  disable_host_check: true
62
48
  use_local_ip: false
@@ -75,9 +61,6 @@ production:
75
61
  # Production depends on precompilation of packs prior to booting for performance.
76
62
  compile: false
77
63
 
78
- # Extract and emit a css file
79
- extract_css: true
80
-
81
64
  # Cache manifest.json for performance
82
65
  cache_manifest: true
83
66
 
@@ -87,9 +70,6 @@ staging:
87
70
  # Production depends on precompilation of packs prior to booting for performance.
88
71
  compile: false
89
72
 
90
- # Extract and emit a css file
91
- extract_css: true
92
-
93
73
  # Cache manifest.json for performance
94
74
  cache_manifest: true
95
75
 
@@ -0,0 +1,79 @@
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_root_path: public
7
+ public_output_path: packs
8
+ cache_path: tmp/cache/webpacker
9
+ webpack_compile_output: false
10
+
11
+ # Additional paths webpack should look up modules
12
+ # ['app/assets', 'engine/foo/app/assets']
13
+ additional_paths:
14
+ - app/assets
15
+ - /etc/yarn
16
+ - some.config.js
17
+ - app/elm
18
+
19
+ # Reload manifest.json on all requests so we reload latest compiled packs
20
+ cache_manifest: false
21
+
22
+ static_assets_extensions:
23
+ - .jpg
24
+ - .jpeg
25
+ - .png
26
+ - .gif
27
+ - .tiff
28
+ - .ico
29
+ - .svg
30
+
31
+ extensions:
32
+ - .mjs
33
+ - .js
34
+
35
+ development:
36
+ <<: *default
37
+ compile: true
38
+
39
+ # Reference: https://webpack.js.org/configuration/dev-server/
40
+ dev_server:
41
+ https: false
42
+ host: localhost
43
+ port: 3035
44
+ public: localhost:3035
45
+ hmr: false
46
+ # Inline should be set to true if using HMR
47
+ inline: true
48
+ overlay: true
49
+ disable_host_check: true
50
+ use_local_ip: false
51
+ pretty: false
52
+
53
+ test:
54
+ <<: *default
55
+ compile: true
56
+
57
+ # Compile test packs to a separate directory
58
+ public_output_path: packs-test
59
+
60
+ production:
61
+ <<: *default
62
+
63
+ # Production depends on precompilation of packs prior to booting for performance.
64
+ compile: false
65
+
66
+ # Cache manifest.json for performance
67
+ cache_manifest: true
68
+
69
+ staging:
70
+ <<: *default
71
+
72
+ # Production depends on precompilation of packs prior to booting for performance.
73
+ compile: false
74
+
75
+ # Cache manifest.json for performance
76
+ cache_manifest: true
77
+
78
+ # Compile staging packs to a separate directory
79
+ public_output_path: packs-staging
@@ -15,5 +15,4 @@ test:
15
15
  production:
16
16
  <<: *default
17
17
  compile: false
18
- extract_css: true
19
18
  cache_manifest: true