webpacker 5.0.1 → 6.0.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +8 -8
  3. data/.github/workflows/jest.yml +38 -0
  4. data/.github/workflows/js-lint.yml +39 -0
  5. data/.github/workflows/rubocop.yml +39 -0
  6. data/.github/workflows/ruby.yml +70 -0
  7. data/.gitignore +2 -0
  8. data/.node-version +1 -1
  9. data/.rubocop.yml +11 -16
  10. data/CHANGELOG.md +33 -1
  11. data/CONTRIBUTING.md +1 -1
  12. data/Gemfile.lock +91 -85
  13. data/README.md +27 -44
  14. data/docs/assets.md +21 -5
  15. data/docs/css.md +80 -30
  16. data/docs/deployment.md +18 -0
  17. data/docs/docker.md +2 -2
  18. data/docs/engines.md +1 -1
  19. data/docs/env.md +4 -1
  20. data/docs/es6.md +1 -1
  21. data/docs/integrations.md +2 -2
  22. data/docs/props.md +2 -38
  23. data/docs/react.md +183 -0
  24. data/docs/target.md +22 -0
  25. data/docs/testing.md +13 -3
  26. data/docs/troubleshooting.md +3 -1
  27. data/docs/typescript.md +92 -27
  28. data/docs/webpack-dev-server.md +17 -15
  29. data/docs/webpack.md +58 -107
  30. data/lib/install/config/webpack/base.js +3 -0
  31. data/lib/install/config/webpack/development.js +2 -2
  32. data/lib/install/config/webpack/production.js +2 -2
  33. data/lib/install/config/webpack/test.js +2 -2
  34. data/lib/install/config/webpacker.yml +9 -42
  35. data/lib/install/examples/{vue → vue3}/app.vue +10 -5
  36. data/lib/install/examples/vue3/hello_vue.js +15 -0
  37. data/lib/install/javascript/packs/application.css +9 -0
  38. data/lib/install/template.rb +33 -19
  39. data/lib/tasks/webpacker.rake +2 -11
  40. data/lib/tasks/webpacker/binstubs.rake +6 -4
  41. data/lib/tasks/webpacker/check_binstubs.rake +4 -4
  42. data/lib/tasks/webpacker/check_node.rake +1 -1
  43. data/lib/tasks/webpacker/check_yarn.rake +2 -3
  44. data/lib/tasks/webpacker/compile.rake +4 -2
  45. data/lib/tasks/webpacker/info.rake +12 -10
  46. data/lib/tasks/webpacker/install.rake +6 -4
  47. data/lib/tasks/webpacker/verify_install.rake +2 -1
  48. data/lib/tasks/webpacker/yarn_install.rake +9 -1
  49. data/lib/webpacker/commands.rb +1 -1
  50. data/lib/webpacker/compiler.rb +14 -9
  51. data/lib/webpacker/configuration.rb +7 -27
  52. data/lib/webpacker/dev_server_proxy.rb +3 -1
  53. data/lib/webpacker/dev_server_runner.rb +23 -4
  54. data/lib/webpacker/helper.rb +55 -46
  55. data/lib/webpacker/manifest.rb +1 -1
  56. data/lib/webpacker/railtie.rb +0 -43
  57. data/lib/webpacker/runner.rb +1 -0
  58. data/lib/webpacker/version.rb +1 -1
  59. data/lib/webpacker/webpack_runner.rb +7 -2
  60. data/package.json +27 -43
  61. data/package/__tests__/config.js +6 -27
  62. data/package/__tests__/dev_server.js +2 -0
  63. data/package/__tests__/development.js +18 -7
  64. data/package/__tests__/env.js +12 -4
  65. data/package/__tests__/production.js +6 -6
  66. data/package/__tests__/staging.js +7 -6
  67. data/package/__tests__/test.js +4 -5
  68. data/package/babel/preset-react.js +62 -0
  69. data/package/babel/preset.js +44 -0
  70. data/package/config.js +4 -9
  71. data/package/configPath.js +3 -0
  72. data/package/dev_server.js +1 -1
  73. data/package/env.js +9 -4
  74. data/package/environments/__tests__/base.js +21 -36
  75. data/package/environments/base.js +67 -128
  76. data/package/environments/development.js +46 -39
  77. data/package/environments/production.js +69 -67
  78. data/package/environments/test.js +2 -2
  79. data/package/index.js +6 -6
  80. data/package/rules/babel.js +20 -11
  81. data/package/rules/coffee.js +6 -0
  82. data/package/rules/erb.js +13 -0
  83. data/package/rules/file.js +19 -18
  84. data/package/rules/index.js +24 -18
  85. data/package/rules/less.js +18 -0
  86. data/package/rules/sass.js +6 -7
  87. data/package/rules/svg.js +23 -0
  88. data/package/utils/get_style_rule.js +22 -28
  89. data/package/utils/helpers.js +3 -35
  90. data/test/compiler_test.rb +4 -11
  91. data/test/configuration_test.rb +2 -32
  92. data/test/dev_server_runner_test.rb +25 -6
  93. data/test/engine_rake_tasks_test.rb +39 -0
  94. data/test/helper_test.rb +18 -9
  95. data/test/mounted_app/Rakefile +4 -0
  96. data/test/mounted_app/test/dummy/Rakefile +3 -0
  97. data/test/mounted_app/test/dummy/bin/rails +3 -0
  98. data/test/mounted_app/test/dummy/bin/rake +3 -0
  99. data/test/mounted_app/test/dummy/config.ru +5 -0
  100. data/test/mounted_app/test/dummy/config/application.rb +10 -0
  101. data/test/mounted_app/test/dummy/config/environment.rb +3 -0
  102. data/test/mounted_app/test/dummy/config/webpacker.yml +75 -0
  103. data/test/mounted_app/test/dummy/package.json +7 -0
  104. data/test/rake_tasks_test.rb +1 -10
  105. data/test/test_app/config/application.rb +0 -1
  106. data/test/test_app/config/webpacker.yml +3 -21
  107. data/test/test_app/config/webpacker_public_root.yml +0 -1
  108. data/test/test_app/public/packs/manifest.json +18 -13
  109. data/test/test_app/some.config.js +0 -0
  110. data/test/webpack_runner_test.rb +10 -4
  111. data/webpacker.gemspec +1 -1
  112. data/yarn.lock +2657 -6224
  113. metadata +53 -71
  114. data/.travis.yml +0 -43
  115. data/lib/install/angular.rb +0 -23
  116. data/lib/install/coffee.rb +0 -25
  117. data/lib/install/config/.browserslistrc +0 -1
  118. data/lib/install/config/babel.config.js +0 -72
  119. data/lib/install/config/postcss.config.js +0 -12
  120. data/lib/install/config/webpack/environment.js +0 -3
  121. data/lib/install/elm.rb +0 -39
  122. data/lib/install/erb.rb +0 -25
  123. data/lib/install/examples/angular/hello_angular.js +0 -7
  124. data/lib/install/examples/angular/hello_angular/app/app.component.ts +0 -9
  125. data/lib/install/examples/angular/hello_angular/app/app.module.ts +0 -16
  126. data/lib/install/examples/angular/hello_angular/index.ts +0 -8
  127. data/lib/install/examples/angular/hello_angular/polyfills.ts +0 -73
  128. data/lib/install/examples/coffee/hello_coffee.coffee +0 -4
  129. data/lib/install/examples/elm/Main.elm +0 -55
  130. data/lib/install/examples/elm/hello_elm.js +0 -16
  131. data/lib/install/examples/erb/hello_erb.js.erb +0 -6
  132. data/lib/install/examples/react/babel.config.js +0 -87
  133. data/lib/install/examples/react/hello_react.jsx +0 -26
  134. data/lib/install/examples/react/tsconfig.json +0 -20
  135. data/lib/install/examples/stimulus/application.js +0 -1
  136. data/lib/install/examples/stimulus/controllers/hello_controller.js +0 -18
  137. data/lib/install/examples/stimulus/controllers/index.js +0 -9
  138. data/lib/install/examples/svelte/app.svelte +0 -11
  139. data/lib/install/examples/svelte/hello_svelte.js +0 -20
  140. data/lib/install/examples/typescript/hello_typescript.ts +0 -4
  141. data/lib/install/examples/typescript/tsconfig.json +0 -23
  142. data/lib/install/examples/vue/hello_vue.js +0 -72
  143. data/lib/install/loaders/coffee.js +0 -6
  144. data/lib/install/loaders/elm.js +0 -25
  145. data/lib/install/loaders/erb.js +0 -11
  146. data/lib/install/loaders/svelte.js +0 -9
  147. data/lib/install/loaders/typescript.js +0 -11
  148. data/lib/install/loaders/vue.js +0 -6
  149. data/lib/install/react.rb +0 -18
  150. data/lib/install/stimulus.rb +0 -12
  151. data/lib/install/svelte.rb +0 -29
  152. data/lib/install/typescript.rb +0 -46
  153. data/lib/install/vue.rb +0 -49
  154. data/lib/tasks/installers.rake +0 -42
  155. data/package/config_types/__tests__/config_list.js +0 -118
  156. data/package/config_types/__tests__/config_object.js +0 -43
  157. data/package/config_types/config_list.js +0 -75
  158. data/package/config_types/config_object.js +0 -55
  159. data/package/config_types/index.js +0 -7
  160. data/package/rules/module.css.js +0 -3
  161. data/package/rules/module.sass.js +0 -8
  162. data/package/rules/node_modules.js +0 -24
  163. data/package/utils/__tests__/deep_assign.js +0 -32
  164. data/package/utils/__tests__/deep_merge.js +0 -10
  165. data/package/utils/__tests__/get_style_rule.js +0 -65
  166. data/package/utils/__tests__/objectify.js +0 -9
  167. data/package/utils/deep_assign.js +0 -22
  168. data/package/utils/deep_merge.js +0 -22
  169. data/package/utils/objectify.js +0 -3
