webpacker 6.0.0.beta.5 → 6.0.0.rc.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/jest.yml +7 -15
  3. data/.github/workflows/js-lint.yml +7 -15
  4. data/.github/workflows/rubocop.yml +1 -1
  5. data/.github/workflows/ruby.yml +15 -40
  6. data/.node-version +1 -1
  7. data/.rubocop.yml +107 -1
  8. data/CHANGELOG.md +36 -13
  9. data/CONTRIBUTING.md +19 -0
  10. data/Gemfile.lock +105 -104
  11. data/README.md +197 -167
  12. data/config/webpacker.yml +1 -1
  13. data/docs/deployment.md +128 -0
  14. data/docs/developing_webpacker.md +29 -0
  15. data/docs/troubleshooting.md +57 -23
  16. data/docs/v6_upgrade.md +113 -0
  17. data/gemfiles/Gemfile-rails-edge +1 -1
  18. data/gemfiles/Gemfile-rails.6.1.x +12 -0
  19. data/lib/install/{packs/entrypoints/application.js → application.js} +4 -9
  20. data/lib/install/bin/webpack +4 -7
  21. data/lib/install/bin/yarn +18 -0
  22. data/lib/install/config/webpacker.yml +19 -20
  23. data/lib/install/package.json +15 -0
  24. data/lib/install/template.rb +48 -19
  25. data/lib/tasks/webpacker/binstubs.rake +2 -2
  26. data/lib/tasks/webpacker/check_node.rake +3 -0
  27. data/lib/tasks/webpacker/check_yarn.rake +4 -1
  28. data/lib/tasks/webpacker/clobber.rake +1 -1
  29. data/lib/tasks/webpacker/install.rake +2 -2
  30. data/lib/tasks/webpacker/verify_config.rake +14 -0
  31. data/lib/tasks/webpacker/verify_install.rake +1 -11
  32. data/lib/tasks/yarn.rake +38 -0
  33. data/lib/webpacker/commands.rb +19 -15
  34. data/lib/webpacker/configuration.rb +19 -8
  35. data/lib/webpacker/dev_server.rb +6 -0
  36. data/lib/webpacker/dev_server_runner.rb +6 -3
  37. data/lib/webpacker/env.rb +5 -1
  38. data/lib/webpacker/helper.rb +14 -8
  39. data/lib/webpacker/instance.rb +4 -0
  40. data/lib/webpacker/manifest.rb +1 -2
  41. data/lib/webpacker/railtie.rb +8 -2
  42. data/lib/webpacker/runner.rb +1 -1
  43. data/lib/webpacker/version.rb +1 -1
  44. data/lib/webpacker/webpack_runner.rb +27 -7
  45. data/lib/webpacker.rb +1 -1
  46. data/package/__tests__/development.js +4 -11
  47. data/package/__tests__/env.js +8 -4
  48. data/package/babel/preset.js +0 -1
  49. data/package/config.js +3 -3
  50. data/package/env.js +6 -3
  51. data/package/environments/__tests__/base.js +3 -3
  52. data/package/environments/base.js +13 -13
  53. data/package/environments/development.js +36 -36
  54. data/package/environments/production.js +1 -1
  55. data/package/index.js +2 -0
  56. data/package/inliningCss.js +7 -0
  57. data/package/rules/babel.js +1 -1
  58. data/package/rules/file.js +1 -1
  59. data/package/rules/sass.js +1 -2
  60. data/package/rules/stylus.js +1 -1
  61. data/package/utils/get_style_rule.js +4 -2
  62. data/package.json +25 -29
  63. data/test/command_test.rb +76 -0
  64. data/test/configuration_test.rb +1 -1
  65. data/test/dev_server_runner_test.rb +5 -2
  66. data/test/helper_test.rb +48 -34
  67. data/test/manifest_test.rb +16 -0
  68. data/test/mounted_app/test/dummy/config/webpacker.yml +2 -2
  69. data/test/test_app/config/initializers/inspect_autoload_paths.rb +1 -0
  70. data/test/test_app/config/webpacker.yml +2 -4
  71. data/test/test_app/config/webpacker_other_location.yml +79 -0
  72. data/test/test_app/public/packs/manifest.json +12 -5
  73. data/test/webpacker_test.rb +21 -0
  74. data/webpacker.gemspec +2 -2
  75. data/yarn.lock +2357 -3262
  76. metadata +24 -12
  77. data/6_0_upgrade.md +0 -62
