webpacker 6.0.0.beta.7 → 6.0.0.rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/jest.yml +5 -2
  3. data/.github/workflows/js-lint.yml +4 -1
  4. data/.github/workflows/rubocop.yml +1 -1
  5. data/.github/workflows/ruby.yml +12 -12
  6. data/.node-version +1 -1
  7. data/.rubocop.yml +1 -0
  8. data/CHANGELOG.md +21 -10
  9. data/Gemfile.lock +2 -2
  10. data/README.md +159 -156
  11. data/config/webpacker.yml +1 -1
  12. data/docs/developing_webpacker.md +29 -0
  13. data/docs/troubleshooting.md +53 -23
  14. data/docs/v6_upgrade.md +31 -42
  15. data/gemfiles/Gemfile-rails-edge +1 -1
  16. data/gemfiles/Gemfile-rails.6.1.x +12 -0
  17. data/lib/install/bin/yarn +18 -0
  18. data/lib/install/config/webpacker.yml +2 -6
  19. data/lib/install/package.json +17 -0
  20. data/lib/install/packs/entrypoints/application.js +3 -4
  21. data/lib/install/template.rb +28 -15
  22. data/lib/tasks/webpacker/check_node.rake +3 -1
  23. data/lib/tasks/webpacker/check_yarn.rake +4 -2
  24. data/lib/tasks/webpacker/clobber.rake +1 -1
  25. data/lib/tasks/webpacker/verify_config.rake +14 -0
  26. data/lib/tasks/webpacker/verify_install.rake +1 -11
  27. data/lib/tasks/yarn.rake +36 -0
  28. data/lib/webpacker/configuration.rb +15 -4
  29. data/lib/webpacker/dev_server.rb +6 -0
  30. data/lib/webpacker/dev_server_runner.rb +5 -2
  31. data/lib/webpacker/env.rb +5 -1
  32. data/lib/webpacker/helper.rb +14 -8
  33. data/lib/webpacker/instance.rb +4 -0
  34. data/lib/webpacker/manifest.rb +1 -2
  35. data/lib/webpacker/railtie.rb +1 -2
  36. data/lib/webpacker/runner.rb +1 -1
  37. data/lib/webpacker/version.rb +1 -1
  38. data/lib/webpacker.rb +1 -1
  39. data/package/__tests__/development.js +2 -2
  40. data/package/__tests__/env.js +8 -4
  41. data/package/babel/preset.js +0 -1
  42. data/package/env.js +7 -1
  43. data/package/environments/__tests__/base.js +3 -3
  44. data/package/environments/base.js +12 -7
  45. data/package/environments/development.js +7 -9
  46. data/package/index.js +2 -0
  47. data/package/inliningCss.js +7 -0
  48. data/package/rules/file.js +1 -1
  49. data/package/rules/sass.js +1 -2
  50. data/package/utils/get_style_rule.js +4 -2
  51. data/package.json +25 -29
  52. data/test/configuration_test.rb +1 -1
  53. data/test/dev_server_runner_test.rb +4 -1
  54. data/test/helper_test.rb +48 -34
  55. data/test/manifest_test.rb +10 -2
  56. data/test/mounted_app/test/dummy/config/webpacker.yml +1 -1
  57. data/test/test_app/config/webpacker.yml +1 -3
  58. data/test/test_app/config/webpacker_other_location.yml +79 -0
  59. data/test/test_app/public/packs/manifest.json +12 -5
  60. data/test/webpacker_test.rb +17 -0
  61. data/yarn.lock +1567 -1039
  62. metadata +14 -5
@@ -1,8 +1,8 @@
1
1
  const { merge } = require('webpack-merge')
2
- const webpack = require('webpack')
3
2
 
4
3
  const baseConfig = require('./base')
5
4
  const devServer = require('../dev_server')
5
+ const { runningWebpackDevServer } = require('../env')
6
6
 
7
7
  const { outputPath: contentBase, publicPath } = require('../config')
8
8
 
@@ -11,14 +11,10 @@ let devConfig = {
11
11
  devtool: 'cheap-module-source-map'
12
12
  }
