webpacker 6.0.0.beta.7 → 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 (84) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/jest.yml +1 -1
  3. data/.github/workflows/js-lint.yml +1 -1
  4. data/.github/workflows/ruby.yml +6 -9
  5. data/.rubocop.yml +0 -105
  6. data/CHANGELOG.md +6 -22
  7. data/CONTRIBUTING.md +1 -1
  8. data/Gemfile.lock +90 -93
  9. data/README.md +110 -308
  10. data/docs/assets.md +135 -0
  11. data/docs/cloud9.md +310 -0
  12. data/docs/css.md +303 -0
  13. data/docs/deployment.md +29 -9
  14. data/docs/docker.md +68 -0
  15. data/docs/engines.md +213 -0
  16. data/docs/env.md +68 -0
  17. data/docs/es6.md +72 -0
  18. data/docs/folder-structure.md +66 -0
  19. data/docs/integrations.md +220 -0
  20. data/docs/misc.md +23 -0
  21. data/docs/props.md +187 -0
  22. data/docs/react.md +183 -0
  23. data/docs/target.md +22 -0
  24. data/docs/testing.md +147 -0
  25. data/docs/troubleshooting.md +3 -5
  26. data/docs/typescript.md +190 -0
  27. data/docs/v4-upgrade.md +142 -0
  28. data/docs/webpack-dev-server.md +94 -0
  29. data/docs/webpack.md +315 -0
  30. data/docs/yarn.md +23 -0
  31. data/lib/install/config/webpacker.yml +3 -5
  32. data/lib/install/examples/vue3/app.vue +27 -0
  33. data/lib/install/examples/vue3/hello_vue.js +15 -0
  34. data/lib/install/javascript/packs/application.css +9 -0
  35. data/lib/install/{packs/entrypoints → javascript/packs}/application.js +2 -4
  36. data/lib/install/template.rb +9 -16
  37. data/lib/tasks/webpacker/binstubs.rake +2 -2
  38. data/lib/tasks/webpacker/check_node.rake +0 -1
  39. data/lib/tasks/webpacker/check_yarn.rake +0 -1
  40. data/lib/tasks/webpacker/install.rake +2 -2
  41. data/lib/webpacker/commands.rb +1 -2
  42. data/lib/webpacker/compiler.rb +3 -9
  43. data/lib/webpacker/configuration.rb +4 -4
  44. data/lib/webpacker/dev_server_runner.rb +0 -2
  45. data/lib/webpacker/helper.rb +43 -13
  46. data/lib/webpacker/manifest.rb +1 -1
  47. data/lib/webpacker/version.rb +1 -1
  48. data/lib/webpacker/webpack_runner.rb +0 -1
  49. data/package.json +1 -1
  50. data/package/__tests__/development.js +1 -2
  51. data/package/babel/preset-react.js +62 -0
  52. data/package/babel/preset.js +13 -24
  53. data/package/environments/__tests__/base.js +5 -5
  54. data/package/environments/base.js +20 -15
  55. data/package/environments/development.js +0 -1
  56. data/package/environments/production.js +30 -28
  57. data/package/index.js +2 -7
  58. data/package/rules/babel.js +1 -1
  59. data/package/rules/coffee.js +5 -5
  60. data/package/rules/erb.js +3 -5
  61. data/package/rules/file.js +3 -5
  62. data/package/rules/index.js +17 -9
  63. data/package/rules/less.js +10 -14
  64. data/package/rules/sass.js +9 -13
  65. data/package/rules/svg.js +23 -0
  66. data/package/utils/get_style_rule.js +31 -27
  67. data/package/utils/helpers.js +0 -25
  68. data/test/configuration_test.rb +2 -2
  69. data/test/dev_server_runner_test.rb +2 -10
  70. data/test/helper_test.rb +39 -33
  71. data/test/manifest_test.rb +0 -8
  72. data/test/mounted_app/test/dummy/config/webpacker.yml +3 -3
  73. data/test/test_app/app/{packs/entrypoints → javascript/packs}/application.js +1 -1
  74. data/test/test_app/app/{packs/entrypoints → javascript/packs}/multi_entry.css +0 -0
  75. data/test/test_app/app/{packs/entrypoints → javascript/packs}/multi_entry.js +0 -0
  76. data/test/test_app/config/webpacker.yml +3 -3
  77. data/test/test_app/public/packs/manifest.json +0 -7
  78. metadata +36 -18
  79. data/config/README.md +0 -3
  80. data/config/webpacker.yml +0 -1
  81. data/docs/v6_upgrade.md +0 -86
  82. data/package/__tests__/index.js +0 -9
  83. data/package/rules/raw.js +0 -5
  84. data/package/rules/stylus.js +0 -26
