webpacker 5.2.1 → 6.0.0.pre.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 (154) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +1 -1
  3. data/.gitignore +2 -0
  4. data/.node-version +1 -1
  5. data/.rubocop.yml +11 -16
  6. data/CHANGELOG.md +15 -4
  7. data/CONTRIBUTING.md +1 -1
  8. data/Gemfile.lock +17 -11
  9. data/README.md +8 -4
  10. data/docs/assets.md +21 -5
  11. data/docs/css.md +24 -29
  12. data/docs/deployment.md +18 -0
  13. data/docs/docker.md +2 -2
  14. data/docs/engines.md +1 -1
  15. data/docs/env.md +5 -0
  16. data/docs/es6.md +1 -1
  17. data/docs/integrations.md +1 -1
  18. data/docs/props.md +2 -38
  19. data/docs/react.md +183 -0
  20. data/docs/testing.md +11 -0
  21. data/docs/typescript.md +2 -2
  22. data/docs/webpack-dev-server.md +17 -15
  23. data/docs/webpack.md +58 -107
  24. data/lib/install/config/webpack/base.js +3 -0
  25. data/lib/install/config/webpack/development.js +2 -2
  26. data/lib/install/config/webpack/production.js +2 -2
  27. data/lib/install/config/webpack/test.js +2 -2
  28. data/lib/install/config/webpacker.yml +8 -37
  29. data/lib/install/examples/{vue → vue3}/app.vue +10 -5
  30. data/lib/install/examples/vue3/hello_vue.js +15 -0
  31. data/lib/install/javascript/packs/application.css +9 -0
  32. data/lib/install/template.rb +33 -19
  33. data/lib/tasks/webpacker.rake +2 -11
  34. data/lib/tasks/webpacker/binstubs.rake +6 -4
  35. data/lib/tasks/webpacker/check_binstubs.rake +4 -4
  36. data/lib/tasks/webpacker/check_yarn.rake +1 -2
  37. data/lib/tasks/webpacker/compile.rake +4 -2
  38. data/lib/tasks/webpacker/info.rake +12 -10
  39. data/lib/tasks/webpacker/install.rake +6 -4
  40. data/lib/tasks/webpacker/verify_install.rake +2 -1
  41. data/lib/tasks/webpacker/yarn_install.rake +9 -1
  42. data/lib/webpacker/commands.rb +1 -1
  43. data/lib/webpacker/compiler.rb +7 -6
  44. data/lib/webpacker/configuration.rb +6 -30
  45. data/lib/webpacker/dev_server_runner.rb +21 -2
  46. data/lib/webpacker/helper.rb +22 -32
  47. data/lib/webpacker/manifest.rb +1 -1
  48. data/lib/webpacker/version.rb +1 -1
  49. data/lib/webpacker/webpack_runner.rb +5 -0
  50. data/package.json +23 -39
  51. data/package/__tests__/config.js +5 -37
  52. data/package/__tests__/development.js +9 -11
  53. data/package/__tests__/env.js +12 -4
  54. data/package/__tests__/production.js +6 -6
  55. data/package/__tests__/staging.js +7 -6
  56. data/package/__tests__/test.js +4 -5
  57. data/package/babel/preset-react.js +62 -0
  58. data/package/babel/preset.js +44 -0
  59. data/package/config.js +3 -11
  60. data/package/env.js +8 -2
  61. data/package/environments/__tests__/base.js +15 -47
  62. data/package/environments/base.js +66 -126
  63. data/package/environments/development.js +45 -44
  64. data/package/environments/production.js +69 -65
  65. data/package/environments/test.js +2 -2
  66. data/package/index.js +6 -6
  67. data/package/rules/babel.js +9 -7
  68. data/package/rules/coffee.js +6 -0
  69. data/package/rules/erb.js +13 -0
  70. data/package/rules/file.js +19 -19
  71. data/package/rules/index.js +24 -18
  72. data/package/rules/less.js +18 -0
  73. data/package/rules/sass.js +5 -6
  74. data/package/rules/svg.js +23 -0
  75. data/package/utils/get_style_rule.js +22 -28
  76. data/package/utils/helpers.js +3 -35
  77. data/test/compiler_test.rb +0 -12
  78. data/test/configuration_test.rb +1 -32
  79. data/test/dev_server_runner_test.rb +24 -5
  80. data/test/engine_rake_tasks_test.rb +39 -0
  81. data/test/helper_test.rb +15 -9
  82. data/test/mounted_app/Rakefile +4 -0
  83. data/test/mounted_app/test/dummy/Rakefile +3 -0
  84. data/test/mounted_app/test/dummy/bin/rails +3 -0
  85. data/test/mounted_app/test/dummy/bin/rake +3 -0
  86. data/test/mounted_app/test/dummy/config.ru +5 -0
  87. data/test/mounted_app/test/dummy/config/application.rb +10 -0
  88. data/test/mounted_app/test/dummy/config/environment.rb +3 -0
  89. data/test/mounted_app/test/dummy/config/webpacker.yml +75 -0
  90. data/test/mounted_app/test/dummy/package.json +7 -0
  91. data/test/rake_tasks_test.rb +1 -10
  92. data/test/test_app/config/webpacker.yml +1 -25
  93. data/test/test_app/config/webpacker_public_root.yml +0 -1
  94. data/test/test_app/public/packs/manifest.json +17 -13
  95. data/test/test_app/some.config.js +0 -0
  96. data/test/webpack_runner_test.rb +9 -3
  97. data/webpacker.gemspec +1 -1
  98. data/yarn.lock +1858 -4915
  99. metadata +47 -70
  100. data/.travis.yml +0 -43
  101. data/lib/install/angular.rb +0 -23
  102. data/lib/install/coffee.rb +0 -25
  103. data/lib/install/config/.browserslistrc +0 -1
  104. data/lib/install/config/babel.config.js +0 -70
  105. data/lib/install/config/postcss.config.js +0 -12
  106. data/lib/install/config/webpack/environment.js +0 -3
  107. data/lib/install/elm.rb +0 -39
  108. data/lib/install/erb.rb +0 -25
  109. data/lib/install/examples/angular/hello_angular.js +0 -7
  110. data/lib/install/examples/angular/hello_angular/app/app.component.ts +0 -9
  111. data/lib/install/examples/angular/hello_angular/app/app.module.ts +0 -16
  112. data/lib/install/examples/angular/hello_angular/index.ts +0 -8
  113. data/lib/install/examples/angular/hello_angular/polyfills.ts +0 -73
  114. data/lib/install/examples/coffee/hello_coffee.coffee +0 -4
  115. data/lib/install/examples/elm/Main.elm +0 -55
  116. data/lib/install/examples/elm/hello_elm.js +0 -16
  117. data/lib/install/examples/erb/hello_erb.js.erb +0 -6
  118. data/lib/install/examples/react/babel.config.js +0 -87
  119. data/lib/install/examples/react/hello_react.jsx +0 -26
  120. data/lib/install/examples/react/tsconfig.json +0 -21
  121. data/lib/install/examples/stimulus/application.js +0 -1
  122. data/lib/install/examples/stimulus/controllers/hello_controller.js +0 -18
  123. data/lib/install/examples/stimulus/controllers/index.js +0 -9
  124. data/lib/install/examples/svelte/app.svelte +0 -11
  125. data/lib/install/examples/svelte/hello_svelte.js +0 -20
  126. data/lib/install/examples/typescript/hello_typescript.ts +0 -4
  127. data/lib/install/examples/typescript/tsconfig.json +0 -24
  128. data/lib/install/examples/vue/hello_vue.js +0 -72
  129. data/lib/install/loaders/coffee.js +0 -6
  130. data/lib/install/loaders/elm.js +0 -25
  131. data/lib/install/loaders/erb.js +0 -11
  132. data/lib/install/loaders/svelte.js +0 -9
  133. data/lib/install/loaders/vue.js +0 -6
  134. data/lib/install/react.rb +0 -18
  135. data/lib/install/stimulus.rb +0 -12
  136. data/lib/install/svelte.rb +0 -29
  137. data/lib/install/typescript.rb +0 -39
  138. data/lib/install/vue.rb +0 -49
  139. data/lib/tasks/installers.rake +0 -42
  140. data/package/config_types/__tests__/config_list.js +0 -118
  141. data/package/config_types/__tests__/config_object.js +0 -43
  142. data/package/config_types/config_list.js +0 -75
  143. data/package/config_types/config_object.js +0 -55
  144. data/package/config_types/index.js +0 -7
  145. data/package/rules/module.css.js +0 -3
  146. data/package/rules/module.sass.js +0 -8
  147. data/package/rules/node_modules.js +0 -22
  148. data/package/utils/__tests__/deep_assign.js +0 -32
  149. data/package/utils/__tests__/deep_merge.js +0 -10
  150. data/package/utils/__tests__/get_style_rule.js +0 -65
  151. data/package/utils/__tests__/objectify.js +0 -9
  152. data/package/utils/deep_assign.js +0 -22
  153. data/package/utils/deep_merge.js +0 -22
  154. data/package/utils/objectify.js +0 -3