13
13
 
14
- if (
15
- process.env.WEBPACK_DEV_SERVER &&
16
- process.env.WEBPACK_DEV_SERVER !== 'undefined'
17
- ) {
14
+ if (runningWebpackDevServer) {
18
15
  if (devServer.hmr) {
19
16
  devConfig = merge(devConfig, {
20
- output: { filename: '[name]-[hash].js' },
21
- plugins: [new webpack.HotModuleReplacementPlugin()]
17
+ output: { filename: '[name]-[hash].js' }
22
18
  })
23
19
  }
24
20
 
@@ -33,8 +29,9 @@ if (
33
29
  https: devServer.https,
34
30
  hot: devServer.hmr,
35
31
  contentBase,
36
- inline: devServer.inline,
37
- injectClient: devServer.inject_client,
32
+ inline: devServer.inline || devServer.hmr,
33
+ injectClient: devServer.hmr,
34
+ injectHot: devServer.hmr,
38
35
  useLocalIp: devServer.use_local_ip,
39
36
  public: devServer.public,
40
37
  publicPath,
@@ -42,6 +39,7 @@ if (
42
39
  headers: devServer.headers,
43
40
  overlay: devServer.overlay,
44
41
  stats: {
42
+ colors: true,
45
43
  entrypoints: false,
46
44
  errorDetails: true,
47
45
  modules: false,
data/package/index.js CHANGED
@@ -10,6 +10,7 @@ const config = require('./config')
10
10
  const devServer = require('./dev_server')
11
11
  const { nodeEnv } = require('./env')
12
12
  const { moduleExists, canProcess } = require('./utils/helpers')
13
+ const inliningCss = require('./inliningCss')
13
14
 
14
15
  const webpackConfig = () => {
15
16
  const path = resolve(__dirname, 'environments', `${nodeEnv}.js`)
@@ -25,5 +26,6 @@ module.exports = {
25
26
  rules,
26
27
  moduleExists,
27
28
  canProcess,
29
+ inliningCss,
28
30
  ...webpackMerge
29
31
  }
@@ -0,0 +1,7 @@
1
+ const { runningWebpackDevServer } = require('./env')
2
+ const devServer = require('./dev_server')
3
+
4
+ // This logic is tied to lib/webpacker/instance.rb
5
+ const inliningCss = runningWebpackDevServer && devServer.hmr
6
+
7
+ module.exports = inliningCss
@@ -18,6 +18,6 @@ module.exports = {
18
18
  exclude: [/\.(js|mjs|jsx|ts|tsx)$/],
19
19
  type: 'asset/resource',
20
20
  generator: {
21
- filename: 'media/images/[hash][ext][query]'
21
+ filename: 'static/[hash][ext][query]'
22
22
  }
23
23
  }
@@ -9,8 +9,7 @@ module.exports = canProcess('sass-loader', (resolvedPath) =>
9
9
  {
10
10
  loader: resolvedPath,
11
11
  options: {
12
- sassOptions: { includePaths },
13
- implementation: require('sass')
12
+ sassOptions: { includePaths }
14
13
  }
15
14
  }
16
15
  ])
@@ -1,6 +1,6 @@
1
1
  /* eslint global-require: 0 */
2
-
3
2
  const { canProcess, moduleExists } = require('./helpers')
3
+ const inliningCss = require('../inliningCss')
4
4
 
5
5
  const getStyleRule = (test, preprocessors = []) => {
6
6
  if (moduleExists('css-loader')) {
@@ -10,8 +10,10 @@ const getStyleRule = (test, preprocessors = []) => {
10
10
  options: { sourceMap: true }
11
11
  }))
12
12
 
13
+ // style-loader is required when using css modules with HMR on the webpack-dev-server
14
+
13
15
  const use = [
14
- { loader: require('mini-css-extract-plugin').loader },
16
+ inliningCss ? 'style-loader' : require('mini-css-extract-plugin').loader,
15
17
  {
16
18
  loader: require.resolve('css-loader'),
17
19
  options: {
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rails/webpacker",
3
- "version": "6.0.0-beta.7",
3
+ "version": "6.0.0-rc.2",
4
4
  "description": "Use webpack to manage app-like JavaScript modules in Rails",
5
5
  "main": "package/index.js",
6
6
  "files": [
@@ -8,40 +8,36 @@
8
8
  "lib/install/config/webpacker.yml"
9
9
  ],
10
10
  "engines": {
11
- "node": ">=10.22.1 || ^12 || >=14",
12
- "yarn": ">=1 <3"
11
+ "node": "^12 || >=14",
12
+ "yarn": ">=1 <4"
13
13
  },
14
14
  "dependencies": {
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",
15
+ "@babel/core": "^7.15.0",
16
+ "@babel/plugin-proposal-class-properties": "^7.14.5",
17
+ "@babel/plugin-transform-runtime": "^7.15.0",
18
+ "@babel/preset-env": "^7.15.0",
19
+ "@babel/runtime": "^7.15.3",
20
20
  "babel-loader": "^8.2.2",
21
- "babel-plugin-macros": "^3.0.1",
22
- "case-sensitive-paths-webpack-plugin": "^2.3.0",
23
- "compression-webpack-plugin": "^7.1.0",
24
- "core-js": "^3.8.0",
25
- "glob": "^7.1.6",
26
- "js-yaml": "^3.14.0",
21
+ "compression-webpack-plugin": "^7.1.2",
22
+ "glob": "^7.1.7",
23
+ "js-yaml": "^3.14.1",
27
24
  "path-complete-extname": "^1.0.0",
28
- "pnp-webpack-plugin": "^1.6.4",
29
- "regenerator-runtime": "^0.13.7",
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"
25
+ "pnp-webpack-plugin": "^1.7.0",
26
+ "terser-webpack-plugin": "^5.1.4",
27
+ "webpack": "^5.50.0",
28
+ "webpack-assets-manifest": "^5.0.6",
29
+ "webpack-cli": "^4.8.0",
30
+ "webpack-merge": "^5.8.0",
31
+ "webpack-sources": "^3.2.0"
36
32
  },
37
33
  "devDependencies": {
38
- "eslint": "^7.16.0",
39
- "eslint-config-airbnb": "^18.2.0",
40
- "eslint-config-prettier": "^7.1.0",
41
- "eslint-plugin-import": "^2.22.1",
42
- "eslint-plugin-jsx-a11y": "^6.3.1",
43
- "eslint-plugin-react": "^7.21.4",
44
- "jest": "^26.5.3"
34
+ "eslint": "^7.32.0",
35
+ "eslint-config-airbnb": "^18.2.1",
36
+ "eslint-config-prettier": "^7.2.0",
37
+ "eslint-plugin-import": "^2.24.0",
38
+ "eslint-plugin-jsx-a11y": "^6.4.1",
39
+ "eslint-plugin-react": "^7.24.0",
40
+ "jest": "^26.6.3"
45
41
  },
46
42
  "jest": {
47
43
  "testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$",
@@ -44,7 +44,7 @@ class ConfigurationTest < Webpacker::Test
44
44
  end
45
45
 
46
46
  def test_cache_path
47
- cache_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/tmp/cache/webpacker").to_s
47
+ cache_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/tmp/webpacker").to_s
48
48
  assert_equal @config.cache_path.to_s, cache_path
49
49
  end
50
50
 
@@ -5,11 +5,13 @@ class DevServerRunnerTest < Webpacker::Test
5
5
  def setup
6
6
  @original_node_env, ENV["NODE_ENV"] = ENV["NODE_ENV"], "development"
7
7
  @original_rails_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "development"
8
+ @original_webpacker_config = ENV["WEBPACKER_CONFIG"]
8
9
  end
9
10
 
10
11
  def teardown
11
12
  ENV["NODE_ENV"] = @original_node_env
12
13
  ENV["RAILS_ENV"] = @original_rails_env
14
+ ENV["WEBPACKER_CONFIG"] = @original_webpacker_config
13
15
  end
14
16
 
15
17
  def test_run_cmd_via_node_modules
@@ -38,6 +40,7 @@ class DevServerRunnerTest < Webpacker::Test
38
40
  def dev_server.port; "3035"; end
39
41
  def dev_server.pretty?; false; end
40
42
  def dev_server.https?; true; end
43
+ def dev_server.hmr?; false; end
41
44
  Webpacker::DevServer.stub(:new, dev_server) do
42
45
  verify_command(cmd, argv: ["--https"])
43
46
  end
@@ -46,7 +49,7 @@ class DevServerRunnerTest < Webpacker::Test
46
49
  def test_environment_variables
47
50
  cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js"]
48
51
  env = Webpacker::Compiler.env.dup
49
- env["WEBPACKER_CONFIG"] = "#{test_app_path}/config/webpacker.yml"
52
+ ENV["WEBPACKER_CONFIG"] = env["WEBPACKER_CONFIG"] = "#{test_app_path}/config/webpacker_other_location.yml"
50
53
  env["WEBPACK_DEV_SERVER"] = "true"
51
54
  verify_command(cmd, env: env)
52
55
  end
data/test/helper_test.rb CHANGED
@@ -26,18 +26,18 @@ class HelperTest < ActionView::TestCase
26
26
 
27
27
  def test_image_pack_path
28
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")
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
33
  end
34
34
 
35
35
  def test_image_pack_url
36
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")
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")
41
41
  end
42
42
 
43
43
  def test_image_pack_tag
@@ -45,20 +45,20 @@ class HelperTest < ActionView::TestCase
45
45
  "<img alt=\"Edit Entry\" src=\"/packs/application-k344a6d59eef8632c9d1.png\" width=\"16\" height=\"10\" />",
46
46
  image_pack_tag("application.png", size: "16x10", alt: "Edit Entry")
47
47
  assert_equal \
48
- "<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\" />",
49
49
  image_pack_tag("image.jpg", size: "16x10", alt: "Edit Entry")
50
50
  assert_equal \
51
- "<img alt=\"Edit Entry\" src=\"/packs/media/images/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
52
- 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")
53
53
  assert_equal \
54
- "<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\" />",
55
55
  image_pack_tag("nested/image.jpg", size: "16x10", alt: "Edit Entry")
56
56
  assert_equal \
57
- "<img alt=\"Edit Entry\" src=\"/packs/media/images/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
58
- 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
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" })
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" })
62
62
  end
63
63
 
64
64
  def test_favicon_pack_tag
@@ -66,17 +66,17 @@ class HelperTest < ActionView::TestCase
66
66
  "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/application-k344a6d59eef8632c9d1.png\" />",
67
67
  favicon_pack_tag("application.png", rel: "apple-touch-icon", type: "image/png")
68
68
  assert_equal \
69
- "<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\" />",
70
70
  favicon_pack_tag("mb-icon.png", rel: "apple-touch-icon", type: "image/png")
71
71
  assert_equal \
72
- "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/media/images/mb-icon-c38deda30895059837cf.png\" />",
73
- 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")
74
74
  assert_equal \
75
- "<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\" />",
76
76
  favicon_pack_tag("nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
77
77
  assert_equal \
78
- "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/media/images/nested/mb-icon-c38deda30895059837cf.png\" />",
79
- favicon_pack_tag("media/images/nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
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")
80
80
  end
81
81
 
82
82
  def test_preload_pack_asset
@@ -96,12 +96,21 @@ class HelperTest < ActionView::TestCase
96
96
  end
97
97
 
98
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
99
108
  assert_equal \
100
109
  %(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>\n) +
101
110
  %(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>\n) +
102
111
  %(<script src="/packs/application-k344a6d59eef8632c9d1.js"></script>\n) +
103
112
  %(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
104
- javascript_pack_tag("application", "bootstrap")
113
+ javascript_pack_tag("application", "bootstrap", defer: false)
105
114
  end
106
115
 
107
116
  def test_javascript_pack_tag_splat
@@ -114,32 +123,37 @@ class HelperTest < ActionView::TestCase
114
123
 
115
124
  def test_javascript_pack_tag_symbol
116
125
  assert_equal \
117
- %(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>\n) +
118
- %(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>\n) +
119
- %(<script src="/packs/application-k344a6d59eef8632c9d1.js"></script>),
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>),
120
129
  javascript_pack_tag(:application)
121
130
  end
122
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]
138
+ end
139
+
123
140
  def test_stylesheet_pack_tag
124
141
  assert_equal \
125
- %(<link rel="stylesheet" media="screen" href="/packs/1-c20632e7baf2c81200d3.chunk.css" />\n) +
126
- %(<link rel="stylesheet" media="screen" href="/packs/application-k344a6d59eef8632c9d1.chunk.css" />\n) +
127
- %(<link rel="stylesheet" media="screen" href="/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css" />),
142
+ (application_stylesheet_chunks + hello_stimulus_stylesheet_chunks)
143
+ .map { |chunk| stylesheet_link_tag(chunk) }.join("\n"),
128
144
  stylesheet_pack_tag("application", "hello_stimulus")
129
145
  end
130
146
 
131
147
  def test_stylesheet_pack_tag_symbol
132
148
  assert_equal \
133
- %(<link rel="stylesheet" media="screen" href="/packs/1-c20632e7baf2c81200d3.chunk.css" />\n) +
134
- %(<link rel="stylesheet" media="screen" href="/packs/application-k344a6d59eef8632c9d1.chunk.css" />\n) +
135
- %(<link rel="stylesheet" media="screen" href="/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css" />),
149
+ (application_stylesheet_chunks + hello_stimulus_stylesheet_chunks)
150
+ .map { |chunk| stylesheet_link_tag(chunk) }.join("\n"),
136
151
  stylesheet_pack_tag(:application, :hello_stimulus)
137
152
  end
138
153
 
139
154
  def test_stylesheet_pack_tag_splat
140
155
  assert_equal \
141
- %(<link rel="stylesheet" media="all" href="/packs/1-c20632e7baf2c81200d3.chunk.css" />\n) +
142
- %(<link rel="stylesheet" media="all" href="/packs/application-k344a6d59eef8632c9d1.chunk.css" />),
156
+ (application_stylesheet_chunks).map { |chunk| stylesheet_link_tag(chunk, media: "all") }.join("\n"),
143
157
  stylesheet_pack_tag("application", media: "all")
144
158
  end
145
159
  end
@@ -26,11 +26,19 @@ class ManifestTest < Minitest::Test
26
26
  end
27
27
 
28
28
  def test_lookup_with_chunks_without_extension_success!
29
- assert_equal Webpacker.manifest.lookup_pack_with_chunks!("bootstrap", type: :javascript), ["/packs/bootstrap-300631c4f0e0f9c865bc.js"]
29
+ assert_equal ["/packs/bootstrap-300631c4f0e0f9c865bc.js"], Webpacker.manifest.lookup_pack_with_chunks!("bootstrap", type: :javascript)
30
30
  end
31
31
 
32
32
  def test_lookup_with_chunks_with_extension_success!
33
- assert_equal Webpacker.manifest.lookup_pack_with_chunks!("bootstrap.js", type: :javascript), ["/packs/bootstrap-300631c4f0e0f9c865bc.js"]
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)
34
42
  end
35
43
 
36
44
  def test_lookup_nil
@@ -4,7 +4,7 @@ default: &default
4
4
  source_path: app/packs
5
5
  source_entry_path: entrypoints
6
6
  public_output_path: packs
7
- cache_path: tmp/cache/webpacker
7
+ cache_path: tmp/webpacker
8
8
 
9
9
  # Additional paths webpack should look up modules
10
10
  # ['app/assets', 'engine/foo/app/assets']
@@ -5,7 +5,7 @@ default: &default
5
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
11
  # Additional paths webpack should look up modules
@@ -43,8 +43,6 @@ development:
43
43
  port: 3035
44
44
  public: localhost:3035
45
45
  hmr: false
46
- # Inline should be set to true if using HMR
47
- inline: true
48
46
  overlay: true
49
47
  disable_host_check: true
50
48
  use_local_ip: false
@@ -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