tiny-lite-sys 0.0.1

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.
Files changed (177) hide show
  1. checksums.yaml +7 -0
  2. data/tiny-lite-sys.gemspec +11 -0
  3. data/webpacker-5.4.4/CHANGELOG.md +1074 -0
  4. data/webpacker-5.4.4/CONTRIBUTING.md +33 -0
  5. data/webpacker-5.4.4/Gemfile +13 -0
  6. data/webpacker-5.4.4/Gemfile.lock +183 -0
  7. data/webpacker-5.4.4/MIT-LICENSE +20 -0
  8. data/webpacker-5.4.4/README.md +427 -0
  9. data/webpacker-5.4.4/Rakefile +11 -0
  10. data/webpacker-5.4.4/docs/assets.md +119 -0
  11. data/webpacker-5.4.4/docs/cloud9.md +310 -0
  12. data/webpacker-5.4.4/docs/css.md +308 -0
  13. data/webpacker-5.4.4/docs/deployment.md +130 -0
  14. data/webpacker-5.4.4/docs/docker.md +68 -0
  15. data/webpacker-5.4.4/docs/engines.md +213 -0
  16. data/webpacker-5.4.4/docs/env.md +63 -0
  17. data/webpacker-5.4.4/docs/es6.md +72 -0
  18. data/webpacker-5.4.4/docs/folder-structure.md +66 -0
  19. data/webpacker-5.4.4/docs/integrations.md +220 -0
  20. data/webpacker-5.4.4/docs/misc.md +23 -0
  21. data/webpacker-5.4.4/docs/props.md +223 -0
  22. data/webpacker-5.4.4/docs/target.md +22 -0
  23. data/webpacker-5.4.4/docs/testing.md +136 -0
  24. data/webpacker-5.4.4/docs/troubleshooting.md +158 -0
  25. data/webpacker-5.4.4/docs/typescript.md +190 -0
  26. data/webpacker-5.4.4/docs/v4-upgrade.md +142 -0
  27. data/webpacker-5.4.4/docs/webpack-dev-server.md +92 -0
  28. data/webpacker-5.4.4/docs/webpack.md +364 -0
  29. data/webpacker-5.4.4/docs/yarn.md +23 -0
  30. data/webpacker-5.4.4/gemfiles/Gemfile-rails-edge +12 -0
  31. data/webpacker-5.4.4/gemfiles/Gemfile-rails.5.2.x +9 -0
  32. data/webpacker-5.4.4/gemfiles/Gemfile-rails.6.0.x +9 -0
  33. data/webpacker-5.4.4/lib/install/angular.rb +23 -0
  34. data/webpacker-5.4.4/lib/install/bin/webpack +18 -0
  35. data/webpacker-5.4.4/lib/install/bin/webpack-dev-server +18 -0
  36. data/webpacker-5.4.4/lib/install/binstubs.rb +4 -0
  37. data/webpacker-5.4.4/lib/install/coffee.rb +25 -0
  38. data/webpacker-5.4.4/lib/install/config/babel.config.js +82 -0
  39. data/webpacker-5.4.4/lib/install/config/postcss.config.js +12 -0
  40. data/webpacker-5.4.4/lib/install/config/webpack/development.js +5 -0
  41. data/webpacker-5.4.4/lib/install/config/webpack/environment.js +3 -0
  42. data/webpacker-5.4.4/lib/install/config/webpack/production.js +5 -0
  43. data/webpacker-5.4.4/lib/install/config/webpack/test.js +5 -0
  44. data/webpacker-5.4.4/lib/install/config/webpacker.yml +92 -0
  45. data/webpacker-5.4.4/lib/install/elm.rb +39 -0
  46. data/webpacker-5.4.4/lib/install/erb.rb +25 -0
  47. data/webpacker-5.4.4/lib/install/examples/angular/hello_angular/app/app.component.ts +9 -0
  48. data/webpacker-5.4.4/lib/install/examples/angular/hello_angular/app/app.module.ts +16 -0
  49. data/webpacker-5.4.4/lib/install/examples/angular/hello_angular/index.ts +8 -0
  50. data/webpacker-5.4.4/lib/install/examples/angular/hello_angular/polyfills.ts +73 -0
  51. data/webpacker-5.4.4/lib/install/examples/angular/hello_angular.js +7 -0
  52. data/webpacker-5.4.4/lib/install/examples/coffee/hello_coffee.coffee +4 -0
  53. data/webpacker-5.4.4/lib/install/examples/elm/Main.elm +55 -0
  54. data/webpacker-5.4.4/lib/install/examples/elm/hello_elm.js +16 -0
  55. data/webpacker-5.4.4/lib/install/examples/erb/hello_erb.js.erb +6 -0
  56. data/webpacker-5.4.4/lib/install/examples/react/babel.config.js +99 -0
  57. data/webpacker-5.4.4/lib/install/examples/react/hello_react.jsx +26 -0
  58. data/webpacker-5.4.4/lib/install/examples/react/tsconfig.json +21 -0
  59. data/webpacker-5.4.4/lib/install/examples/stimulus/application.js +1 -0
  60. data/webpacker-5.4.4/lib/install/examples/stimulus/controllers/hello_controller.js +18 -0
  61. data/webpacker-5.4.4/lib/install/examples/stimulus/controllers/index.js +9 -0
  62. data/webpacker-5.4.4/lib/install/examples/svelte/app.svelte +11 -0
  63. data/webpacker-5.4.4/lib/install/examples/svelte/hello_svelte.js +20 -0
  64. data/webpacker-5.4.4/lib/install/examples/typescript/hello_typescript.ts +4 -0
  65. data/webpacker-5.4.4/lib/install/examples/typescript/tsconfig.json +24 -0
  66. data/webpacker-5.4.4/lib/install/examples/vue/app.vue +22 -0
  67. data/webpacker-5.4.4/lib/install/examples/vue/hello_vue.js +72 -0
  68. data/webpacker-5.4.4/lib/install/javascript/packs/application.js +18 -0
  69. data/webpacker-5.4.4/lib/install/loaders/coffee.js +6 -0
  70. data/webpacker-5.4.4/lib/install/loaders/elm.js +25 -0
  71. data/webpacker-5.4.4/lib/install/loaders/erb.js +11 -0
  72. data/webpacker-5.4.4/lib/install/loaders/svelte.js +9 -0
  73. data/webpacker-5.4.4/lib/install/loaders/vue.js +6 -0
  74. data/webpacker-5.4.4/lib/install/react.rb +18 -0
  75. data/webpacker-5.4.4/lib/install/stimulus.rb +12 -0
  76. data/webpacker-5.4.4/lib/install/svelte.rb +29 -0
  77. data/webpacker-5.4.4/lib/install/template.rb +63 -0
  78. data/webpacker-5.4.4/lib/install/typescript.rb +39 -0
  79. data/webpacker-5.4.4/lib/install/vue.rb +49 -0
  80. data/webpacker-5.4.4/lib/tasks/installers.rake +42 -0
  81. data/webpacker-5.4.4/lib/tasks/webpacker/binstubs.rake +13 -0
  82. data/webpacker-5.4.4/lib/tasks/webpacker/check_binstubs.rake +12 -0
  83. data/webpacker-5.4.4/lib/tasks/webpacker/check_node.rake +31 -0
  84. data/webpacker-5.4.4/lib/tasks/webpacker/check_yarn.rake +30 -0
  85. data/webpacker-5.4.4/lib/tasks/webpacker/clean.rake +25 -0
  86. data/webpacker-5.4.4/lib/tasks/webpacker/clobber.rake +20 -0
  87. data/webpacker-5.4.4/lib/tasks/webpacker/compile.rake +43 -0
  88. data/webpacker-5.4.4/lib/tasks/webpacker/info.rake +19 -0
  89. data/webpacker-5.4.4/lib/tasks/webpacker/install.rake +13 -0
  90. data/webpacker-5.4.4/lib/tasks/webpacker/verify_install.rake +13 -0
  91. data/webpacker-5.4.4/lib/tasks/webpacker/yarn_install.rake +16 -0
  92. data/webpacker-5.4.4/lib/tasks/webpacker.rake +28 -0
  93. data/webpacker-5.4.4/lib/webpacker/commands.rb +74 -0
  94. data/webpacker-5.4.4/lib/webpacker/compiler.rb +111 -0
  95. data/webpacker-5.4.4/lib/webpacker/configuration.rb +128 -0
  96. data/webpacker-5.4.4/lib/webpacker/dev_server.rb +66 -0
  97. data/webpacker-5.4.4/lib/webpacker/dev_server_proxy.rb +33 -0
  98. data/webpacker-5.4.4/lib/webpacker/dev_server_runner.rb +72 -0
  99. data/webpacker-5.4.4/lib/webpacker/env.rb +43 -0
  100. data/webpacker-5.4.4/lib/webpacker/helper.rb +195 -0
  101. data/webpacker-5.4.4/lib/webpacker/instance.rb +37 -0
  102. data/webpacker-5.4.4/lib/webpacker/manifest.rb +118 -0
  103. data/webpacker-5.4.4/lib/webpacker/railtie.rb +55 -0
  104. data/webpacker-5.4.4/lib/webpacker/runner.rb +23 -0
  105. data/webpacker-5.4.4/lib/webpacker/version.rb +4 -0
  106. data/webpacker-5.4.4/lib/webpacker/webpack_runner.rb +32 -0
  107. data/webpacker-5.4.4/lib/webpacker.rb +46 -0
  108. data/webpacker-5.4.4/package/__tests__/config.js +66 -0
  109. data/webpacker-5.4.4/package/__tests__/dev_server.js +45 -0
  110. data/webpacker-5.4.4/package/__tests__/development.js +43 -0
  111. data/webpacker-5.4.4/package/__tests__/env.js +46 -0
  112. data/webpacker-5.4.4/package/__tests__/production.js +29 -0
  113. data/webpacker-5.4.4/package/__tests__/staging.js +29 -0
  114. data/webpacker-5.4.4/package/__tests__/test.js +26 -0
  115. data/webpacker-5.4.4/package/config.js +40 -0
  116. data/webpacker-5.4.4/package/configPath.js +3 -0
  117. data/webpacker-5.4.4/package/config_types/__tests__/config_list.js +118 -0
  118. data/webpacker-5.4.4/package/config_types/__tests__/config_object.js +43 -0
  119. data/webpacker-5.4.4/package/config_types/config_list.js +75 -0
  120. data/webpacker-5.4.4/package/config_types/config_object.js +55 -0
  121. data/webpacker-5.4.4/package/config_types/index.js +7 -0
  122. data/webpacker-5.4.4/package/dev_server.js +20 -0
  123. data/webpacker-5.4.4/package/env.js +18 -0
  124. data/webpacker-5.4.4/package/environments/__tests__/base.js +101 -0
  125. data/webpacker-5.4.4/package/environments/base.js +176 -0
  126. data/webpacker-5.4.4/package/environments/development.js +53 -0
  127. data/webpacker-5.4.4/package/environments/production.js +77 -0
  128. data/webpacker-5.4.4/package/environments/test.js +3 -0
  129. data/webpacker-5.4.4/package/index.js +24 -0
  130. data/webpacker-5.4.4/package/rules/babel.js +28 -0
  131. data/webpacker-5.4.4/package/rules/css.js +3 -0
  132. data/webpacker-5.4.4/package/rules/file.js +21 -0
  133. data/webpacker-5.4.4/package/rules/index.js +20 -0
  134. data/webpacker-5.4.4/package/rules/module.css.js +3 -0
  135. data/webpacker-5.4.4/package/rules/module.sass.js +8 -0
  136. data/webpacker-5.4.4/package/rules/node_modules.js +22 -0
  137. data/webpacker-5.4.4/package/rules/sass.js +17 -0
  138. data/webpacker-5.4.4/package/utils/__tests__/deep_assign.js +32 -0
  139. data/webpacker-5.4.4/package/utils/__tests__/deep_merge.js +10 -0
  140. data/webpacker-5.4.4/package/utils/__tests__/get_style_rule.js +65 -0
  141. data/webpacker-5.4.4/package/utils/__tests__/objectify.js +9 -0
  142. data/webpacker-5.4.4/package/utils/deep_assign.js +22 -0
  143. data/webpacker-5.4.4/package/utils/deep_merge.js +22 -0
  144. data/webpacker-5.4.4/package/utils/get_style_rule.js +45 -0
  145. data/webpacker-5.4.4/package/utils/helpers.js +58 -0
  146. data/webpacker-5.4.4/package/utils/objectify.js +3 -0
  147. data/webpacker-5.4.4/package.json +82 -0
  148. data/webpacker-5.4.4/test/command_test.rb +33 -0
  149. data/webpacker-5.4.4/test/compiler_test.rb +80 -0
  150. data/webpacker-5.4.4/test/configuration_test.rb +109 -0
  151. data/webpacker-5.4.4/test/dev_server_runner_test.rb +51 -0
  152. data/webpacker-5.4.4/test/dev_server_test.rb +47 -0
  153. data/webpacker-5.4.4/test/env_test.rb +23 -0
  154. data/webpacker-5.4.4/test/helper_test.rb +157 -0
  155. data/webpacker-5.4.4/test/manifest_test.rb +73 -0
  156. data/webpacker-5.4.4/test/rake_tasks_test.rb +80 -0
  157. data/webpacker-5.4.4/test/test_app/Rakefile +3 -0
  158. data/webpacker-5.4.4/test/test_app/app/javascript/packs/application.js +10 -0
  159. data/webpacker-5.4.4/test/test_app/app/javascript/packs/multi_entry.css +4 -0
  160. data/webpacker-5.4.4/test/test_app/app/javascript/packs/multi_entry.js +4 -0
  161. data/webpacker-5.4.4/test/test_app/bin/webpack +14 -0
  162. data/webpacker-5.4.4/test/test_app/bin/webpack-dev-server +14 -0
  163. data/webpacker-5.4.4/test/test_app/config/application.rb +11 -0
  164. data/webpacker-5.4.4/test/test_app/config/environment.rb +4 -0
  165. data/webpacker-5.4.4/test/test_app/config/webpack/development.js +0 -0
  166. data/webpacker-5.4.4/test/test_app/config/webpacker.yml +103 -0
  167. data/webpacker-5.4.4/test/test_app/config/webpacker_public_root.yml +19 -0
  168. data/webpacker-5.4.4/test/test_app/config.ru +5 -0
  169. data/webpacker-5.4.4/test/test_app/package.json +13 -0
  170. data/webpacker-5.4.4/test/test_app/public/packs/manifest.json +32 -0
  171. data/webpacker-5.4.4/test/test_app/yarn.lock +11 -0
  172. data/webpacker-5.4.4/test/test_helper.rb +33 -0
  173. data/webpacker-5.4.4/test/webpack_runner_test.rb +51 -0
  174. data/webpacker-5.4.4/test/webpacker_test.rb +13 -0
  175. data/webpacker-5.4.4/webpacker.gemspec +31 -0
  176. data/webpacker-5.4.4/yarn.lock +8271 -0
  177. metadata +215 -0