@@ -8,11 +8,13 @@ module Webpacker
8
8
  class DevServerRunner < Webpacker::Runner
9
9
  def run
10
10
  load_config
11
+ detect_unsupported_switches!
11
12
  detect_port!
12
13
  execute_cmd
13
14
  end
14
15
 
15
16
  private
17
+
16
18
  def load_config
17
19
  app_root = Pathname.new(@app_path)
18
20
 
@@ -27,6 +29,7 @@ module Webpacker
27
29
  @hostname = dev_server.host
28
30
  @port = dev_server.port
29
31
  @pretty = dev_server.pretty?
32
+ @https = dev_server.https?
30
33
 
31
34
  rescue Errno::ENOENT, NoMethodError
32
35
  $stdout.puts "webpack dev_server configuration not found in #{@config.config_path}[#{ENV["RAILS_ENV"]}]."
@@ -34,6 +37,21 @@ module Webpacker
34
37
  exit!
35
38
  end
36
39
 
40
+ UNSUPPORTED_SWITCHES = %w[--host --port]
41
+ private_constant :UNSUPPORTED_SWITCHES
42
+ def detect_unsupported_switches!
43
+ unsupported_switches = UNSUPPORTED_SWITCHES & @argv
44
+ if unsupported_switches.any?
45
+ $stdout.puts "The following CLI switches are not supported by Webpacker: #{unsupported_switches.join(' ')}. Please edit your command and try again."
46
+ exit!
47
+ end
48
+
49
+ if @argv.include?("--https") && !@https
50
+ $stdout.puts "Please set https: true in webpacker.yml to use the --https command line flag."
51
+ exit!
52
+ end
53
+ end
54
+
37
55
  def detect_port!