@@ -1,14 +1,13 @@
1
+ const sass = require('sass')
1
2
  const getStyleRule = require('../utils/get_style_rule')
2
- const { resolved_paths: includePaths } = require('../config')
3
+ const { additional_paths: includePaths } = require('../config')
3
4
 
4
- module.exports = getStyleRule(/\.(scss|sass)(\.erb)?$/i, false, [
5
+ module.exports = getStyleRule(/\.(scss|sass)(\.erb)?$/i, [
5
6
  {
6
- loader: 'sass-loader',
7
+ loader: require.resolve('sass-loader'),
7
8
  options: {
8
- sourceMap: true,
9
- sassOptions: {
10
- includePaths
11
- }
9
+ sassOptions: { includePaths },
10
+ implementation: sass
12
11
  }
13
12
  }
14
13
  ])
@@ -0,0 +1,23 @@
1
+ /* eslint global-require: 0 */
2
+ /* eslint import/no-dynamic-require: 0 */
3
+
4
+ module.exports = {
5
+ test: /\.svg$/i,
6
+ type: 'asset/inline',
7
+ generator: {
8
+ dataUrl: (content) => {
9
+ let optimisedContent = content
10
+
11
+ try {
12
+ if (require.resolve('mini-svg-data-uri')) {
13
+ const svgToMiniDataURI = require('mini-svg-data-uri')
14
+ optimisedContent = svgToMiniDataURI(content.toString())
15
+ }
16
+ } catch (e) {
17
+ /* Work out what to print here */
18
+ }
19
+
20
+ return optimisedContent
21
+ }
22
+ }
23
+ }
@@ -1,44 +1,38 @@
1
1
  const MiniCssExtractPlugin = require('mini-css-extract-plugin')
2
- const { resolve } = require('path')
3
- const config = require('../config')
4
2
 
5
- const styleLoader = {
6
- loader: 'style-loader'
3
+ const tryPostcss = () => {
4
+ let postcssLoader = false
5
+ try {
6
+ if (require.resolve('postcss-loader')) {
7
+ postcssLoader = {
8
+ loader: require.resolve('postcss-loader'),
9
+ options: { sourceMap: true }
10
+ }
11
+ }
12
+ } catch (e) {
13
+ /* Work out what to print here */
14
+ }
15
+
16
+ return postcssLoader
7
17
  }
8
18
 
9
- const getStyleRule = (test, modules = false, preprocessors = []) => {
19
+ const getStyleRule = (test, preprocessors = []) => {
10
20
  const use = [
21
+ { loader: MiniCssExtractPlugin.loader },
11
22
  {
12
- loader: 'css-loader',
23
+ loader: require.resolve('css-loader'),
13
24
  options: {
14
25
  sourceMap: true,
15
- importLoaders: 2,
16
- modules: modules ? {
17
- localIdentName: '[name]__[local]___[hash:base64:5]'
18
- } : false
19
- }
20
- },
21
- {
22
- loader: 'postcss-loader',
23
- options: {
24
- config: { path: resolve() },
25
- sourceMap: true
26
+ importLoaders: 2
26
27
  }
27
28
  },
29
+ tryPostcss(),
28
30
  ...preprocessors
29
- ]
30
-
31
- const options = modules ? { include: /\.module\.[a-z]+$/ } : { exclude: /\.module\.[a-z]+$/ }
32
-
33
- if (config.extract_css) {
34
- use.unshift(MiniCssExtractPlugin.loader)
35
- } else {
36
- use.unshift(styleLoader)
37
- }
31
+ ].filter(Boolean)
38
32
 
39
- // sideEffects - See https://github.com/webpack/webpack/issues/6571
40
33
  return {
41
- test, use, sideEffects: !modules, ...options
34
+ test,
35
+ use
42
36
  }
43
37
  }
44
38
 
@@ -1,30 +1,5 @@
1
- const { stringify } = require('flatted/cjs')
2
-
3
- const isObject = (value) => typeof value === 'object'
4
- && value !== null
5
- && (value.length === undefined || value.length === null)
6
-
7
- const isNotObject = (value) => !isObject(value)
8
-
9
- const isBoolean = (str) => /^true/.test(str) || /^false/.test(str)
10
-
11
- const isEmpty = (value) => value === null || value === undefined
12
-
13
- const isString = (key) => key && typeof key === 'string'
14
-
15
- const isStrPath = (key) => {
16
- if (!isString(key)) throw new Error(`Key ${key} should be string`)
17
- return isString(key) && key.includes('.')
18
- }
19
-
20
1
  const isArray = (value) => Array.isArray(value)
21
-
22
- const isEqual = (target, source) => stringify(target) === stringify(source)
23
-
24
- const canMerge = (value) => isObject(value) || isArray(value)
25
-
26
- const prettyPrint = (obj) => JSON.stringify(obj, null, 2)
27
-
2
+ const isBoolean = (str) => /^true/.test(str) || /^false/.test(str)
28
3
  const chdirTestApp = () => {
29
4
  try {
30
5
  return process.chdir('test/test_app')
@@ -44,15 +19,8 @@ const ensureTrailingSlash = (path) => (path.endsWith('/') ? path : `${path}/`)
44
19
  module.exports = {
45
20
  chdirTestApp,
46
21
  chdirCwd,
47
- ensureTrailingSlash,
48
- isObject,
49
- isNotObject,
50
- isBoolean,
51
22
  isArray,
52
- isEqual,
53
- isEmpty,
54
- isStrPath,
55
- canMerge,
56
- prettyPrint,
23
+ isBoolean,
24
+ ensureTrailingSlash,
57
25
  resetEnv
58
26
  }
@@ -23,22 +23,15 @@ 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}",
29
- "/etc/yarn/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg}",
30
- "app/javascript/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg}",
31
- "yarn.lock",
32
- "package.json",
33
- "config/webpack/**/*"
34
- ]
35
- end
36
-
37
26
  def test_freshness
38
27
  assert Webpacker.compiler.stale?
39
28
  assert !Webpacker.compiler.fresh?
40
29
  end
41
30
 
31
+ def test_compile
32
+ assert !Webpacker.compiler.compile
33
+ end
34
+
42
35
  def test_freshness_on_compile_success
43
36
  status = OpenStruct.new(success?: true)
44
37
 
@@ -14,11 +14,6 @@ class ConfigurationTest < Webpacker::Test
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}"
20
- end
21
-
22
17
  def test_source_entry_path
23
18
  source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript", "packs").to_s
24
19
  assert_equal @config.source_entry_path.to_s, source_entry_path
@@ -53,21 +48,8 @@ class ConfigurationTest < Webpacker::Test
53
48
  assert_equal @config.cache_path.to_s, cache_path
54
49
  end
55
50
 
56
- def test_resolved_paths
57
- assert_equal @config.resolved_paths, ["app/assets", "/etc/yarn"]
58
- end
59
-
60
- def test_resolved_paths_globbed
61
- assert_equal @config.resolved_paths_globbed, [
62
- "app/assets/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg}",
63
- "/etc/yarn/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg}"
64
- ]
65
- end
66
-
67
- def test_extensions
68
- config_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/config/webpacker.yml").to_s
69
- webpacker_yml = YAML.load_file(config_path)
70
- assert_equal @config.extensions, webpacker_yml["default"]["extensions"]
51
+ def test_additional_paths
52
+ assert_equal @config.additional_paths, ["app/assets", "/etc/yarn", "some.config.js", "app/elm"]
71
53
  end
72
54
 
73
55
  def test_cache_manifest?
@@ -93,16 +75,4 @@ class ConfigurationTest < Webpacker::Test
93
75
  assert Webpacker.config.compile?
94
76
  end
95
77
  end
96
-
97
- def test_extract_css?
98
- assert @config.extract_css?
99
-
100
- with_rails_env("development") do
101
- refute Webpacker.config.extract_css?
102
- end
103
-
104
- with_rails_env("test") do
105
- refute Webpacker.config.extract_css?
106
- end
107
- end
108
78
  end
@@ -13,34 +13,53 @@ class DevServerRunnerTest < Webpacker::Test
13
13
  end
14
14
 
15
15
  def test_run_cmd_via_node_modules
16
- cmd = ["#{test_app_path}/node_modules/.bin/webpack-dev-server", "--config", "#{test_app_path}/config/webpack/development.js"]
16
+ cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js"]
17
17
 
18
18
  verify_command(cmd, use_node_modules: true)
19
19
  end
20
20
 
21
21
  def test_run_cmd_via_yarn
22
- cmd = ["yarn", "webpack-dev-server", "--config", "#{test_app_path}/config/webpack/development.js"]
22
+ cmd = ["yarn", "webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js"]
23
23
 
24
24
  verify_command(cmd, use_node_modules: false)
25
25
  end
26
26
 
27
+ def test_run_cmd_argv
28
+ cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js", "--quiet"]
29
+
30
+ verify_command(cmd, argv: ["--quiet"])
31
+ end
32
+
33
+ def test_run_cmd_argv_with_https
34
+ cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js", "--https"]
35
+
36
+ dev_server = Webpacker::DevServer.new({})
37
+ def dev_server.host; "localhost"; end
38
+ def dev_server.port; "3035"; end
39
+ def dev_server.pretty?; false; end
40
+ def dev_server.https?; true; end
41
+ Webpacker::DevServer.stub(:new, dev_server) do
42
+ verify_command(cmd, argv: ["--https"])
43
+ end
44
+ end
45
+
27
46
  private
28
47
  def test_app_path
29
48
  File.expand_path("test_app", __dir__)
30
49
  end
31
50
 
32
- def verify_command(cmd, use_node_modules: true)
51
+ def verify_command(cmd, use_node_modules: true, argv: [])
33
52
  cwd = Dir.pwd
34
53
  Dir.chdir(test_app_path)
35
54
 
36
55
  klass = Webpacker::DevServerRunner
37
- instance = klass.new([])
56
+ instance = klass.new(argv)
38
57
  mock = Minitest::Mock.new
39
- mock.expect(:call, nil, [{}, *cmd])
58
+ mock.expect(:call, nil, [Webpacker::Compiler.env, *cmd])
40
59
 
41
60
  klass.stub(:new, instance) do
42
61
  instance.stub(:node_modules_bin_exist?, use_node_modules) do
43
- Kernel.stub(:exec, mock) { klass.run([]) }
62
+ Kernel.stub(:exec, mock) { klass.run(argv) }
44
63
  end
45
64
  end
46
65
 
@@ -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
@@ -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/media/images/image-c38deda30895059837cf.jpg", image_pack_path("image.jpg")
30
+ assert_equal "/packs/media/images/image-c38deda30895059837cf.jpg", image_pack_path("media/images/image.jpg")
31
+ assert_equal "/packs/media/images/nested/image-c38deda30895059837cf.jpg", image_pack_path("nested/image.jpg")
32
+ assert_equal "/packs/media/images/nested/image-c38deda30895059837cf.jpg", image_pack_path("media/images/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/media/images/image-c38deda30895059837cf.jpg", image_pack_url("image.jpg")
38
+ assert_equal "https://example.com/packs/media/images/image-c38deda30895059837cf.jpg", image_pack_url("media/images/image.jpg")
39
+ assert_equal "https://example.com/packs/media/images/nested/image-c38deda30895059837cf.jpg", image_pack_url("nested/image.jpg")
40
+ assert_equal "https://example.com/packs/media/images/nested/image-c38deda30895059837cf.jpg", image_pack_url("media/images/nested/image.jpg")
35
41
  end
36
42
 
37
43
  def test_image_pack_tag
@@ -50,6 +56,9 @@ class HelperTest < ActionView::TestCase
50
56
  assert_equal \
51
57
  "<img alt=\"Edit Entry\" src=\"/packs/media/images/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
52
58
  image_pack_tag("media/images/nested/image.jpg", size: "16x10", alt: "Edit Entry")
59
+ assert_equal \
60
+ "<img srcset=\"/packs/media/images/image-2x-7cca48e6cae66ec07b8e.jpg 2x\" src=\"/packs/media/images/image-c38deda30895059837cf.jpg\" />",
61
+ image_pack_tag("media/images/image.jpg", srcset: { "media/images/image-2x.jpg" => "2x" })
53
62
  end
54
63
 
55
64
  def test_favicon_pack_tag
@@ -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,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,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/javascript
5
+ source_entry_path: packs
6
+ public_output_path: packs
7
+ cache_path: tmp/cache/webpacker
8
+
9
+ # Additional paths webpack should lookup 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