@@ -0,0 +1,195 @@
1
+ module Webpacker::Helper
2
+ # Returns the current Webpacker instance.
3
+ # Could be overridden to use multiple Webpacker
4
+ # configurations within the same app (e.g. with engines).
5
+ def current_webpacker_instance
6
+ Webpacker.instance
7
+ end
8
+
9
+ # Computes the relative path for a given Webpacker asset.
10
+ # Returns the relative path using manifest.json and passes it to path_to_asset helper.
11
+ # This will use path_to_asset internally, so most of their behaviors will be the same.
12
+ #
13
+ # Example:
14
+ #
15
+ # # When extract_css is false in webpacker.yml and the file is a css:
16
+ # <%= asset_pack_path 'calendar.css' %> # => nil
17
+ #
18
+ # # When extract_css is true in webpacker.yml or the file is not a css:
19
+ # <%= asset_pack_path 'calendar.css' %> # => "/packs/calendar-1016838bab065ae1e122.css"
20
+ def asset_pack_path(name, **options)
21
+ if current_webpacker_instance.config.extract_css? || !stylesheet?(name)
22
+ path_to_asset(current_webpacker_instance.manifest.lookup!(name), options)
23
+ end
24
+ end
25
+
26
+ # Computes the absolute path for a given Webpacker asset.
27
+ # Returns the absolute path using manifest.json and passes it to url_to_asset helper.
28
+ # This will use url_to_asset internally, so most of their behaviors will be the same.
29
+ #
30
+ # Example:
31
+ #
32
+ # # When extract_css is false in webpacker.yml and the file is a css:
33
+ # <%= asset_pack_url 'calendar.css' %> # => nil
34
+ #
35
+ # # When extract_css is true in webpacker.yml or the file is not a css:
36
+ # <%= asset_pack_url 'calendar.css' %> # => "http://example.com/packs/calendar-1016838bab065ae1e122.css"
37
+ def asset_pack_url(name, **options)
38
+ if current_webpacker_instance.config.extract_css? || !stylesheet?(name)
39
+ url_to_asset(current_webpacker_instance.manifest.lookup!(name), options)
40
+ end
41
+ end
42
+
43
+ # Creates an image tag that references the named pack file.
44
+ #
45
+ # Example:
46
+ #
47
+ # <%= image_pack_tag 'application.png', size: '16x10', alt: 'Edit Entry' %>
48
+ # <img alt='Edit Entry' src='/packs/application-k344a6d59eef8632c9d1.png' width='16' height='10' />
49
+ #
50
+ # <%= image_pack_tag 'picture.png', srcset: { 'picture-2x.png' => '2x' } %>
51
+ # <img srcset= "/packs/picture-2x-7cca48e6cae66ec07b8e.png 2x" src="/packs/picture-c38deda30895059837cf.png" >
52
+ def image_pack_tag(name, **options)
53
+ if options[:srcset] && !options[:srcset].is_a?(String)
54
+ options[:srcset] = options[:srcset].map do |src_name, size|
55
+ "#{resolve_path_to_image(src_name)} #{size}"
56
+ end.join(", ")
57
+ end
58
+
59
+ image_tag(resolve_path_to_image(name), options)
60
+ end
61
+
62
+ # Creates a link tag for a favicon that references the named pack file.
63
+ #
64
+ # Example:
65
+ #
66
+ # <%= favicon_pack_tag 'mb-icon.png', rel: 'apple-touch-icon', type: 'image/png' %>
67
+ # <link href="/packs/mb-icon-k344a6d59eef8632c9d1.png" rel="apple-touch-icon" type="image/png" />
68
+ def favicon_pack_tag(name, **options)
69
+ favicon_link_tag(resolve_path_to_image(name), options)
70
+ end
71
+
72
+ # Creates a script tag that references the named pack file, as compiled by webpack per the entries list
73
+ # in package/environments/base.js. By default, this list is auto-generated to match everything in
74
+ # app/javascript/packs/*.js. In production mode, the digested reference is automatically looked up.
75
+ #
76
+ # Example:
77
+ #
78
+ # <%= javascript_pack_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
79
+ # <script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
80
+ def javascript_pack_tag(*names, **options)
81
+ javascript_include_tag(*sources_from_manifest_entries(names, type: :javascript), **options)
82
+ end
83
+
84
+ # Creates script tags that reference the js chunks from entrypoints when using split chunks API,
85
+ # as compiled by webpack per the entries list in package/environments/base.js.
86
+ # By default, this list is auto-generated to match everything in
87
+ # app/javascript/packs/*.js and all the dependent chunks. In production mode, the digested reference is automatically looked up.
88
+ # See: https://webpack.js.org/plugins/split-chunks-plugin/
89
+ #
90
+ # Example:
91
+ #
92
+ # <%= javascript_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %> # =>
93
+ # <script src="/packs/vendor-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
94
+ # <script src="/packs/calendar~runtime-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
95
+ # <script src="/packs/calendar-1016838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
96
+ # <script src="/packs/map~runtime-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
97
+ # <script src="/packs/map-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
98
+ #
99
+ # DO:
100
+ #
101
+ # <%= javascript_packs_with_chunks_tag 'calendar', 'map' %>
102
+ #
103
+ # DON'T:
104
+ #
105
+ # <%= javascript_packs_with_chunks_tag 'calendar' %>
106
+ # <%= javascript_packs_with_chunks_tag 'map' %>
107
+ def javascript_packs_with_chunks_tag(*names, **options)
108
+ javascript_include_tag(*sources_from_manifest_entrypoints(names, type: :javascript), **options)
109
+ end
110
+
111
+ # Creates a link tag, for preloading, that references a given Webpacker asset.
112
+ # In production mode, the digested reference is automatically looked up.
113
+ # See: https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content
114
+ #
115
+ # Example:
116
+ #
117
+ # <%= preload_pack_asset 'fonts/fa-regular-400.woff2' %> # =>
118
+ # <link rel="preload" href="/packs/fonts/fa-regular-400-944fb546bd7018b07190a32244f67dc9.woff2" as="font" type="font/woff2" crossorigin="anonymous">
119
+ def preload_pack_asset(name, **options)
120
+ if self.class.method_defined?(:preload_link_tag)
121
+ preload_link_tag(current_webpacker_instance.manifest.lookup!(name), options)
122
+ else
123
+ raise "You need Rails >= 5.2 to use this tag."
124
+ end
125
+ end
126
+
127
+ # Creates a link tag that references the named pack file, as compiled by webpack per the entries list
128
+ # in package/environments/base.js. By default, this list is auto-generated to match everything in
129
+ # app/javascript/packs/*.js. In production mode, the digested reference is automatically looked up.
130
+ #
131
+ # Note: If the development server is running and hot module replacement is active, this will return nothing.
132
+ # In that setup you need to configure your styles to be inlined in your JavaScript for hot reloading.
133
+ #
134
+ # Examples:
135
+ #
136
+ # # When extract_css is false in webpacker.yml:
137
+ # <%= stylesheet_pack_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
138
+ # nil
139
+ #
140
+ # # When extract_css is true in webpacker.yml:
141
+ # <%= stylesheet_pack_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
142
+ # <link rel="stylesheet" media="screen" href="/packs/calendar-1016838bab065ae1e122.css" data-turbolinks-track="reload" />
143
+ def stylesheet_pack_tag(*names, **options)
144
+ if current_webpacker_instance.config.extract_css?
145
+ stylesheet_link_tag(*sources_from_manifest_entries(names, type: :stylesheet), **options)
146
+ end
147
+ end
148
+
149
+ # Creates link tags that reference the css chunks from entrypoints when using split chunks API,
150
+ # as compiled by webpack per the entries list in package/environments/base.js.
151
+ # By default, this list is auto-generated to match everything in
152
+ # app/javascript/packs/*.js and all the dependent chunks. In production mode, the digested reference is automatically looked up.
153
+ # See: https://webpack.js.org/plugins/split-chunks-plugin/
154
+ #
155
+ # Examples:
156
+ #
157
+ # <%= stylesheet_packs_with_chunks_tag 'calendar', 'map' %> # =>
158
+ # <link rel="stylesheet" media="screen" href="/packs/3-8c7ce31a.chunk.css" />
159
+ # <link rel="stylesheet" media="screen" href="/packs/calendar-8c7ce31a.chunk.css" />
160
+ # <link rel="stylesheet" media="screen" href="/packs/map-8c7ce31a.chunk.css" />
161
+ #
162
+ # DO:
163
+ #
164
+ # <%= stylesheet_packs_with_chunks_tag 'calendar', 'map' %>
165
+ #
166
+ # DON'T:
167
+ #
168
+ # <%= stylesheet_packs_with_chunks_tag 'calendar' %>
169
+ # <%= stylesheet_packs_with_chunks_tag 'map' %>
170
+ def stylesheet_packs_with_chunks_tag(*names, **options)
171
+ if current_webpacker_instance.config.extract_css?
172
+ stylesheet_link_tag(*sources_from_manifest_entrypoints(names, type: :stylesheet), **options)
173
+ end
174
+ end
175
+
176
+ private
177
+ def stylesheet?(name)
178
+ File.extname(name) == ".css"
179
+ end
180
+
181
+ def sources_from_manifest_entries(names, type:)
182
+ names.map { |name| current_webpacker_instance.manifest.lookup!(name, type: type) }.flatten
183
+ end
184
+
185
+ def sources_from_manifest_entrypoints(names, type:)
186
+ names.map { |name| current_webpacker_instance.manifest.lookup_pack_with_chunks!(name, type: type) }.flatten.uniq
187
+ end
188
+
189
+ def resolve_path_to_image(name)
190
+ path = name.starts_with?("media/images/") ? name : "media/images/#{name}"
191
+ path_to_asset(current_webpacker_instance.manifest.lookup!(path))
192
+ rescue
193
+ path_to_asset(current_webpacker_instance.manifest.lookup!(name))
194
+ end
195
+ end
@@ -0,0 +1,37 @@
1
+ class Webpacker::Instance
2
+ cattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) }
3
+
4
+ attr_reader :root_path, :config_path
5
+
6
+ def initialize(root_path: Rails.root, config_path: Rails.root.join("config/webpacker.yml"))
7
+ @root_path, @config_path = root_path, config_path
8
+ end
9
+
10
+ def env
11
+ @env ||= Webpacker::Env.inquire self
12
+ end
13
+
14
+ def config
15
+ @config ||= Webpacker::Configuration.new(
16
+ root_path: root_path,
17
+ config_path: config_path,
18
+ env: env
19
+ )
20
+ end
21
+
22
+ def compiler
23
+ @compiler ||= Webpacker::Compiler.new self
24
+ end
25
+
26
+ def dev_server
27
+ @dev_server ||= Webpacker::DevServer.new config
28
+ end
29
+
30
+ def manifest
31
+ @manifest ||= Webpacker::Manifest.new self
32
+ end
33
+
34
+ def commands
35
+ @commands ||= Webpacker::Commands.new self
36
+ end
37
+ end
@@ -0,0 +1,118 @@
1
+ # Singleton registry for accessing the packs path using a generated manifest.
2
+ # This allows javascript_pack_tag, stylesheet_pack_tag, asset_pack_path to take a reference to,
3
+ # say, "calendar.js" or "calendar.css" and turn it into "/packs/calendar-1016838bab065ae1e314.js" or
4
+ # "/packs/calendar-1016838bab065ae1e314.css".
5
+ #
6
+ # When the configuration is set to on-demand compilation, with the `compile: true` option in
7
+ # the webpacker.yml file, any lookups will be preceded by a compilation if one is needed.
8
+ class Webpacker::Manifest
9
+ class MissingEntryError < StandardError; end
10
+
11
+ delegate :config, :compiler, :dev_server, to: :@webpacker
12
+
13
+ def initialize(webpacker)
14
+ @webpacker = webpacker
15
+ end
16
+
17
+ def refresh
18
+ @data = load
19
+ end
20
+
21
+ def lookup_pack_with_chunks(name, pack_type = {})
22
+ compile if compiling?
23
+
24
+ manifest_pack_type = manifest_type(pack_type[:type])
25
+ manifest_pack_name = manifest_name(name, manifest_pack_type)
26
+ find("entrypoints")[manifest_pack_name][manifest_pack_type]
27
+ rescue NoMethodError
28
+ nil
29
+ end
30
+
31
+ def lookup_pack_with_chunks!(name, pack_type = {})
32
+ lookup_pack_with_chunks(name, pack_type) || handle_missing_entry(name, pack_type)
33
+ end
34
+
35
+ # Computes the relative path for a given Webpacker asset using manifest.json.
36
+ # If no asset is found, returns nil.
37
+ #
38
+ # Example:
39
+ #
40
+ # Webpacker.manifest.lookup('calendar.js') # => "/packs/calendar-1016838bab065ae1e122.js"
41
+ def lookup(name, pack_type = {})
42
+ compile if compiling?
43
+
44
+ find(full_pack_name(name, pack_type[:type]))
45
+ end
46
+
47
+ # Like lookup, except that if no asset is found, raises a Webpacker::Manifest::MissingEntryError.
48
+ def lookup!(name, pack_type = {})
49
+ lookup(name, pack_type) || handle_missing_entry(name, pack_type)
50
+ end
51
+
52
+ private
53
+ def compiling?
54
+ config.compile? && !dev_server.running?
55
+ end
56
+
57
+ def compile
58
+ Webpacker.logger.tagged("Webpacker") { compiler.compile }
59
+ end
60
+
61
+ def data
62
+ if config.cache_manifest?
63
+ @data ||= load
64
+ else
65
+ refresh
66
+ end
67
+ end
68
+
69
+ def find(name)
70
+ data[name.to_s].presence
71
+ end
72
+
73
+ def full_pack_name(name, pack_type)
74
+ return name unless File.extname(name.to_s).empty?
75
+ "#{name}.#{manifest_type(pack_type)}"
76
+ end
77
+
78
+ def handle_missing_entry(name, pack_type)
79
+ raise Webpacker::Manifest::MissingEntryError, missing_file_from_manifest_error(full_pack_name(name, pack_type[:type]))
80
+ end
81
+
82
+ def load
83
+ if config.public_manifest_path.exist?
84
+ JSON.parse config.public_manifest_path.read
85
+ else
86
+ {}
87
+ end
88
+ end
89
+
90
+ # The `manifest_name` method strips of the file extension of the name, because in the
91
+ # manifest hash the entrypoints are defined by their pack name without the extension.
92
+ # When the user provides a name with a file extension, we want to try to strip it off.
93
+ def manifest_name(name, pack_type)
94
+ return name if File.extname(name.to_s).empty?
95
+ File.basename(name, pack_type)
96
+ end
97
+
98
+ def manifest_type(pack_type)
99
+ case pack_type
100
+ when :javascript then "js"
101
+ when :stylesheet then "css"
102
+ else pack_type.to_s
103
+ end
104
+ end
105
+
106
+ def missing_file_from_manifest_error(bundle_name)
107
+ <<-MSG
108
+ Webpacker can't find #{bundle_name} in #{config.public_manifest_path}. Possible causes:
109
+ 1. You want to set webpacker.yml value of compile to true for your environment
110
+ unless you are using the `webpack -w` or the webpack-dev-server.
111
+ 2. webpack has not yet re-run to reflect updates.
112
+ 3. You have misconfigured Webpacker's config/webpacker.yml file.
113
+ 4. Your webpack configuration is not creating a manifest.
114
+ Your manifest contains:
115
+ #{JSON.pretty_generate(@data)}
116
+ MSG
117
+ end
118
+ end
@@ -0,0 +1,55 @@
1
+ require "rails/railtie"
2
+
3
+ require "webpacker/helper"
4
+ require "webpacker/dev_server_proxy"
5
+
6
+ class Webpacker::Engine < ::Rails::Engine
7
+ # Allows Webpacker config values to be set via Rails env config files
8
+ config.webpacker = ActiveSupport::OrderedOptions.new
9
+
10
+ initializer "webpacker.proxy" do |app|
11
+ insert_middleware = Webpacker.config.dev_server.present? rescue nil
12
+ if insert_middleware
13
+ app.middleware.insert_before 0,
14
+ Rails::VERSION::MAJOR >= 5 ?
15
+ Webpacker::DevServerProxy : "Webpacker::DevServerProxy", ssl_verify_none: true
16
+ end
17
+ end
18
+
19
+ initializer "webpacker.helper" do
20
+ ActiveSupport.on_load :action_controller do
21
+ ActionController::Base.helper Webpacker::Helper
22
+ end
23
+
24
+ ActiveSupport.on_load :action_view do
25
+ include Webpacker::Helper
26
+ end
27
+ end
28
+
29
+ initializer "webpacker.logger" do
30
+ config.after_initialize do
31
+ if ::Rails.logger.respond_to?(:tagged)
32
+ Webpacker.logger = ::Rails.logger
33
+ else
34
+ Webpacker.logger = ActiveSupport::TaggedLogging.new(::Rails.logger)
35
+ end
36
+ end
37
+ end
38
+
39
+ initializer "webpacker.bootstrap" do
40
+ if defined?(Rails::Server) || defined?(Rails::Console)
41
+ Webpacker.bootstrap
42
+ if defined?(Spring)
43
+ require "spring/watcher"
44
+ Spring.after_fork { Webpacker.bootstrap }
45
+ Spring.watch(Webpacker.config.config_path)
46
+ end
47
+ end
48
+ end
49
+
50
+ initializer "webpacker.set_source" do |app|
51
+ if Webpacker.config.config_path.exist?
52
+ app.config.javascript_path = Webpacker.config.source_path.relative_path_from(Rails.root.join("app")).to_s
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,23 @@
1
+ module Webpacker
2
+ class Runner
3
+ def self.run(argv)
4
+ $stdout.sync = true
5
+
6
+ new(argv).run
7
+ end
8
+
9
+ def initialize(argv)
10
+ @argv = argv
11
+
12
+ @app_path = File.expand_path(".", Dir.pwd)
13
+ @node_modules_bin_path = ENV["WEBPACKER_NODE_MODULES_BIN_PATH"] || `yarn bin`.chomp
14
+ @webpack_config = File.join(@app_path, "config/webpack/#{ENV["NODE_ENV"]}.js")
15
+ @webpacker_config = File.join(@app_path, "config/webpacker.yml")
16
+
17
+ unless File.exist?(@webpack_config)
18
+ $stderr.puts "webpack config #{@webpack_config} not found, please run 'bundle exec rails webpacker:install' to install Webpacker with default configs or add the missing config file for your custom environment."
19
+ exit!
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,4 @@
1
+ module Webpacker
2
+ # Change the version in package.json too, please!
3
+ VERSION = "5.4.4".freeze
4
+ end
@@ -0,0 +1,32 @@
1
+ require "shellwords"
2
+ require "webpacker/runner"
3
+
4
+ module Webpacker
5
+ class WebpackRunner < Webpacker::Runner
6
+ def run
7
+ env = Webpacker::Compiler.env
8
+ env["WEBPACKER_CONFIG"] = @webpacker_config
9
+
10
+ cmd = if node_modules_bin_exist?
11
+ ["#{@node_modules_bin_path}/webpack"]
12
+ else
13
+ ["yarn", "webpack"]
14
+ end
15
+
16
+ if @argv.include?("--debug-webpacker")
17
+ cmd = [ "node", "--inspect-brk"] + cmd
18
+ end
19
+
20
+ cmd += ["--config", @webpack_config] + @argv
21
+
22
+ Dir.chdir(@app_path) do
23
+ Kernel.exec env, *cmd
24
+ end
25
+ end
26
+
27
+ private
28
+ def node_modules_bin_exist?
29
+ File.exist?("#{@node_modules_bin_path}/webpack")
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,46 @@
1
+ require "active_support/core_ext/module/attribute_accessors"
2
+ require "active_support/core_ext/string/inquiry"
3
+ require "active_support/logger"
4
+ require "active_support/tagged_logging"
5
+
6
+ module Webpacker
7
+ extend self
8
+
9
+ def instance=(instance)
10
+ @instance = instance
11
+ end
12
+
13
+ def instance
14
+ @instance ||= Webpacker::Instance.new
15
+ end
16
+
17
+ def with_node_env(env)
18
+ original = ENV["NODE_ENV"]
19
+ ENV["NODE_ENV"] = env
20
+ yield
21
+ ensure
22
+ ENV["NODE_ENV"] = original
23
+ end
24
+
25
+ def ensure_log_goes_to_stdout
26
+ old_logger = Webpacker.logger
27
+ Webpacker.logger = ActiveSupport::Logger.new(STDOUT)
28
+ yield
29
+ ensure
30
+ Webpacker.logger = old_logger
31
+ end
32
+
33
+ delegate :logger, :logger=, :env, to: :instance
34
+ delegate :config, :compiler, :manifest, :commands, :dev_server, to: :instance
35
+ delegate :bootstrap, :clean, :clobber, :compile, to: :commands
36
+ end
37
+
38
+ require "webpacker/instance"
39
+ require "webpacker/env"
40
+ require "webpacker/configuration"
41
+ require "webpacker/manifest"
42
+ require "webpacker/compiler"
43
+ require "webpacker/commands"
44
+ require "webpacker/dev_server"
45
+
46
+ require "webpacker/railtie" if defined?(Rails)
@@ -0,0 +1,66 @@
1
+ /* global test expect, describe */
2
+
3
+ const { chdirCwd, chdirTestApp, resetEnv } = require('../utils/helpers')
4
+
5
+ chdirTestApp()
6
+
7
+ const config = require('../config')
8
+
9
+ describe('Config', () => {
10
+ beforeEach(() => jest.resetModules() && resetEnv())
11
+ afterAll(chdirCwd)
12
+
13
+ test('public path', () => {
14
+ process.env.RAILS_ENV = 'development'
15
+ const config = require('../config')
16
+ expect(config.publicPath).toEqual('/packs/')
17
+ })
18
+
19
+ test('public path with asset host', () => {
20
+ process.env.RAILS_ENV = 'development'
21
+ process.env.WEBPACKER_ASSET_HOST = 'http://foo.com/'
22
+ const config = require('../config')
23
+ expect(config.publicPath).toEqual('http://foo.com/packs/')
24
+ })
25
+
26
+ test('should return additional paths as listed in app config, with resolved paths', () => {
27
+ expect(config.additional_paths).toEqual(
28
+ [
29
+ 'app/assets',
30
+ '/etc/yarn',
31
+ 'app/elm'
32
+ ]
33
+ )
34
+ })
35
+
36
+ test('should return extensions as listed in app config', () => {
37
+ expect(config.extensions).toEqual([
38
+ '.mjs',
39
+ '.js',
40
+ '.sass',
41
+ '.scss',
42
+ '.css',
43
+ '.module.sass',
44
+ '.module.scss',
45
+ '.module.css',
46
+ '.png',
47
+ '.svg',
48
+ '.gif',
49
+ '.jpeg',
50
+ '.jpg',
51
+ '.elm'
52
+ ])
53
+ })
54
+
55
+ test('should return static assets extensions as listed in app config', () => {
56
+ expect(config.static_assets_extensions).toEqual([
57
+ '.jpg',
58
+ '.jpeg',
59
+ '.png',
60
+ '.gif',
61
+ '.tiff',
62
+ '.ico',
63
+ '.svg',
64
+ ])
65
+ })
66
+ })
@@ -0,0 +1,45 @@
1
+ /* global test expect, describe */
2
+
3
+ const { chdirTestApp, chdirCwd } = require('../utils/helpers')
4
+
5
+ chdirTestApp()
6
+
7
+ describe('DevServer', () => {
8
+ beforeEach(() => jest.resetModules())
9
+ afterAll(chdirCwd)
10
+
11
+ test('with NODE_ENV and RAILS_ENV set to development', () => {
12
+ process.env.NODE_ENV = 'development'
13
+ process.env.RAILS_ENV = 'development'
14
+ process.env.WEBPACKER_DEV_SERVER_HOST = '0.0.0.0'
15
+ process.env.WEBPACKER_DEV_SERVER_PORT = 5000
16
+ process.env.WEBPACKER_DEV_SERVER_DISABLE_HOST_CHECK = false
17
+
18
+ const devServer = require('../dev_server')
19
+ expect(devServer).toBeDefined()
20
+ expect(devServer.host).toEqual('0.0.0.0')
21
+ expect(devServer.port).toEqual('5000')
22
+ expect(devServer.disable_host_check).toBe(false)
23
+ })
24
+
25
+ test('with custom env prefix', () => {
26
+ const config = require('../config')
27
+ config.dev_server.env_prefix = 'TEST_WEBPACKER_DEV_SERVER'
28
+
29
+ process.env.NODE_ENV = 'development'
30
+ process.env.RAILS_ENV = 'development'
31
+ process.env.TEST_WEBPACKER_DEV_SERVER_HOST = '0.0.0.0'
32
+ process.env.TEST_WEBPACKER_DEV_SERVER_PORT = 5000
33
+
34
+ const devServer = require('../dev_server')
35
+ expect(devServer).toBeDefined()
36
+ expect(devServer.host).toEqual('0.0.0.0')
37
+ expect(devServer.port).toEqual('5000')
38
+ })
39
+
40
+ test('with NODE_ENV and RAILS_ENV set to production', () => {
41
+ process.env.RAILS_ENV = 'production'
42
+ process.env.NODE_ENV = 'production'
43
+ expect(require('../dev_server')).toEqual({})
44
+ })
45
+ })
@@ -0,0 +1,43 @@
1
+ /* test expect, describe, afterAll, beforeEach */
2
+
3
+ const { resolve } = require('path')
4
+ const { chdirTestApp, chdirCwd } = require('../utils/helpers')
5
+
6
+ chdirTestApp()
7
+
8
+ describe('Development environment', () => {
9
+ afterAll(chdirCwd)
10
+
11
+ describe('toWebpackConfig', () => {
12
+ beforeEach(() => jest.resetModules())
13
+
14
+ test('should use development config and environment including devServer if WEBPACK_DEV_SERVER', () => {
15
+ process.env.RAILS_ENV = 'development'
16
+ process.env.NODE_ENV = 'development'
17
+ process.env.WEBPACK_DEV_SERVER = 'YES'
18
+ const { environment } = require('../index')
19
+
20
+ const config = environment.toWebpackConfig()
21
+ expect(config.output.path).toEqual(resolve('public', 'packs'))
22
+ expect(config.output.publicPath).toEqual('/packs/')
23
+ expect(config).toMatchObject({
24
+ devServer: {
25
+ host: 'localhost',
26
+ port: 3035
27
+ }
28
+ })
29
+ })
30
+
31
+ test('should use development config and environment if WEBPACK_DEV_SERVER', () => {
32
+ process.env.RAILS_ENV = 'development'
33
+ process.env.NODE_ENV = 'development'
34
+ process.env.WEBPACK_DEV_SERVER = undefined
35
+ const { environment } = require('../index')
36
+
37
+ const config = environment.toWebpackConfig()
38
+ expect(config.output.path).toEqual(resolve('public', 'packs'))
39
+ expect(config.output.publicPath).toEqual('/packs/')
40
+ expect(config.devServer).toEqual(undefined)
41
+ })
42
+ })
43
+ })