38
56
  server = TCPServer.new(@hostname, @port)
39
57
  server.close
@@ -48,9 +66,9 @@ module Webpacker
48
66
  env["WEBPACKER_CONFIG"] = @webpacker_config
49
67
 
50
68
  cmd = if node_modules_bin_exist?
51
- ["#{@node_modules_bin_path}/webpack-dev-server"]
69
+ ["#{@node_modules_bin_path}/webpack", "serve"]
52
70
  else
53
- ["yarn", "webpack-dev-server"]
71
+ ["yarn", "webpack", "serve"]
54
72
  end
55
73
 
56
74
  if @argv.include?("--debug-webpacker")
@@ -59,6 +77,7 @@ module Webpacker
59
77
 
60
78
  cmd += ["--config", @webpack_config]
61
79
  cmd += ["--progress", "--color"] if @pretty
80
+ cmd += @argv
62
81
 
63
82
  Dir.chdir(@app_path) do
64
83
  Kernel.exec env, *cmd
@@ -12,15 +12,9 @@ module Webpacker::Helper
12
12
  #
13
13
  # Example:
14
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
15
  # <%= asset_pack_path 'calendar.css' %> # => "/packs/calendar-1016838bab065ae1e122.css"
20
16
  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
17
+ path_to_asset(current_webpacker_instance.manifest.lookup!(name), options)
24
18
  end