@@ -1,16 +1,24 @@
1
1
  /* eslint global-require: 0 */
2
2
  /* eslint import/no-dynamic-require: 0 */
3
3
 
4
+ const load = (name) => {
5
+ try {
6
+ return require(`./${name}`)
7
+ } catch (e) {
8
+ return null
9
+ }
10
+ }
11
+
4
12
  const rules = {
5
- raw: require('./raw'),
6
- file: require('./file'),
7
- css: require('./css'),
8
- sass: require('./sass'),
9
- babel: require('./babel'),
10
- erb: require('./erb'),
11
- coffee: require('./coffee'),
12
- less: require('./less'),
13
- stylus: require('./stylus')
13
+ file: load('file'),
14
+ svg: load('svg'),
15
+ css: load('css'),
16
+ sass: load('sass'),
17
+ babel: load('babel'),
18
+ erb: load('erb'),
19
+ coffee: load('coffee'),
20
+ html: load('html'),
21
+ less: load('less')
14
22
  }
15
23
 
16
24
  module.exports = Object.keys(rules)
@@ -1,22 +1,18 @@
1
1
  const path = require('path')
2
- const { canProcess } = require('../utils/helpers')
3
2
  const getStyleRule = require('../utils/get_style_rule')
4
-
5
3
  const {
6
4
  additional_paths: paths,
7
5
  source_path: sourcePath
8
6
  } = require('../config')
9
7
 