@@ -0,0 +1,128 @@
1
+ # Deployment
2
+
3
+ Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which gets run whenever you run `assets:precompile`.
4
+ If you are not using Sprockets `webpacker:compile` is automatically aliased to `assets:precompile`. Remember to set `NODE_ENV` environment variable to production during deployment or when running the rake task.
5
+
6
+ The `javascript_pack_tag` and `stylesheet_pack_tag` helper method will automatically insert the correct HTML tag for compiled pack. Just like the asset pipeline does it.
7
+
8
+ By default the output will look like this in different environments:
9
+
10
+ ```html
11
+ <!-- In development mode with webpack-dev-server -->
12
+ <script src="http://localhost:8080/calendar-0bd141f6d9360cf4a7f5.js"></script>
13
+ <link rel="stylesheet" media="screen" href="http://localhost:8080/calendar-dc02976b5f94b507e3b6.css">
14
+
15
+ <!-- In production or development mode -->
16
+ <script src="/packs/js/calendar-0bd141f6d9360cf4a7f5.js"></script>
17
+ <link rel="stylesheet" media="screen" href="/packs/css/calendar-dc02976b5f94b507e3b6.css">
18
+ ```
19
+
20
+ ## Heroku
21
+
22
+ In order for your Webpacker app to run on Heroku, you'll need to do a bit of configuration before hand.
23
+
24
+ ```bash
25
+ heroku create my-webpacker-heroku-app
26
+ heroku addons:create heroku-postgresql:hobby-dev
27
+ heroku buildpacks:add heroku/nodejs
28
+ heroku buildpacks:add heroku/ruby
29
+ git push heroku master
30
+ ```
31
+
32
+ We're essentially doing the following here:
33
+
34
+ * Creating an app on Heroku
35
+ * Creating a Postgres database for the app (this is assuming that you're using Heroku Postgres for your app)
36
+ * Adding the Heroku NodeJS and Ruby buildpacks for your app. This allows the `npm` or `yarn` executables to properly function when compiling your app - as well as Ruby.
37
+ * Pushing our code to Heroku and kicking off the deployment
38
+
39
+ ## Nginx
40
+
41
+ Webpacker doesn't serve anything in production. You’re expected to configure your web server to serve files in public/ directly.
42
+
43
+ Some servers support sending precompressed versions of files when they're available. For example, nginx offers a `gzip_static` directive that serves files with the `.gz` extension to supported clients. With an optional module, nginx can also serve Brotli compressed files with the `.br` extension (see below for installation and configuration instructions).
44
+
45
+ Here's a sample nginx site config for a Rails app using Webpacker:
46
+
47
+ ```nginx
48
+ upstream app {
49
+ # server unix:///path/to/app/tmp/puma.sock;
50
+ }
51
+
52
+ server {
53
+ listen 80;
54
+ server_name www.example.com;
55
+ root /path/to/app/public;
56
+
57
+ location @app {
58
+ proxy_pass http://app;
59
+ proxy_redirect off;
60
+
61
+ proxy_set_header Host $host;
62
+ proxy_set_header X-Real-IP $remote_addr;
63
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
64
+ proxy_set_header X-Forwarded-Proto $scheme;
65
+ }
66
+
67
+ location / {
68
+ try_files $uri @app;
69
+ }
70
+
71
+ location = /favicon.ico { access_log off; log_not_found off; }
72
+ location = /robots.txt { access_log off; log_not_found off; }
73
+
74
+ location ~ /\.(?!well-known).* {
75
+ deny all;
76
+ }
77
+
78
+ location ~ ^/(assets|packs)/ {
79
+ gzip_static on;
80
+ brotli_static on; # Optional, see below
81
+ expires max;
82
+ add_header Cache-Control public;
83
+ }
84
+ }
85
+ ```
86
+
87
+ ### Installing the ngx_brotli module
88
+
89
+ If you want to serve Brotli compressed files with nginx, you will need to install the `nginx_brotli` module. Installation instructions from source can be found in the official [google/ngx_brotli](https://github.com/google/ngx_brotli) git repository. Alternatively, depending on your platform, the module might be available via a pre-compiled package.
90
+
91
+ Once installed, you need to load the module. As we want to serve the pre-compressed files, we only need the static module. Add the following line to your `nginx.conf` file and reload nginx:
92
+
93
+ ```
94
+ load_module modules/ngx_http_brotli_static_module.so;
95
+ ```
96
+
97
+ Now, you can set `brotli_static on;` in your nginx site config, as per the config in the last section above.
98
+
99
+ ## CDN
100
+
101
+ Webpacker out-of-the-box provides CDN support using your Rails app `config.action_controller.asset_host` setting. If you already have [CDN](http://guides.rubyonrails.org/asset_pipeline.html#cdns) added in your Rails app
102
+ you don't need to do anything extra for Webpacker, it just works.
103
+
104
+ ## Capistrano
105
+
106
+ ### Assets compiling on every deployment even if JavaScript and CSS files are not changed
107
+
108
+ Make sure you have `public/packs` and `node_modules` in `:linked_dirs`
109
+
110
+ ```ruby
111
+ append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/packs", ".bundle", "node_modules"
112
+ ```
113
+
114
+ If you have `node_modules` added to `:linked_dirs` you'll need to run yarn install before `deploy:assets:precompile`, so you can add this code snippet at the bottom deploy.rb
115
+
116
+ ```ruby
117
+ before "deploy:assets:precompile", "deploy:yarn_install"
118
+ namespace :deploy do
119
+ desc "Run rake yarn install"
120
+ task :yarn_install do
121
+ on roles(:web) do
122
+ within release_path do
123
+ execute("cd #{release_path} && yarn install --silent --no-progress --no-audit --no-optional")
124
+ end
125
+ end
126
+ end
127
+ end
128
+ ```
@@ -0,0 +1,29 @@
1
+ # Developing Webpacker
2
+
3
+ It's a little trickier for Rails developers to work on the JS code of a project like rails/webpacker. So here are some tips!
4
+
5
+ ## Use some test app
6
+ For example, for React on Rails Changes, I'm using [shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh).
7
+ This directory is the `TEST_APP_DIR`.
8
+
9
+ ## Fork rails/webpacker
10
+ Let's call the rails/webpacker directory `WEBPACKER_DIR` which has rails/webpacker's `package.json`.
11
+
12
+ ## Changing the Package
13
+ ### Setup with Yalc
14
+ Use [`yalc`](https://github.com/wclr/yalc) unless you like yak shaving weird errors.
15
+ 1. In `WEBPACKER_DIR`, run `yalc publish`
16
+ 2. In `TEST_APP_DIR`, run `yalc link @rails/webpacker`
17
+
18
+ ## Update the Package Code
19
+ 1. Make some JS change in WEBPACKER_DIR
20
+ 2. Run `yalc push` and your changes will be pushed to your `TEST_APP_DIR`'s node_modules.
21
+ 3. You may need to run `yarn` in `TEST_APP_DIR` if you added or removed dependencies of rails/webpacker.
22
+
23
+ ## Updating the Ruby Code
24
+
25
+ For the Ruby part, just change the gem reference `TEST_APP_DIR`, like:
26
+
27
+ ```ruby
28
+ gem "webpacker", path: "../../forks/webpacker"
29
+ ```
@@ -4,14 +4,17 @@
4
4
 
5
5
  1. Read the error message carefully. The error message will tell you the precise key value
6
6
  that is not matching what Webpack expects.
7
+
7
8
  2. Put a `debugger` statement in your Webpack configuration and run `bin/webpack --debug-webpacker`.
8
9
  If you have a node debugger installed, you'll see the Chrome debugger for your webpack
9
- config. For example, install the Chrome extension
10
+ config. For example, install the Chrome extension
10
11
  [NiM](https://chrome.google.com/webstore/detail/nodejs-v8-inspector-manag/gnhhdgbaldcilmgcpfddgdbkhjohddkj) and
11
12
  set the option for the dev tools to open automatically. Or put `chrome://inspect` in the URL bar.
12
13
  For more details on debugging, see the official
13
14
  [Webpack docs on debugging](https://webpack.js.org/contribute/debugging/#devtools)
15
+
14
16
  3. Any arguments that you add to bin/webpack get sent to webpack. For example, you can pass `--debug` to switch loaders to debug mode. See [webpack CLI debug options](https://webpack.js.org/api/cli/#debug-options) for more information on the available options.
17
+
15
18
  4. You can also pass additional options to the command to run the webpack-dev-server and start the webpack-dev-server with the option `--debug-webpacker`
16
19
 
17
20
  ## ENOENT: no such file or directory - node-sass
@@ -56,16 +59,15 @@ completed the compilation successfully before loading a view.
56
59
  * If you get this error while trying to use Elm, try rebuilding Elm. You can do
57
60
  so with a postinstall hook in your `package.json`:
58
61
 
59
- ```
62
+ ```json
60
63
  "scripts": {
61
64
  "postinstall": "npm rebuild elm"
62
65
  }
63
66
  ```
64
67
 
65
-
66
68
  ## webpack or webpack-dev-server not found
67
69
 
68
- * This could happen if `webpacker:install` step is skipped. Please run `bundle exec rails webpacker:install` to fix the issue.
70
+ * This could happen if `webpacker:install` step is skipped. Please run `bundle exec rails webpacker:install` to fix the issue.
69
71
 
70
72
  * If you encounter the above error on heroku after upgrading from Rails 4.x to 5.1.x, then the problem might be related to missing `yarn` binstub. Please run following commands to update/add binstubs:
71
73
 
@@ -74,7 +76,6 @@ bundle config --delete bin
74
76
  ./bin/rails app:update:bin # or rails app:update:bin
75
77
  ```
76
78
 
77
-
78
79
  ## Running webpack on Windows
79
80
 
80
81
  If you are running webpack on Windows, your command shell may not be able to interpret the preferred interpreter
@@ -86,7 +87,6 @@ C:\path>ruby bin\webpack
86
87
  C:\path>ruby bin\webpack-dev-server
87
88
  ```
88
89
 
89
-
90
90
  ## Invalid configuration object. webpack has been initialised using a configuration object that does not match the API schema.
91
91
 
92
92
  If you receive this error when running `$ ./bin/webpack-dev-server` ensure your configuration is correct; most likely the path to your "packs" folder is incorrect if you modified from the original "source_path" defined in `config/webpacker.yml`.
@@ -101,6 +101,7 @@ Basic fix involves:
101
101
 
102
102
  ```bash
103
103
  # install sysconfcpus on CI
104
+
104
105
  git clone https://github.com/obmarg/libsysconfcpus.git $HOME/dependencies/libsysconfcpus
105
106
  cd libsysconfcpus
106
107
  .configure --prefix=$HOME/dependencies/sysconfcpus
@@ -113,41 +114,39 @@ chmod +x $HOME/your_rails_app/node_modules/.bin/elm-make
113
114
  ```
114
115
 
115
116
  ## Rake assets:precompile fails. ExecJS::RuntimeError
116
- This error occurs because you are trying to minify by terser a pack that's already been minified by Webpacker. To avoid this conflict and prevent appearing of ExecJS::RuntimeError error, you will need to disable uglifier from Rails config:
117
+ This error occurs because you are trying to minify by `terser` a pack that's already been minified by Webpacker. To avoid this conflict and prevent appearing of `ExecJS::RuntimeError` error, you will need to disable uglifier from Rails config:
117
118
 
118
119
  ```ruby
119
- // production.rb
120
- # From
120
+ # In production.rb
121
121
 
122
+ # From
122
123
  Rails.application.config.assets.js_compressor = :uglifier
123
124
 
124
125
  # To
125
-
126
126
  Rails.application.config.assets.js_compressor = Uglifier.new(harmony: true)
127
-
128
127
  ```
129
128
 
130
129
  ### Angular: WARNING in ./node_modules/@angular/core/esm5/core.js, Critical dependency: the request of a dependency is an expression
131
130
 
132
- To silent these warnings, please update `config/webpack/environment.js`
133
-
131
+ To silent these warnings, please update `config/webpack/base.js`:
134
132
  ```js
135
- // environment.js
136
133
  const webpack = require('webpack')
137
134
  const { resolve } = require('path')
138
- const { environment, config } = require('@rails/webpacker')
139
-
140
- environment.plugins.append('ContextReplacement',
141
- new webpack.ContextReplacementPlugin(
142
- /angular(\\|\/)core(\\|\/)(@angular|esm5)/,
143
- resolve(config.source_path)
144
- )
145
- )
135
+ const { webpackConfig, merge } = require('@rails/webpacker')
136
+
137
+ module.exports = merge(webpackConfig, {
138
+ plugins: [
139
+ new webpack.ContextReplacementPlugin(
140
+ /angular(\\|\/)core(\\|\/)(@angular|esm5)/,
141
+ resolve(config.source_path)
142
+ )
143
+ ]
144
+ })
146
145
  ```
147
146
 
148
147
  ### Compilation Fails Silently
149
148
 
150
- If compiling is not producing output files and there are no error messages to help troubleshoot. Setting the webpack_compile_output configuration variable to 'true' in webpacker.yml may add some helpful error information to your log file (Rails log/development.log or log/production.log)
149
+ If compiling is not producing output files and there are no error messages to help troubleshoot. Setting the `webpack_compile_output` configuration variable to `true` in webpacker.yml may add some helpful error information to your log file (Rails `log/development.log` or `log/production.log`)
151
150
 
152
151
  ```yml
153
152
  # webpacker.yml
@@ -158,3 +157,38 @@ default: &default
158
157
  public_output_path: complaints_packs
159
158
  webpack_compile_output: true
160
159
  ```
160
+
161
+ ### Using global variables for dependencies
162
+
163
+ If you want to access any dependency without importing it everywhere or use it directly in your dev tools, please check: [https://webpack.js.org/plugins/provide-plugin/](https://webpack.js.org/plugins/provide-plugin/) and the [webpack docs on shimming globals](https://webpack.js.org/guides/shimming/#shimming-globals).
164
+
165
+ Note, if you are exposing globals, like jQuery, to non-webpack dependencies (like an inline script) via the [expose-loader](https://webpack.js.org/loaders/expose-loader/), you will need to override the default of `defer: true` to be `defer:false` your call to the `javascript_pack_tag` so that the browser will load your bundle to setup the global variable before other code depends on it. However, you really should try to remove the dependendency on such globals.
166
+
167
+ Thus ProvidePlugin manages build-time dependencies to global symbols whereas the expose-loader manages runtime dependencies to global symbols.
168
+
169
+ **You don't need to assign dependencies on `window`.**
170
+
171
+ For instance, with [jQuery](https://jquery.com/):
172
+ ```diff
173
+ // app/packs/entrypoints/application.js
174
+
175
+ - import jQuery from 'jquery'
176
+ - window.jQuery = jQuery
177
+ ```
178
+
179
+ Instead do:
180
+ ```js
181
+ // config/webpack/base.js
182
+
183
+ const webpack = require('webpack')
184
+ const { webpackConfig, merge } = require('@rails/webpacker')
185
+
186
+ module.exports = merge(webpackConfig, {
187
+ plugins: [
188
+ new webpack.ProvidePlugin({
189
+ $: 'jquery',
190
+ jQuery: 'jquery',
191
+ })
192
+ ],
193
+ })
194
+ ```
@@ -0,0 +1,113 @@
1
+ # Upgrading from Webpacker 5 to 6
2
+
3
+ There are several substantial changes in Webpacker 6 that you need to manually account for when coming from Webpacker 5. This guide will help you through it.
4
+
5
+ ## Webpacker has become a slimmer wrapper around Webpack
6
+
7
+ By default, Webpacker 6 is focused on compiling and bundling JavaScript. This pairs with the existing asset pipeline in Rails that's setup to transpile CSS and static images using [Sprockets](https://github.com/rails/sprockets). For most developers, that's the recommended combination. But if you'd like to use Webpacker for CSS and static assets as well, please see [integrations](https://github.com/rails/webpacker#integrations) for more information.
8
+
9
+ Webpacker used to configure Webpack indirectly, which lead to a [complicated secondary configuration process](https://github.com/rails/webpacker/blob/5-x-stable/docs/webpack.md). This was done in order to provide default configurations for the most popular frameworks, but ended up creating more complexity than it cured. So now Webpacker delegates all configuration directly to Webpack's default configuration setup.
10
+
11
+ This means you have to configure integration with frameworks yourself, but webpack-merge helps with this. See this example for [Vue](https://github.com/rails/webpacker#other-frameworks).
12
+
13
+ ## How to upgrade to Webpacker v6 from v5
14
+
15
+ 1. If you are changing from the v5 default for `source_entry_path`:
16
+ ```yml
17
+ source_path: app/javascript
18
+ source_entry_path: packs
19
+ ```
20
+ to the v6 default:
21
+ ```yml
22
+ source_path: app/javascript
23
+ source_entry_path: /
24
+ ```
25
+ Then move your `app/javascript/packs/*` (including `application.js`) to `app/javascript/`.
26
+
27
+ Check if you had any entry point files in child directories of your `source_entry_path`. Files for entry points in child directories are not supported by rails/webpacker v6.
28
+
29
+ 2. Rename `config/webpack` to `config/webpack_old`
30
+
31
+ 3. Rename `config/webpacker.yml` to `config/webpacker_old.yml`
32
+
33
+ 4. Uninstall the current version of `webpack-dev-server`: `yarn remove webpack-dev-server`
34
+
35
+ 5. Upgrade the Webpacker Ruby gem and NPM package
36
+
37
+ Note: [Check the releases page to verify the latest version](https://github.com/rails/webpacker/releases), and make sure to install identical version numbers of webpacker gem and `@rails/webpacker` npm package. (Gems use a period and packages use a dot between the main version number and the beta version.)
38
+
39
+ Example going to a specific version:
40
+
41
+ ```ruby
42
+ # Gemfile
43
+ gem 'webpacker', '6.0.0.rc.5'
44
+ ```
45
+
46
+ ```bash
47
+ bundle install
48
+ ```
49
+
50
+ ```bash
51
+ yarn add @rails/webpacker@6.0.0-rc.5 --exact
52
+ ```
53
+
54
+ ```bash
55
+ bundle exec rails webpacker:install
56
+ ```
57
+
58
+ 6. Update API usage of the view helpers by changing `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` to `javascript_pack_tag` and `stylesheet_pack_tag`. Ensure that your layouts and views will only have **at most one call** to `javascript_pack_tag` and **at most one call** to `stylesheet_pack_tag`. You can now pass multiple bundles to these view helper methods. If you fail to changes this, you may experience performance issues, and other bugs related to multiple copies of React, like [issue 2932](https://github.com/rails/webpacker/issues/2932). If you expose jquery globally with `expose-loader,` by using `import $ from "expose-loader?exposes=$,jQuery!jquery"` in your `app/javascript/application.js`, pass the option `defer: false` to your `javascript_pack_tag`.
59
+
60
+ 7. If you are using any integrations like `css`, `React` or `TypeScript`. Please see https://github.com/rails/webpacker#integrations section on how they work in v6.
61
+
62
+ 8. Copy over any custom webpack config from `config/webpack_old`. Common code previously called 'environment' should be changed to 'base', and import `environment` changed to `webpackConfig`.
63
+
64
+ ```js
65
+ // config/webpack/base.js
66
+ const { webpackConfig, merge } = require('@rails/webpacker')
67
+ const customConfig = require('./custom')
68
+
69
+ module.exports = merge(webpackConfig, customConfig)
70
+ ```
71
+
72
+ 9. Copy over custom browserlist config from `.browserslistrc` if it exists into the `"browserslist"` key in `package.json` and remove `.browserslistrc`.
73
+
74
+ 10. Remove `babel.config.js` if you never changed it. Be sure to have this config in your `package.json`:
75
+
76
+ ```json
77
+ "babel": {
78
+ "presets": [
79
+ "./node_modules/@rails/webpacker/package/babel/preset.js"
80
+ ]
81
+ }
82
+ ```
83
+
84
+ 11. Remove `postcss.config.js` if you don't use `PostCSS`.
85
+
86
+ 12. `extensions` was removed from the `webpacker.yml` file. Move custom extensions to your configuration by merging an object like this. For more details, see docs for [Webpack Configuration](https://github.com/rails/webpacker/blob/master/README.md#webpack-configuration)
87
+
88
+ ```js
89
+ {
90
+ resolve: {
91
+ extensions: ['.ts', '.tsx', '.vue', '.css']
92
+ }
93
+ }
94
+ ```
95
+
96
+ 13. Some dependencies were removed in [PR 3056](https://github.com/rails/webpacker/pull/3056). If you see the error: `Error: Cannot find module 'babel-plugin-macros'`, or similar, then you need to `yarn add <dependency>` where <dependency> might include: `babel-plugin-macros`, `case-sensitive-paths-webpack-plugin`, `core-js`, `regenerator-runtime`. Or you might want to remove your dependency on those.
97
+
98
+ 14. If `bin/yarn` does not exist, create an executable [yarn](https://github.com/rails/webpacker/blob/master/lib/install/bin/yarn) file in your `/bin` directory.
99
+
100
+ 15. Remove overlapping dependencies from your `package.json` and rails/webpacker's `package.json`. For example, don't include `webpack` directly as that's a dependency of rails/webpacker.
101
+
102
+ 16. Review the new default's changes to `webpacker.yml` and `config/webpack`. Consider each suggested change carefully, especially the change to have your `source_entry_path` be at the top level of your `source_path`.
103
+
104
+ 17. Make sure that you can run `bin/webpack` without errors.
105
+
106
+ 18. Try running `RAILS_ENV=production bin/rails assets:precompile`. If all goes well, don't forget to clean the generated assets with `bin/rails assets:clobber`.
107
+
108
+ 19. Try your app!
109
+
110
+ ## Examples of v5 to v6
111
+
112
+ 1. [React on Rails Project with HMR and SSR](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/compare/webpacker-5.x...master)
113
+ 2. [Vue and Sass Example](https://github.com/guillaumebriday/upgrade-webpacker-5-to-6)
@@ -4,7 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
4
4
 
5
5
  gemspec path: "../"
6
6
 
7
- gem "rails", github: "rails/rails"
7
+ gem "rails", github: "rails/rails", branch: "main"
8
8
  gem "arel", github: "rails/arel"
9
9
  gem "rake", ">= 11.1"
10
10
  gem "rack-proxy", require: false
@@ -0,0 +1,12 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
4
+
5
+ gemspec path: "../"
6
+
7
+ gem "rails", '~>6.1.0'
8
+ gem "arel", github: "rails/arel"
9
+ gem "rake", ">= 11.1"
10
+ gem "rack-proxy", require: false
11
+ gem "minitest", "~> 5.0"
12
+ gem "byebug"
@@ -1,20 +1,15 @@
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
- // To reference this file, add <%= javascript_packs_with_chunks_tag 'application' %> to the appropriate
7
+ // To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
8
8
  // layout file, like app/views/layouts/application.html.erb
9
9
 
10
- // Uncomment to copy all static images under ../images to the output folder and reference
10
+ // Uncomment to copy all static images under ./images to the output folder and reference
11
11
  // them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
12
12
  // or the `imagePath` JavaScript helper below.
13
13
  //
14
- // const images = require.context('../images', true)
14
+ // const images = require.context('./images', true)
15
15
  // const imagePath = (name) => images(name, true)
16
-
17
- import 'core-js/stable'
18
- import 'regenerator-runtime/runtime'
19
-
20
- console.log('Hello World from Webpacker')
@@ -1,17 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4
- ENV["NODE_ENV"] ||= "development"
5
-
6
3
  require "pathname"
7
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8
- Pathname.new(__FILE__).realpath)
9
-
10
4
  require "bundler/setup"
11
-
12
5
  require "webpacker"
13
6
  require "webpacker/webpack_runner"
14
7
 
8
+ ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
9
+ ENV["NODE_ENV"] ||= "development"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath)
11
+
15
12
  APP_ROOT = File.expand_path("..", __dir__)
16
13
  Dir.chdir(APP_ROOT) do
17
14
  Webpacker::WebpackRunner.run(ARGV)
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ APP_ROOT = File.expand_path("..", __dir__)
4
+ Dir.chdir(APP_ROOT) do
5
+ yarn = ENV["PATH"].split(File::PATH_SEPARATOR).
6
+ select { |dir| File.expand_path(dir) != __dir__ }.
7
+ product(["yarn", "yarnpkg", "yarn.cmd", "yarn.ps1"]).
8
+ map { |dir, file| File.expand_path(file, dir) }.
9
+ find { |file| File.executable?(file) }
10
+
11
+ if yarn
12
+ exec yarn, *ARGV
13
+ else
14
+ $stderr.puts "Yarn executable was not detected in the system."
15
+ $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
16
+ exit 1
17
+ end
18
+ end
@@ -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: /
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: true
10
10
 
11
- # Additional paths webpack should lookup modules
11
+ # Additional paths webpack should look up modules
12
12
  # ['app/assets', 'engine/foo/app/assets']
13
13
  additional_paths: []
14
14
 
@@ -24,29 +24,28 @@ development:
24
24
  https: false
25
25
  host: localhost
26
26
  port: 3035
27
- public: localhost:3035
28
- # Inject browserside javascript that required by both HMR and Live(full) reload
29
- inject_client: true
30
27
  # Hot Module Replacement updates modules while the application is running without a full reload
31
28
  hmr: false
32
- # Inline should be set to true if using HMR; it inserts a script to take care of live reloading
33
- inline: true
34
- # Should we show a full-screen overlay in the browser when there are compiler errors or warnings?
35
- overlay: true
29
+ # Defaults to the inverse of hmr. Uncomment to manually set this.
30
+ # live_reload: true
31
+ client:
32
+ # Should we show a full-screen overlay in the browser when there are compiler errors or warnings?
33
+ overlay: true
34
+ # May also be a string
35
+ # webSocketURL:
36
+ # hostname: "0.0.0.0"
37
+ # pathname: "/ws"
38
+ # port: 8080
36
39
  # Should we use gzip compression?
37
40
  compress: true
38
41
  # Note that apps that do not check the host are vulnerable to DNS rebinding attacks
39
- disable_host_check: true
40
- # This option lets the browser open with your local IP
41
- use_local_ip: false
42
- # When enabled, nothing except the initial startup information will be written to the console.
43
- # This also means that errors or warnings from webpack are not visible.
44
- quiet: false
45
- pretty: false
42
+ allowed_hosts: "all"
43
+ pretty: true
46
44
  headers:
47
45
  'Access-Control-Allow-Origin': '*'
48
- watch_options:
49
- ignored: '**/node_modules/**'
46
+ static:
47
+ watch:
48
+ ignored: '**/node_modules/**'
50
49
 
51
50
  test:
52
51
  <<: *default
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "app",
3
+ "private": true,
4
+ "dependencies": {
5
+ },
6
+ "version": "0.1.0",
7
+ "babel": {
8
+ "presets": [
9
+ "./node_modules/@rails/webpacker/package/babel/preset.js"
10
+ ]
11
+ },
12
+ "browserslist": [
13
+ "defaults"
14
+ ]
15
+ }