25
19
 
26
20
  # Computes the absolute path for a given Webpacker asset.
@@ -29,15 +23,24 @@ module Webpacker::Helper
29
23
  #
30
24
  # Example:
31
25
  #
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
26
  # <%= asset_pack_url 'calendar.css' %> # => "http://example.com/packs/calendar-1016838bab065ae1e122.css"
37
27
  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
28
+ url_to_asset(current_webpacker_instance.manifest.lookup!(name), options)
29
+ end
30
+
31
+ # Computes the relative path for a given Webpacker image with the same automated processing as image_pack_tag.
32
+ # Returns the relative path using manifest.json and passes it to path_to_asset helper.
33
+ # This will use path_to_asset internally, so most of their behaviors will be the same.
34
+ def image_pack_path(name, **options)
35
+ resolve_path_to_image(name, **options)
36
+ end
37
+
38
+ # Computes the absolute path for a given Webpacker image with the same automated
39
+ # processing as image_pack_tag. Returns the relative path using manifest.json
40
+ # and passes it to path_to_asset helper. This will use path_to_asset internally,
41
+ # so most of their behaviors will be the same.
42
+ def image_pack_url(name, **options)
43
+ resolve_path_to_image(name, **options.merge(protocol: :request))
41
44
  end
42
45
 
43
46
  # Creates an image tag that references the named pack file.
@@ -133,17 +136,10 @@ module Webpacker::Helper
133
136
  #
134
137
  # Examples:
135
138
  #
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
139
  # <%= stylesheet_pack_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
142
140
  # <link rel="stylesheet" media="screen" href="/packs/calendar-1016838bab065ae1e122.css" data-turbolinks-track="reload" />
143
141
  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
142
+ stylesheet_link_tag(*sources_from_manifest_entries(names, type: :stylesheet), **options)
147
143
  end
148
144
 
149
145
  # Creates link tags that reference the css chunks from entrypoints when using split chunks API,
@@ -168,16 +164,10 @@ module Webpacker::Helper
168
164
  # <%= stylesheet_packs_with_chunks_tag 'calendar' %>
169
165
  # <%= stylesheet_packs_with_chunks_tag 'map' %>
170
166
  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
167
+ stylesheet_link_tag(*sources_from_manifest_entrypoints(names, type: :stylesheet), **options)
174
168
  end
175
169
 
176
170
  private
177
- def stylesheet?(name)
178
- File.extname(name) == ".css"
179
- end
180
-
181
171
  def sources_from_manifest_entries(names, type:)
182
172
  names.map { |name| current_webpacker_instance.manifest.lookup!(name, type: type) }.flatten
183
173
  end
@@ -186,10 +176,10 @@ module Webpacker::Helper
186
176
  names.map { |name| current_webpacker_instance.manifest.lookup_pack_with_chunks!(name, type: type) }.flatten.uniq
187
177
  end
188
178
 
189
- def resolve_path_to_image(name)
179
+ def resolve_path_to_image(name, **options)
190
180
  path = name.starts_with?("media/images/") ? name : "media/images/#{name}"
191
- path_to_asset(current_webpacker_instance.manifest.lookup!(path))
181
+ path_to_asset(current_webpacker_instance.manifest.lookup!(path), options)
192
182
  rescue