10
- module.exports = canProcess('less-loader', (resolvedPath) =>
11
- getStyleRule(/\.(less)(\.erb)?$/i, [
12
- {
13
- loader: resolvedPath,
14
- options: {
15
- lessOptions: {
16
- paths: [path.resolve(__dirname, 'node_modules'), sourcePath, ...paths]
17
- },
18
- sourceMap: true
19
- }
8
+ module.exports = getStyleRule(/\.(less)(\.erb)?$/i, [
9
+ {
10
+ loader: require.resolve('less-loader'),
11
+ options: {
12
+ lessOptions: {
13
+ paths: [path.resolve(__dirname, 'node_modules'), sourcePath, ...paths]
14
+ },
15
+ sourceMap: true
20
16
  }
21
- ])
22
- )
17
+ }
18
+ ])
@@ -1,17 +1,13 @@
1
- /* eslint global-require: 0 */
2
-
1
+ const sass = require('sass')
3
2
  const getStyleRule = require('../utils/get_style_rule')
4
- const { canProcess } = require('../utils/helpers')
5
3
  const { additional_paths: includePaths } = require('../config')
6
4
 
7
- module.exports = canProcess('sass-loader', (resolvedPath) =>
8
- getStyleRule(/\.(scss|sass)(\.erb)?$/i, [
9
- {
10
- loader: resolvedPath,
11
- options: {
12
- sassOptions: { includePaths },
13
- implementation: require('sass')
14
- }
5
+ module.exports = getStyleRule(/\.(scss|sass)(\.erb)?$/i, [
6
+ {
7
+ loader: require.resolve('sass-loader'),
8
+ options: {
9
+ sassOptions: { includePaths },
10
+ implementation: sass
15
11
  }
16
- ])
17
- )
12
+ }
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,35 +1,39 @@
1
- /* eslint global-require: 0 */
1
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin')
2
2
 
3
- const { canProcess, moduleExists } = require('./helpers')
4
-
5
- const getStyleRule = (test, preprocessors = []) => {
6
- if (moduleExists('css-loader')) {
7
- const tryPostcss = () =>
8
- canProcess('postcss-loader', (loaderPath) => ({
9
- loader: loaderPath,
3
+ const tryPostcss = () => {
4
+ let postcssLoader = false
5
+ try {
6
+ if (require.resolve('postcss-loader')) {
7
+ postcssLoader = {
8
+ loader: require.resolve('postcss-loader'),
10
9
  options: { sourceMap: true }
11
- }))
12
-
13
- const use = [
14
- { loader: require('mini-css-extract-plugin').loader },
15
- {
16
- loader: require.resolve('css-loader'),
17
- options: {
18
- sourceMap: true,
19
- importLoaders: 2
20
- }
21
- },
22
- tryPostcss(),
23
- ...preprocessors
24
- ].filter(Boolean)
25
-
26
- return {
27
- test,
28
- use
10
+ }
29
11
  }
12
+ } catch (e) {
13
+ /* Work out what to print here */
30
14
  }
31
15
 
32
- return null
16
+ return postcssLoader
17
+ }
18
+
19
+ const getStyleRule = (test, preprocessors = []) => {
20
+ const use = [
21
+ { loader: MiniCssExtractPlugin.loader },
22
+ {
23
+ loader: require.resolve('css-loader'),
24
+ options: {
25
+ sourceMap: true,
26
+ importLoaders: 2
27
+ }
28
+ },
29
+ tryPostcss(),
30
+ ...preprocessors
31
+ ].filter(Boolean)
32
+
33
+ return {
34
+ test,
35
+ use
36
+ }
33
37
  }
34
38
 
35
39
  module.exports = getStyleRule
@@ -16,36 +16,11 @@ const resetEnv = () => {
16
16
 
17
17
  const ensureTrailingSlash = (path) => (path.endsWith('/') ? path : `${path}/`)
18
18
 
19
- const resolvedPath = (packageName) => {
20
- try {
21
- return require.resolve(packageName)
22
- } catch (e) {
23
- if (e.code !== 'MODULE_NOT_FOUND') {
24
- throw e
25
- }
26
- return null
27
- }
28
- }
29
-
30
- const moduleExists = (packageName) => (!!resolvedPath(packageName))
31
-
32
- const canProcess = (rule, fn) => {
33
- const modulePath = resolvedPath(rule)
34
-
35
- if (modulePath) {
36
- return fn(modulePath)
37
- }
38
-
39
- return null
40
- }
41
-
42
19
  module.exports = {
43
20
  chdirTestApp,
44
21
  chdirCwd,
45
22
  isArray,
46
23
  isBoolean,
47
24
  ensureTrailingSlash,
48
- canProcess,
49
- moduleExists,
50
25
  resetEnv
51
26
  }
@@ -10,12 +10,12 @@ class ConfigurationTest < Webpacker::Test
10
10
  end
11
11
 
12
12
  def test_source_path
13
- source_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/packs").to_s
13
+ source_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript").to_s
14
14
  assert_equal source_path, @config.source_path.to_s
15
15
  end
16
16
 
17
17
  def test_source_entry_path
18
- source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/packs", "entrypoints").to_s
18
+ source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript", "packs").to_s
19
19
  assert_equal @config.source_entry_path.to_s, source_entry_path
20
20
  end
21
21
 
@@ -43,27 +43,19 @@ class DevServerRunnerTest < Webpacker::Test
43
43
  end
44
44
  end
45
45
 
46
- def test_environment_variables
47
- cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js"]
48
- env = Webpacker::Compiler.env.dup
49
- env["WEBPACKER_CONFIG"] = "#{test_app_path}/config/webpacker.yml"
50
- env["WEBPACK_DEV_SERVER"] = "true"
51
- verify_command(cmd, env: env)
52
- end
53
-
54
46
  private
55
47
  def test_app_path
56
48
  File.expand_path("test_app", __dir__)
57
49
  end
58
50
 
59
- def verify_command(cmd, use_node_modules: true, argv: [], env: Webpacker::Compiler.env)
51
+ def verify_command(cmd, use_node_modules: true, argv: [])
60
52
  cwd = Dir.pwd
61
53
  Dir.chdir(test_app_path)
62
54
 
63
55
  klass = Webpacker::DevServerRunner
64
56
  instance = klass.new(argv)
65
57
  mock = Minitest::Mock.new
66
- mock.expect(:call, nil, [env, *cmd])
58
+ mock.expect(:call, nil, [Webpacker::Compiler.env, *cmd])
67
59
 
68
60
  klass.stub(:new, instance) do
69
61
  instance.stub(:node_modules_bin_exist?, use_node_modules) do
data/test/helper_test.rb CHANGED
@@ -79,6 +79,33 @@ class HelperTest < ActionView::TestCase
79
79
  favicon_pack_tag("media/images/nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
80
80
  end
81
81
 
82
+ def test_javascript_pack_tag
83
+ assert_equal \
84
+ %(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
85
+ javascript_pack_tag("bootstrap.js")
86
+ end
87
+
88
+ def test_javascript_pack_tag_symbol
89
+ assert_equal \
90
+ %(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
91
+ javascript_pack_tag(:bootstrap)
92
+ end
93
+
94
+ def test_javascript_pack_tag_splat
95
+ assert_equal \
96
+ %(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js" defer="defer"></script>\n) +
97
+ %(<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>),
98
+ javascript_pack_tag("bootstrap.js", "application.js", defer: true)
99
+ end
100
+
101
+ def test_javascript_pack_tag_split_chunks
102
+ assert_equal \
103
+ %(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>\n) +
104
+ %(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>\n) +
105
+ %(<script src="/packs/application-k344a6d59eef8632c9d1.js"></script>),
106
+ javascript_packs_with_chunks_tag("application")
107
+ end
108
+
82
109
  def test_preload_pack_asset
83
110
  if self.class.method_defined?(:preload_link_tag)
84
111
  assert_equal \
@@ -95,51 +122,30 @@ class HelperTest < ActionView::TestCase
95
122
  end
96
123
  end
97
124
 
98
- def test_javascript_pack_tag
125
+ def test_stylesheet_pack_tag_split_chunks
99
126
  assert_equal \
100
- %(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>\n) +
101
- %(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>\n) +
102
- %(<script src="/packs/application-k344a6d59eef8632c9d1.js"></script>\n) +
103
- %(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
104
- javascript_pack_tag("application", "bootstrap")
105
- end
106
-
107
- def test_javascript_pack_tag_splat
108
- assert_equal \
109
- %(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>\n) +
110
- %(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>\n) +
111
- %(<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>),
112
- javascript_pack_tag("application", defer: true)
113
- end
114
-
115
- def test_javascript_pack_tag_symbol
116
- 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>),
120
- javascript_pack_tag(:application)
127
+ %(<link rel="stylesheet" media="screen" href="/packs/1-c20632e7baf2c81200d3.chunk.css" />\n) +
128
+ %(<link rel="stylesheet" media="screen" href="/packs/application-k344a6d59eef8632c9d1.chunk.css" />\n) +
129
+ %(<link rel="stylesheet" media="screen" href="/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css" />),
130
+ stylesheet_packs_with_chunks_tag("application", "hello_stimulus")
121
131
  end
122
132
 
123
133
  def test_stylesheet_pack_tag
124
134
  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" />),
128
- stylesheet_pack_tag("application", "hello_stimulus")
135
+ %(<link rel="stylesheet" media="screen" href="/packs/bootstrap-c38deda30895059837cf.css" />),
136
+ stylesheet_pack_tag("bootstrap.css")
129
137
  end
130
138
 
131
139
  def test_stylesheet_pack_tag_symbol
132
140
  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" />),
136
- stylesheet_pack_tag(:application, :hello_stimulus)
141
+ %(<link rel="stylesheet" media="screen" href="/packs/bootstrap-c38deda30895059837cf.css" />),
142
+ stylesheet_pack_tag(:bootstrap)
137
143
  end
138
144
 
139
145
  def test_stylesheet_pack_tag_splat
140
146
  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" />),
143
- stylesheet_pack_tag("application", media: "all")
147
+ %(<link rel="stylesheet" media="all" href="/packs/bootstrap-c38deda30895059837cf.css" />\n) +
148
+ %(<link rel="stylesheet" media="all" href="/packs/application-dd6b1cd38bfa093df600.css" />),
149
+ stylesheet_pack_tag("bootstrap.css", "application.css", media: "all")
144
150
  end
145
151
  end
@@ -25,14 +25,6 @@ class ManifestTest < Minitest::Test
25
25
  assert_equal Webpacker.manifest.lookup!("bootstrap.js"), "/packs/bootstrap-300631c4f0e0f9c865bc.js"
26
26
  end
27
27
 
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"]
30
- end
31
-
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"]
34
- end
35
-
36
28
  def test_lookup_nil
37
29
  assert_nil Webpacker.manifest.lookup("foo.js")
38
30
  end
@@ -1,12 +1,12 @@
1
1
  # Note: You must restart bin/webpack-dev-server for changes to take effect
2
2
 
3
3
  default: &default
4
- source_path: app/packs
5
- source_entry_path: entrypoints
4
+ source_path: app/javascript
5
+ source_entry_path: packs
6
6
  public_output_path: packs
7
7
  cache_path: tmp/cache/webpacker
8
8
 
9
- # Additional paths webpack should look up modules
9
+ # Additional paths webpack should lookup modules
10
10
  # ['app/assets', 'engine/foo/app/assets']
11
11
  additional_paths:
12
12
  - app/assets
@@ -1,7 +1,7 @@
1
1
  /* eslint no-console:0 */
2
2
  // This file is automatically compiled by Webpack, along with any other files
3
3
  // present in this directory. You're encouraged to place your actual application logic in
4
- // a relevant structure within app/packs and only use these pack files to reference
4
+ // a relevant structure within app/javascript and only use these pack files to reference
5
5
  // that code so it'll be compiled.
6
6
  //
7
7
  // To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
@@ -1,14 +1,14 @@
1
1
  # Note: You must restart bin/webpack-dev-server for changes to take effect
2
2
 
3
3
  default: &default
4
- source_path: app/packs
5
- source_entry_path: entrypoints
4
+ source_path: app/javascript
5
+ source_entry_path: packs
6
6
  public_root_path: public
7
7
  public_output_path: packs
8
8
  cache_path: tmp/cache/webpacker
9
9
  webpack_compile_output: false
10
10
 
11
- # Additional paths webpack should look up modules
11
+ # Additional paths webpack should lookup modules
12
12
  # ['app/assets', 'engine/foo/app/assets']
13
13
  additional_paths:
14
14
  - app/assets
@@ -24,13 +24,6 @@
24
24
  ]
25
25
  }
26
26
  },
27
- "bootstrap": {
28
- "assets": {
29
- "js": [
30
- "/packs/bootstrap-300631c4f0e0f9c865bc.js"
31
- ]
32
- }
33
- },
34
27
  "hello_stimulus": {
35
28
  "assets": {
36
29
  "css": [