193
- path_to_asset(current_webpacker_instance.manifest.lookup!(name))
183
+ path_to_asset(current_webpacker_instance.manifest.lookup!(name), options)
194
184
  end
195
185
  end
@@ -23,7 +23,7 @@ class Webpacker::Manifest
23
23
 
24
24
  manifest_pack_type = manifest_type(pack_type[:type])
25
25
  manifest_pack_name = manifest_name(name, manifest_pack_type)
26
- find("entrypoints")[manifest_pack_name][manifest_pack_type]
26
+ find("entrypoints")[manifest_pack_name]["assets"][manifest_pack_type]
27
27
  rescue NoMethodError
28
28
  nil
29
29
  end
@@ -1,4 +1,4 @@
1
1
  module Webpacker
2
2
  # Change the version in package.json too, please!
3
- VERSION = "5.2.1".freeze
3
+ VERSION = "6.0.0.pre.1".freeze
4
4
  end
@@ -17,6 +17,11 @@ module Webpacker
17
17
  cmd = [ "node", "--inspect-brk"] + cmd
18
18
  end
19
19
 
20
+ if @argv.include?("--trace-deprecation")
21
+ cmd = [ "node", "--trace-deprecation"] + cmd
22
+ @argv.delete "--trace-deprecation"
23
+ end
24
+
20
25
  cmd += ["--config", @webpack_config] + @argv
21
26
 
22
27
  Dir.chdir(@app_path) do
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rails/webpacker",
3
- "version": "5.2.1",
3
+ "version": "6.0.0-pre.1",
4
4
  "description": "Use webpack to manage app-like JavaScript modules in Rails",
5
5
  "main": "package/index.js",
6
6
  "files": [
@@ -8,56 +8,40 @@
8
8
  "lib/install/config/webpacker.yml"
9
9
  ],
10
10
  "engines": {
11
- "node": ">=10.17.0",
12
- "yarn": ">=1 <2"
11
+ "node": ">=10.22.1 || ^12 || >=14",
12
+ "yarn": ">=1 <3"
13
13
  },
14
14
  "dependencies": {
15
- "@babel/core": "^7.11.1",
16
- "@babel/plugin-proposal-class-properties": "^7.10.4",
17
- "@babel/plugin-proposal-object-rest-spread": "^7.10.1",
18
- "@babel/plugin-syntax-dynamic-import": "^7.8.3",
19
- "@babel/plugin-transform-destructuring": "^7.10.1",
20
- "@babel/plugin-transform-regenerator": "^7.10.1",
21
- "@babel/plugin-transform-runtime": "^7.11.0",
22
- "@babel/preset-env": "^7.11.0",
23
- "@babel/runtime": "^7.11.2",
24
- "babel-loader": "^8.1.0",
25
- "babel-plugin-dynamic-import-node": "^2.3.3",
26
- "babel-plugin-macros": "^2.8.0",
15
+ "@babel/core": "^7.12.9",
16
+ "@babel/plugin-proposal-class-properties": "^7.12.1",
17
+ "@babel/plugin-transform-runtime": "^7.12.1",
18
+ "@babel/preset-env": "^7.12.11",
19
+ "@babel/runtime": "^7.12.5",
20
+ "babel-loader": "^8.2.2",
21
+ "babel-plugin-macros": "^3.0.1",
27
22
  "case-sensitive-paths-webpack-plugin": "^2.3.0",
28
- "compression-webpack-plugin": "^4.0.0",
29
- "core-js": "^3.6.5",
30
- "css-loader": "^3.5.3",
31
- "file-loader": "^6.0.0",
32
- "flatted": "^3.0.4",
23
+ "compression-webpack-plugin": "^7.1.0",
24
+ "core-js": "^3.8.0",
33
25
  "glob": "^7.1.6",
34
26
  "js-yaml": "^3.14.0",
35
- "mini-css-extract-plugin": "^0.9.0",
36
- "node-sass": "^4.14.1",
37
- "optimize-css-assets-webpack-plugin": "^5.0.3",
38
27
  "path-complete-extname": "^1.0.0",
39
28
  "pnp-webpack-plugin": "^1.6.4",
40
- "postcss-flexbugs-fixes": "^4.2.1",
41
- "postcss-import": "^12.0.1",
42
- "postcss-loader": "^3.0.0",
43
- "postcss-preset-env": "^6.7.0",
44
- "postcss-safe-parser": "^4.0.2",
45
29
  "regenerator-runtime": "^0.13.7",
46
- "sass-loader": "^8.0.2",
47
- "style-loader": "^1.2.1",
48
- "terser-webpack-plugin": "^4.0.0",
49
- "webpack": "^4.44.1",
50
- "webpack-assets-manifest": "^3.1.1",
51
- "webpack-cli": "^3.3.12",
52
- "webpack-sources": "^1.4.3"
30
+ "terser-webpack-plugin": "^5.0.3",
31
+ "webpack": "^5.11.0",
32
+ "webpack-assets-manifest": "^5.0.0",
33
+ "webpack-cli": "^4.2.0",
34
+ "webpack-merge": "^5.7.2",
35
+ "webpack-sources": "^2.2.0"
53
36
  },
54
37
  "devDependencies": {
55
- "eslint": "^7.6.0",
38
+ "eslint": "^7.16.0",
56
39
  "eslint-config-airbnb": "^18.2.0",
57
- "eslint-plugin-import": "^2.22.0",
40
+ "eslint-config-prettier": "^7.1.0",
41
+ "eslint-plugin-import": "^2.22.1",
58
42
  "eslint-plugin-jsx-a11y": "^6.3.1",
59
- "eslint-plugin-react": "^7.20.5",
60
- "jest": "^26.2.2"
43
+ "eslint-plugin-react": "^7.21.4",
44
+ "jest": "^26.5.3"
61
45
  },
62
46
  "jest": {
63
47
  "testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$",
@@ -24,43 +24,11 @@ describe('Config', () => {
24
24
  })
25
25
 
26
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',
27
+ expect(config.additional_paths).toEqual([
28
+ 'app/assets',
29
+ '/etc/yarn',
30
+ 'some.config.js',
31
+ 'app/elm'
64
32
  ])
65
33
  })
66
34
  })
@@ -8,19 +8,18 @@ chdirTestApp()
8
8
  describe('Development environment', () => {
9
9
  afterAll(chdirCwd)
10
10
 
11
- describe('toWebpackConfig', () => {
11
+ describe('webpackConfig', () => {
12
12
  beforeEach(() => jest.resetModules())
13
13
 
14
14
  test('should use development config and environment including devServer if WEBPACK_DEV_SERVER', () => {
15
15
  process.env.RAILS_ENV = 'development'
16
16
  process.env.NODE_ENV = 'development'
17
17
  process.env.WEBPACK_DEV_SERVER = 'YES'
18
- const { environment } = require('../index')
18
+ const { webpackConfig } = require('../index')
19
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({
20
+ expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
21
+ expect(webpackConfig.output.publicPath).toEqual('/packs/')
22
+ expect(webpackConfig).toMatchObject({
24
23
  devServer: {
25
24
  host: 'localhost',
26
25
  port: 3035
@@ -32,12 +31,11 @@ describe('Development environment', () => {
32
31
  process.env.RAILS_ENV = 'development'
33
32
  process.env.NODE_ENV = 'development'
34
33
  process.env.WEBPACK_DEV_SERVER = undefined
35
- const { environment } = require('../index')
34
+ const { webpackConfig } = require('../index')
36
35
 
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)
36
+ expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
37
+ expect(webpackConfig.output.publicPath).toEqual('/packs/')
38
+ expect(webpackConfig.devServer).toEqual(undefined)
41
39
  })
42
40
  })
43
41
  })
@@ -13,7 +13,9 @@ describe('Env', () => {
13
13
  process.env.NODE_ENV = 'development'
14
14
  expect(require('../env')).toEqual({
15
15
  railsEnv: 'development',
16
- nodeEnv: 'development'
16
+ nodeEnv: 'development',
17
+ isProduction: false,
18
+ isDevelopment: true
17
19
  })
18
20
  })
19
21
 
@@ -22,7 +24,9 @@ describe('Env', () => {
22
24
  delete process.env.NODE_ENV
23
25
  expect(require('../env')).toEqual({
24
26
  railsEnv: 'development',
25
- nodeEnv: 'production'
27
+ nodeEnv: 'production',
28
+ isProduction: true,
29
+ isDevelopment: false
26
30
  })
27
31
  })
28
32
 
@@ -31,7 +35,9 @@ describe('Env', () => {
31
35
  delete process.env.RAILS_ENV
32
36
  expect(require('../env')).toEqual({
33
37
  railsEnv: 'production',
34
- nodeEnv: 'production'
38
+ nodeEnv: 'production',
39
+ isProduction: true,
40
+ isDevelopment: false
35
41
  })
36
42
  })
37
43
 
@@ -40,7 +46,9 @@ describe('Env', () => {
40
46
  process.env.NODE_ENV = 'staging'
41
47
  expect(require('../env')).toEqual({
42
48
  railsEnv: 'staging',
43
- nodeEnv: 'production'
49
+ nodeEnv: 'production',
50
+ isProduction: true,
51
+ isDevelopment: false
44
52
  })
45
53
  })
46
54
  })
@@ -8,19 +8,19 @@ chdirTestApp()
8
8
  describe('Production environment', () => {
9
9
  afterAll(chdirCwd)
10
10
 
11
- describe('toWebpackConfig', () => {
11
+ describe('webpackConfig', () => {
12
12
  beforeEach(() => jest.resetModules())
13
13
 
14
14
  test('should use production config and environment', () => {
15
15
  process.env.RAILS_ENV = 'production'
16
16
  process.env.NODE_ENV = 'production'
17
17
 
18
- const { environment } = require('../index')
19
- const config = environment.toWebpackConfig()
18
+ const { webpackConfig } = require('../index')
20
19
 
21
- expect(config.output.path).toEqual(resolve('public', 'packs'))
22
- expect(config.output.publicPath).toEqual('/packs/')
23
- expect(config).toMatchObject({
20
+ expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
21
+ expect(webpackConfig.output.publicPath).toEqual('/packs/')
22
+
23
+ expect(webpackConfig).toMatchObject({
24
24
  devtool: 'source-map',
25
25
  stats: 'normal'
26
26
  })
@@ -8,19 +8,20 @@ chdirTestApp()
8
8
  describe('Custom environment', () => {
9
9
  afterAll(chdirCwd)
10
10
 
11
- describe('toWebpackConfig', () => {
11
+ describe('webpackConfig', () => {
12
12
  beforeEach(() => jest.resetModules())
13
13
 
14
14
  test('should use staging config and default production environment', () => {
15
15
  process.env.RAILS_ENV = 'staging'
16
16
  delete process.env.NODE_ENV
17
17
 
18
- const { environment } = require('../index')
19
- const config = environment.toWebpackConfig()
18
+ const { webpackConfig } = require('../index')
20
19
 
21
- expect(config.output.path).toEqual(resolve('public', 'packs-staging'))
22
- expect(config.output.publicPath).toEqual('/packs-staging/')
23
- expect(config).toMatchObject({
20
+ expect(webpackConfig.output.path).toEqual(
21
+ resolve('public', 'packs-staging')
22
+ )
23
+ expect(webpackConfig.output.publicPath).toEqual('/packs-staging/')
24
+ expect(webpackConfig).toMatchObject({
24
25
  devtool: 'source-map',
25
26
  stats: 'normal'
26
27
  })