shakapacker 9.0.0 β†’ 9.1.0

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.
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Shakapacker (v9)
2
+
2
3
  ---
3
4
 
4
5
  _πŸš€ Shakapacker 9 supports [Rspack](https://rspack.rs/)! 10x faster than webpack!_
@@ -7,13 +8,13 @@ _πŸš€ Shakapacker 9 supports [Rspack](https://rspack.rs/)! 10x faster than webpa
7
8
 
8
9
  _Official, actively maintained successor to [rails/webpacker](https://github.com/rails/webpacker). ShakaCode stands behind the long-term maintenance and development of this project for the Rails community._
9
10
 
10
- * ⚠️ See the [6-stable](https://github.com/shakacode/shakapacker/tree/6-stable) branch for Shakapacker v6.x code and documentation. :warning:
11
- * **See [V9 Upgrade](./docs/v9_upgrade.md) for upgrading from the v8 release.**
12
- * See [V8 Upgrade](./docs/v8_upgrade.md) for upgrading from the v7 release.
13
- * See [V7 Upgrade](./docs/v7_upgrade.md) for upgrading from the v6 release.
14
- * See [V6 Upgrade](./docs/v6_upgrade.md) for upgrading from v5 or prior v6 releases.
11
+ - ⚠️ See the [6-stable](https://github.com/shakacode/shakapacker/tree/6-stable) branch for Shakapacker v6.x code and documentation. :warning:
12
+ - **See [V9 Upgrade](./docs/v9_upgrade.md) for upgrading from the v8 release.**
13
+ - See [V8 Upgrade](./docs/v8_upgrade.md) for upgrading from the v7 release.
14
+ - See [V7 Upgrade](./docs/v7_upgrade.md) for upgrading from the v6 release.
15
+ - See [V6 Upgrade](./docs/v6_upgrade.md) for upgrading from v5 or prior v6 releases.
15
16
 
16
- [![Ruby specs](https://github.com/shakacode/shakapacker/workflows/Ruby%20specs/badge.svg)](https://github.com/shakacode/shakapacker/actions)
17
+ [![Ruby based checks](https://github.com/shakacode/shakapacker/workflows/Ruby%20based%20checks/badge.svg)](https://github.com/shakacode/shakapacker/actions)
17
18
  [![Jest specs](https://github.com/shakacode/shakapacker/workflows/Jest%20specs/badge.svg)](https://github.com/shakacode/shakapacker/actions)
18
19
  [![Rubocop](https://github.com/shakacode/shakapacker/workflows/Rubocop/badge.svg)](https://github.com/shakacode/shakapacker/actions)
19
20
  [![JS lint](https://github.com/shakacode/shakapacker/workflows/JS%20lint/badge.svg)](https://github.com/shakacode/shakapacker/actions)
@@ -33,9 +34,10 @@ See a comparison of [Shakapacker with jsbundling-rails](https://github.com/rails
33
34
  For discussions, see our [Slack Channel](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE).
34
35
 
35
36
  ---
37
+
36
38
  ## ShakaCode Support
37
39
 
38
- [ShakaCode](https://www.shakacode.com) focuses on helping Ruby on Rails teams use React and Webpack better. We can upgrade your project and improve your development and customer experiences, allowing you to focus on building new features or fixing bugs instead.
40
+ [ShakaCode](https://www.shakacode.com) focuses on helping Ruby on Rails teams use React and Webpack better. We can upgrade your project and improve your development and customer experiences, allowing you to focus on building new features or fixing bugs instead.
39
41
 
40
42
  For an overview of working with us, see our [Client Engagement Model](https://www.shakacode.com/blog/client-engagement-model/) article and [how we bill for time](https://www.shakacode.com/blog/shortcut-jira-trello-github-toggl-time-and-task-tracking/).
41
43
 
@@ -44,6 +46,7 @@ We also specialize in helping development teams lower infrastructure and CI cost
44
46
  If you think ShakaCode can help your project, [click here](https://meetings.hubspot.com/justingordon/30-minute-consultation) to book a call with [Justin Gordon](mailto:justin@shakacode.com), the creator of React on Rails and Shakapacker.
45
47
 
46
48
  Here's a testimonial of how ShakaCode can help from [Florian Gâßler](https://github.com/FGoessler) of [Blinkist](https://www.blinkist.com/), January 2, 2023:
49
+
47
50
  > Hey Justin πŸ‘‹
48
51
  >
49
52
  > I just wanted to let you know that we today shipped the webpacker to shakapacker upgrades and it all seems to be running smoothly! Thanks again for all your support and your teams work! 😍
@@ -59,50 +62,50 @@ Read the [full review here](https://clutch.co/profile/shakacode#reviews?sort_by=
59
62
  <!-- START doctoc generated TOC please keep comment here to allow auto update -->
60
63
  <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
61
64
 
62
- - [Prerequisites](#prerequisites)
63
- - [Features](#features)
64
- - [Optional support](#optional-support)
65
- - [Installation](#installation)
66
- - [Rails v6+](#rails-v6)
67
- - [Concepts](#concepts)
68
- - [Usage](#usage)
69
- - [Configuration and Code](#configuration-and-code)
70
- - [View Helpers](#view-helpers)
71
- - [View Helpers `javascript_pack_tag` and `stylesheet_pack_tag`](#view-helpers-javascript_pack_tag-and-stylesheet_pack_tag)
72
- - [View Helpers `append_javascript_pack_tag`, `prepend_javascript_pack_tag` and `append_stylesheet_pack_tag`](#view-helper-append_javascript_pack_tag-prepend_javascript_pack_tag-and-append_stylesheet_pack_tag)
73
- - [View Helper: `asset_pack_path`](#view-helper-asset_pack_path)
74
- - [View Helper: `image_pack_tag`](#view-helper-image_pack_tag)
75
- - [View Helper: `favicon_pack_tag`](#view-helper-favicon_pack_tag)
76
- - [View Helper: `preload_pack_asset`](#view-helper-preload_pack_asset)
77
- - [Images in Stylesheets](#images-in-stylesheets)
78
- - [Server-Side Rendering (SSR)](#server-side-rendering-ssr)
79
- - [Development](#development)
80
- - [Automatic Webpack Code Building](#automatic-webpack-code-building)
81
- - [Compiler strategies](#compiler-strategies)
82
- - [Common Development Commands](#common-development-commands)
83
- - [Webpack Configuration](#webpack-configuration)
84
- - [Babel configuration](#babel-configuration)
85
- - [SWC configuration](#swc-configuration)
86
- - [esbuild loader configuration](#esbuild-loader-configuration)
87
- - [Integrations](#integrations)
88
- - [React](#react)
89
- - [Typescript](#typescript)
90
- - [CSS](#css)
91
- - [Postcss](#postcss)
92
- - [Sass](#sass)
93
- - [Less](#less)
94
- - [Stylus](#stylus)
95
- - [CoffeeScript](#coffeescript)
96
- - [Other frameworks](#other-frameworks)
97
- - [Custom Rails environments](#custom-rails-environments)
98
- - [Upgrading](#upgrading)
99
- - [Paths](#paths)
100
- - [Additional paths](#additional-paths)
101
- - [Deployment](#deployment)
102
- - [Example Apps](#example-apps)
103
- - [Troubleshooting](#troubleshooting)
104
- - [Contributing](#contributing)
105
- - [License](#license)
65
+ - [Prerequisites](#prerequisites)
66
+ - [Features](#features)
67
+ - [Optional support](#optional-support)
68
+ - [Installation](#installation)
69
+ - [Rails v6+](#rails-v6)
70
+ - [Concepts](#concepts)
71
+ - [Usage](#usage)
72
+ - [Configuration and Code](#configuration-and-code)
73
+ - [View Helpers](#view-helpers)
74
+ - [View Helpers `javascript_pack_tag` and `stylesheet_pack_tag`](#view-helpers-javascript_pack_tag-and-stylesheet_pack_tag)
75
+ - [View Helpers `append_javascript_pack_tag`, `prepend_javascript_pack_tag` and `append_stylesheet_pack_tag`](#view-helper-append_javascript_pack_tag-prepend_javascript_pack_tag-and-append_stylesheet_pack_tag)
76
+ - [View Helper: `asset_pack_path`](#view-helper-asset_pack_path)
77
+ - [View Helper: `image_pack_tag`](#view-helper-image_pack_tag)
78
+ - [View Helper: `favicon_pack_tag`](#view-helper-favicon_pack_tag)
79
+ - [View Helper: `preload_pack_asset`](#view-helper-preload_pack_asset)
80
+ - [Images in Stylesheets](#images-in-stylesheets)
81
+ - [Server-Side Rendering (SSR)](#server-side-rendering-ssr)
82
+ - [Development](#development)
83
+ - [Automatic Webpack Code Building](#automatic-webpack-code-building)
84
+ - [Compiler strategies](#compiler-strategies)
85
+ - [Common Development Commands](#common-development-commands)
86
+ - [Webpack Configuration](#webpack-configuration)
87
+ - [Babel configuration](#babel-configuration)
88
+ - [SWC configuration](#swc-configuration)
89
+ - [esbuild loader configuration](#esbuild-loader-configuration)
90
+ - [Integrations](#integrations)
91
+ - [React](#react)
92
+ - [Typescript](#typescript)
93
+ - [CSS](#css)
94
+ - [Postcss](#postcss)
95
+ - [Sass](#sass)
96
+ - [Less](#less)
97
+ - [Stylus](#stylus)
98
+ - [CoffeeScript](#coffeescript)
99
+ - [Other frameworks](#other-frameworks)
100
+ - [Custom Rails environments](#custom-rails-environments)
101
+ - [Upgrading](#upgrading)
102
+ - [Paths](#paths)
103
+ - [Additional paths](#additional-paths)
104
+ - [Deployment](#deployment)
105
+ - [Example Apps](#example-apps)
106
+ - [Troubleshooting](#troubleshooting)
107
+ - [Contributing](#contributing)
108
+ - [License](#license)
106
109
  - [Supporters](#supporters)
107
110
 
108
111
  <!-- END doctoc generated TOC please keep comment here to allow auto update -->
@@ -114,6 +117,7 @@ Read the [full review here](https://clutch.co/profile/shakacode#reviews?sort_by=
114
117
  - Node.js 14+
115
118
 
116
119
  ## Features
120
+
117
121
  - Rails view helpers that fully support Webpack output, including HMR and code splitting.
118
122
  - Convenient but not required webpack configuration. The only requirement is that your webpack configuration creates a manifest.
119
123
  - HMR with the `shakapacker-dev-server`, such as for hot-reloading React!
@@ -126,17 +130,20 @@ Read the [full review here](https://clutch.co/profile/shakacode#reviews?sort_by=
126
130
  - Extensible and configurable. For example, all major dependencies are specified as peers, so you can upgrade easily.
127
131
 
128
132
  ### Optional support
129
- _Requires extra packages to be installed._
130
- - React
131
- - TypeScript
132
- - Stylesheets - Sass, Less, Stylus and Css, PostCSS
133
- - CoffeeScript
133
+
134
+ _Requires extra packages to be installed._
135
+
136
+ - React
137
+ - TypeScript
138
+ - Stylesheets - Sass, Less, Stylus and Css, PostCSS
139
+ - CoffeeScript
134
140
 
135
141
  ## Installation
136
142
 
137
143
  ### Rails v6+
138
144
 
139
145
  With Rails v6+, skip JavaScript for a new app and follow below Manual Installation Steps to manually add the `shakapacker` gem to your Gemfile.
146
+
140
147
  ```bash
141
148
  rails new myapp --skip-javascript
142
149
  ```
@@ -178,7 +185,7 @@ If you wish to use [Yarn PnP](https://yarnpkg.com/features/pnp) you will need to
178
185
  > [!NOTE]
179
186
  >
180
187
  > The rest of the documentation will only reference `npm` when providing commands such as to install optional packages except in cases where
181
- > a particular package manager requires a very different command; otherwise it should be safe to just replace `npm` with the name of your
188
+ > a particular package manager requires a very different command; otherwise it should be safe to just replace `npm` with the name of your
182
189
  > preferred package manager when running the command
183
190
 
184
191
  Note, in v6+, most JS packages are peer dependencies. Thus, the installer will add the packages:
@@ -203,6 +210,7 @@ making these peer dependencies, you have control over the versions used in your
203
210
  ### Optional Peer Dependencies
204
211
 
205
212
  All peer dependencies in Shakapacker are marked as optional via `peerDependenciesMeta`. This design decision ensures:
213
+
206
214
  - **No warnings during package installation** when dependencies are not needed
207
215
  - **Clear visibility of supported package versions** for upgrades
208
216
  - **Flexibility to choose only the tools you need** (webpack vs rspack, babel vs swc vs esbuild)
@@ -215,6 +223,7 @@ version compatibility constraints when you do install those packages.
215
223
  Depending on your setup, you'll need different subsets of the optional peer dependencies:
216
224
 
217
225
  **For Webpack + Babel (traditional setup):**
226
+
218
227
  ```json
219
228
  {
220
229
  "dependencies": {
@@ -235,6 +244,7 @@ Depending on your setup, you'll need different subsets of the optional peer depe
235
244
  ```
236
245
 
237
246
  **For Webpack + SWC (faster alternative):**
247
+
238
248
  ```json
239
249
  {
240
250
  "dependencies": {
@@ -252,6 +262,7 @@ Depending on your setup, you'll need different subsets of the optional peer depe
252
262
  ```
253
263
 
254
264
  **For Rspack + SWC (10x faster bundling):**
265
+
255
266
  ```json
256
267
  {
257
268
  "dependencies": {
@@ -265,7 +276,21 @@ Depending on your setup, you'll need different subsets of the optional peer depe
265
276
  }
266
277
  ```
267
278
 
279
+ **Quick tip:** You can easily switch between webpack and rspack using:
280
+
281
+ ```bash
282
+ rails shakapacker:switch_bundler rspack --install-deps
283
+ # or with rake (note the -- separator)
284
+ rake shakapacker:switch_bundler rspack -- --install-deps
285
+
286
+ # For faster switching, use --no-uninstall to keep both bundlers installed
287
+ rails shakapacker:switch_bundler webpack --install-deps --no-uninstall
288
+ ```
289
+
290
+ See the [Rspack Migration Guide](./docs/rspack_migration_guide.md) for details.
291
+
268
292
  **For CSS/Sass processing (add to any config above):**
293
+
269
294
  ```json
270
295
  {
271
296
  "dependencies": {
@@ -294,10 +319,11 @@ You will need your file system to correspond to the setup of your `config/shakap
294
319
  Suppose you have the following configuration:
295
320
 
296
321
  `shakapacker.yml`
322
+
297
323
  ```yml
298
324
  default: &default
299
325
  source_path: app/javascript
300
- source_entry_path: packs
326
+ source_entry_path: packs
301
327
  public_root_path: public
302
328
  public_output_path: packs
303
329
  nested_entries: false
@@ -331,6 +357,7 @@ To enable/disable the usage of contentHash in any node environment (specified us
331
357
  You can use the environment variable `SHAKAPACKER_CONFIG` to enforce a particular path to the config file rather than the default `config/shakapacker.yml`.
332
358
 
333
359
  ### View Helpers
360
+
334
361
  The Shakapacker view helpers generate the script and link tags to get the webpack output onto your views.
335
362
 
336
363
  Be sure to consult the API documentation in the source code of [helper.rb](./lib/shakapacker/helper.rb).
@@ -358,6 +385,7 @@ You can provide multiple packs and other attributes. Note, `defer` defaults to s
358
385
  ```
359
386
 
360
387
  The resulting HTML would look like this:
388
+
361
389
  ```html
362
390
  <script src="/packs/vendor-16838bab065ae1e314.js" data-turbo-track="reload" defer></script>
363
391
  <script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbo-track="reload" defer></script>
@@ -390,7 +418,7 @@ Note that when using `async: true`, scripts may execute in any order as soon as
390
418
  >
391
419
  > When both `async` and `defer` attributes are specified, `async` takes precedence according to HTML5 specifications. So if you pass both `async: true` and `defer: true`, the script tag will use `async`.
392
420
 
393
- **Important:** Pass all your pack names as multiple arguments, not multiple calls, when using `javascript_pack_tag` and the `stylesheet_pack_tag`. Otherwise, you will get duplicated chunks on the page.
421
+ **Important:** Pass all your pack names as multiple arguments, not multiple calls, when using `javascript_pack_tag` and the `stylesheet_pack_tag`. Otherwise, you will get duplicated chunks on the page.
394
422
 
395
423
  ```erb
396
424
  <%# DO %>
@@ -406,7 +434,7 @@ you may use multiple calls to stylesheet_pack_tag if,
406
434
  say,
407
435
  you require multiple `<style>` tags for different output media:
408
436
 
409
- ``` erb
437
+ ```erb
410
438
  <%= stylesheet_pack_tag 'application', media: 'screen' %>
411
439
  <%= stylesheet_pack_tag 'print', media: 'print' %>
412
440
  ```
@@ -416,18 +444,21 @@ you require multiple `<style>` tags for different output media:
416
444
  If you need to configure your script pack names or stylesheet pack names from the view for a route or partials, then you will need some logic to ensure you call the helpers only once with multiple arguments. The new view helpers, `append_javascript_pack_tag` and `append_stylesheet_pack_tag` can solve this problem. The helper `append_javascript_pack_tag` will queue up script packs when the `javascript_pack_tag` is finally used. Similarly,`append_stylesheet_pack_tag` will queue up style packs when the `stylesheet_pack_tag` is finally used.
417
445
 
418
446
  Main view:
447
+
419
448
  ```erb
420
449
  <% append_javascript_pack_tag 'calendar' %>
421
450
  <% append_stylesheet_pack_tag 'calendar' %>
422
451
  ```
423
452
 
424
453
  Some partial:
454
+
425
455
  ```erb
426
456
  <% append_javascript_pack_tag 'map' %>
427
457
  <% append_stylesheet_pack_tag 'map' %>
428
458
  ```
429
459
 
430
460
  And the main layout has:
461
+
431
462
  ```erb
432
463
  <%= javascript_pack_tag 'application' %>
433
464
  <%= stylesheet_pack_tag 'application' %>
@@ -449,9 +480,9 @@ Thus, you can distribute the logic of what packs are needed for any route. All t
449
480
  The typical issue is that your layout might reference some partials that need to configure packs. A good way to solve this problem is to use `content_for` to ensure that the code to render your partial comes before the call to `javascript_pack_tag`.
450
481
 
451
482
  ```erb
452
- <% content_for :footer do
483
+ <% content_for :footer do
453
484
  render 'shared/footer' %>
454
-
485
+
455
486
  <%= javascript_pack_tag %>
456
487
 
457
488
  <%= content_for :footer %>
@@ -460,16 +491,19 @@ The typical issue is that your layout might reference some partials that need to
460
491
  There is also `prepend_javascript_pack_tag` that will put the entry at the front of the queue. This is handy when you want an entry in the main layout to go before the partial and main layout `append_javascript_pack_tag` entries.
461
492
 
462
493
  Main view:
494
+
463
495
  ```erb
464
496
  <% append_javascript_pack_tag 'map' %>
465
497
  ```
466
498
 
467
499
  Some partial:
500
+
468
501
  ```erb
469
502
  <% append_javascript_pack_tag 'map' %>
470
503
  ```
471
504
 
472
505
  And the main layout has:
506
+
473
507
  ```erb
474
508
  <% prepend_javascript_pack_tag 'main' %>
475
509
  <%= javascript_pack_tag 'application' %>
@@ -486,6 +520,7 @@ For alternative options for setting the additional packs, [see this discussion](
486
520
  #### View Helper: `asset_pack_path`
487
521
 
488
522
  If you want to link a static asset for `<img />` tag, you can use the `asset_pack_path` helper:
523
+
489
524
  ```erb
490
525
  <img src="<%= asset_pack_path 'static/logo.svg' %>" />
491
526
  ```
@@ -493,30 +528,35 @@ If you want to link a static asset for `<img />` tag, you can use the `asset_pac
493
528
  #### View Helper: `image_pack_tag`
494
529
 
495
530
  Or use the dedicated helper:
531
+
496
532
  ```erb
497
533
  <%= image_pack_tag 'application.png', size: '16x10', alt: 'Edit Entry' %>
498
534
  <%= image_pack_tag 'picture.png', srcset: { 'picture-2x.png' => '2x' } %>
499
535
  ```
500
536
 
501
537
  #### View Helper: `favicon_pack_tag`
538
+
502
539
  If you want to create a favicon:
540
+
503
541
  ```erb
504
542
  <%= favicon_pack_tag 'mb-icon.png', rel: 'apple-touch-icon', type: 'image/png' %>
505
543
  ```
506
544
 
507
545
  #### View Helper: `preload_pack_asset`
546
+
508
547
  If you want to preload a static asset in your `<head>`, you can use the `preload_pack_asset` helper:
548
+
509
549
  ```erb
510
550
  <%= preload_pack_asset 'fonts/fa-regular-400.woff2' %>
511
551
  ```
512
552
 
513
-
514
553
  ### Images in Stylesheets
554
+
515
555
  If you want to use images in your stylesheets:
516
556
 
517
557
  ```css
518
558
  .foo {
519
- background-image: url('../images/logo.svg')
559
+ background-image: url("../images/logo.svg");
520
560
  }
521
561
  ```
522
562
 
@@ -596,25 +636,24 @@ end
596
636
 
597
637
  **Note:** Don't forget to prefix `ruby` when running these binstubs on Windows
598
638
 
599
-
600
639
  ### Webpack Configuration
601
640
 
602
641
  First, you don't _need_ to use Shakapacker's webpack configuration. However, the `shakapacker` NPM package provides convenient access to configuration code that reads the `config/shakapacker.yml` file which the view helpers also use. If you have your customized webpack configuration, at the minimum, you must ensure:
603
642
 
604
643
  1. Your output files go to the right directory
605
644
  2. Your output includes a manifest, via package [`webpack-assets-manifest`](https://github.com/webdeveric/webpack-assets-manifest) that maps output names (your 'packs') to the fingerprinted versions, including bundle-splitting dependencies. That's the main secret sauce of Shakapacker!
606
-
645
+
607
646
  The webpack configuration used by Shakapacker lives in `config/webpack/webpack.config.js`; this makes it easy to customize the configuration beyond what's available in `config/shakapacker.yml` by giving you complete control of the final configuration. By default, this file exports the result of `generateWebpackConfig` which handles generating a webpack configuration based on `config/shakapacker.yml`.
608
647
 
609
648
  The easiest way to modify this config is to pass your desired customizations to `generateWebpackConfig` which will use [webpack-merge](https://github.com/survivejs/webpack-merge) to merge them with the configuration generated from `config/shakapacker.yml`:
610
649
 
611
650
  ```js
612
651
  // config/webpack/webpack.config.js
613
- const { generateWebpackConfig } = require('shakapacker')
652
+ const { generateWebpackConfig } = require("shakapacker")
614
653
 
615
654
  const options = {
616
655
  resolve: {
617
- extensions: ['.css', '.ts', '.tsx']
656
+ extensions: [".css", ".ts", ".tsx"]
618
657
  }
619
658
  }
620
659
 
@@ -626,13 +665,13 @@ The `shakapacker` package also exports the `merge` function from [webpack-merge]
626
665
 
627
666
  ```js
628
667
  // config/webpack/webpack.config.js
629
- const { generateWebpackConfig, merge } = require('shakapacker')
668
+ const { generateWebpackConfig, merge } = require("shakapacker")
630
669
 
631
670
  const webpackConfig = generateWebpackConfig()
632
671
 
633
672
  const options = {
634
673
  resolve: {
635
- extensions: ['.css', '.ts', '.tsx']
674
+ extensions: [".css", ".ts", ".tsx"]
636
675
  }
637
676
  }
638
677
 
@@ -650,11 +689,11 @@ You might add separate files to keep your code more organized.
650
689
  module.exports = {
651
690
  resolve: {
652
691
  alias: {
653
- jquery: 'jquery/src/jquery',
654
- vue: 'vue/dist/vue.js',
655
- React: 'react',
656
- ReactDOM: 'react-dom',
657
- vue_resource: 'vue-resource/dist/vue-resource'
692
+ jquery: "jquery/src/jquery",
693
+ vue: "vue/dist/vue.js",
694
+ React: "react",
695
+ ReactDOM: "react-dom",
696
+ vue_resource: "vue-resource/dist/vue-resource"
658
697
  }
659
698
  }
660
699
  }
@@ -665,9 +704,9 @@ Then `require` this file in your `config/webpack/webpack.config.js`:
665
704
  ```js
666
705
  // config/webpack/webpack.config.js
667
706
  // use the new NPM package name, `shakapacker`.
668
- const { generateWebpackConfig } = require('shakapacker')
707
+ const { generateWebpackConfig } = require("shakapacker")
669
708
 
670
- const customConfig = require('./custom')
709
+ const customConfig = require("./custom")
671
710
 
672
711
  module.exports = generateWebpackConfig(customConfig)
673
712
  ```
@@ -676,7 +715,7 @@ If you need access to configs within Shakapacker's configuration, you can import
676
715
 
677
716
  ```js
678
717
  // config/webpack/webpack.config.js
679
- const { generateWebpackConfig } = require('shakapacker')
718
+ const { generateWebpackConfig } = require("shakapacker")
680
719
 
681
720
  const webpackConfig = generateWebpackConfig()
682
721
 
@@ -690,11 +729,12 @@ console.log(JSON.stringify(webpackConfig, undefined, 2))
690
729
  You may want to modify the rules in the default configuration. For instance, if you are using a custom svg loader, you may want to remove `.svg` from the default file loader rules. You can search and filter the default rules like so:
691
730
 
692
731
  ```js
693
- const fileRule = config.module.rules.find(rule => rule.test.test('.svg'));
732
+ const fileRule = config.module.rules.find((rule) => rule.test.test(".svg"))
694
733
  // removing svg from asset file rule's test RegExp
695
- fileRule.test = /\.(bmp|gif|jpe?g|png|tiff|ico|avif|webp|eot|otf|ttf|woff|woff2)$/
734
+ fileRule.test =
735
+ /\.(bmp|gif|jpe?g|png|tiff|ico|avif|webp|eot|otf|ttf|woff|woff2)$/
696
736
  // changing the rule type from 'asset/resource' to 'asset'. See https://webpack.js.org/guides/asset-modules/
697
- fileRule.type = 'asset'
737
+ fileRule.type = "asset"
698
738
  ```
699
739
 
700
740
  ### Babel configuration
@@ -708,8 +748,8 @@ By default, you will find the Shakapacker preset in your `package.json`. Note, y
708
748
  ]
709
749
  },
710
750
  ```
711
- Optionally, you can change your Babel configuration by removing these lines in your `package.json` and adding [a Babel configuration file](https://babeljs.io/docs/en/config-files) to your project. For an example of customization based on the original, see [Customizing Babel Config](./docs/customizing_babel_config.md).
712
751
 
752
+ Optionally, you can change your Babel configuration by removing these lines in your `package.json` and adding [a Babel configuration file](https://babeljs.io/docs/en/config-files) to your project. For an example of customization based on the original, see [Customizing Babel Config](./docs/customizing_babel_config.md).
713
753
 
714
754
  ### SWC configuration
715
755
 
@@ -776,30 +816,30 @@ Then modify the webpack config to use it as a plugin:
776
816
 
777
817
  ```js
778
818
  // config/webpack/webpack.config.js
779
- const { generateWebpackConfig } = require("shakapacker");
780
- const ForkTSCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
819
+ const { generateWebpackConfig } = require("shakapacker")
820
+ const ForkTSCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin")
781
821
 
782
822
  module.exports = generateWebpackConfig({
783
- plugins: [new ForkTSCheckerWebpackPlugin()],
784
- });
823
+ plugins: [new ForkTSCheckerWebpackPlugin()]
824
+ })
785
825
  ```
786
826
 
787
827
  Optionally, your webpack config file itself can be written in Typescript:
788
828
 
789
- ``` bash
829
+ ```bash
790
830
  npm install ts-node @types/node @types/webpack
791
831
  ```
792
832
 
793
833
  ```ts
794
834
  // config/webpack/webpack.config.ts
795
- import { generateWebpackConfig } from "shakapacker";
796
- import ForkTSCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
835
+ import { generateWebpackConfig } from "shakapacker"
836
+ import ForkTSCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin"
797
837
 
798
838
  const config = generateWebpackConfig({
799
- plugins: [new ForkTSCheckerWebpackPlugin()],
800
- });
839
+ plugins: [new ForkTSCheckerWebpackPlugin()]
840
+ })
801
841
 
802
- export default config;
842
+ export default config
803
843
  ```
804
844
 
805
845
  #### CSS
@@ -814,11 +854,11 @@ Optionally, add the `CSS` extension to webpack config for easy resolution.
814
854
 
815
855
  ```js
816
856
  // config/webpack/webpack.config.js
817
- const { generateWebpackConfig } = require('shakapacker')
857
+ const { generateWebpackConfig } = require("shakapacker")
818
858
 
819
859
  const customConfig = {
820
860
  resolve: {
821
- extensions: ['.css']
861
+ extensions: [".css"]
822
862
  }
823
863
  }
824
864
 
@@ -835,6 +875,7 @@ npm install postcss postcss-loader
835
875
  ```
836
876
 
837
877
  Optionally add these two plugins if they are required in your `postcss.config.js`:
878
+
838
879
  ```bash
839
880
  npm install postcss-preset-env postcss-flexbugs-fixes
840
881
  ```
@@ -850,16 +891,19 @@ You will also need to install [Dart Sass](https://github.com/sass/dart-sass), [N
850
891
  Please refer to [sass-loader documentation](https://www.npmjs.com/package/sass-loader) and individual packages repos for more information on all the options.
851
892
 
852
893
  ##### Dart Sass
894
+
853
895
  ```bash
854
896
  npm install sass
855
897
  ```
856
898
 
857
899
  ##### Node Sass
900
+
858
901
  ```bash
859
902
  npm install node-sass
860
903
  ```
861
904
 
862
905
  ##### Sass Embedded
906
+
863
907
  ```bash
864
908
  npm install sass-embedded
865
909
  ```
@@ -891,33 +935,34 @@ Please follow Webpack integration guide for the relevant framework or library,
891
935
  3. [Vue](https://vue-loader.vuejs.org/guide/)
892
936
 
893
937
  For example to add Vue support:
938
+
894
939
  ```js
895
940
  // config/webpack/rules/vue.js
896
- const { VueLoaderPlugin } = require('vue-loader')
941
+ const { VueLoaderPlugin } = require("vue-loader")
897
942
 
898
943
  module.exports = {
899
944
  module: {
900
945
  rules: [
901
946
  {
902
947
  test: /\.vue$/,
903
- loader: 'vue-loader'
948
+ loader: "vue-loader"
904
949
  }
905
950
  ]
906
951
  },
907
952
  plugins: [new VueLoaderPlugin()],
908
953
  resolve: {
909
- extensions: ['.vue']
954
+ extensions: [".vue"]
910
955
  }
911
956
  }
912
957
  ```
913
958
 
914
959
  ```js
915
960
  // config/webpack/webpack.config.js
916
- const { generateWebpackConfig, merge } = require('shakapacker')
961
+ const { generateWebpackConfig, merge } = require("shakapacker")
917
962
 
918
963
  const webpackConfig = generateWebpackConfig()
919
964
 
920
- const vueConfig = require('./rules/vue')
965
+ const vueConfig = require("./rules/vue")
921
966
 
922
967
  module.exports = merge(vueConfig, webpackConfig)
923
968
  ```
@@ -1001,6 +1046,14 @@ npm install shakapacker@next
1001
1046
 
1002
1047
  Also, consult the [CHANGELOG](./CHANGELOG.md) for additional upgrade links.
1003
1048
 
1049
+ #### Common Upgrade Scenarios
1050
+
1051
+ For step-by-step guides on common migrations, see the [Common Upgrades Guide](./docs/common-upgrades.md):
1052
+
1053
+ - [Migrating Package Managers](./docs/common-upgrades.md#migrating-package-managers) (Yarn ↔ npm, pnpm)
1054
+ - [Migrating from Babel to SWC](./docs/common-upgrades.md#migrating-from-babel-to-swc) (20-70x faster builds)
1055
+ - [Migrating from Webpack to Rspack](./docs/common-upgrades.md#migrating-from-webpack-to-rspack) (5-10x faster builds)
1056
+
1004
1057
  ### Paths
1005
1058
 
1006
1059
  By default, Shakapacker ships with simple conventions for where the JavaScript app files and compiled webpack bundles will go in your Rails app. All these options are configurable from `config/shakapacker.yml` file.
@@ -1029,11 +1082,12 @@ This is particularly useful when working with libraries like React on Rails wher
1029
1082
  If you're using React on Rails with separate client and server bundles, you can now leverage the `private_output_path` configuration instead of using custom webpack configurations:
1030
1083
 
1031
1084
  1. Update your `config/shakapacker.yml`:
1085
+
1032
1086
  ```yml
1033
1087
  # Before: both client and server bundles in public/
1034
1088
  # After: separate directories
1035
- public_output_path: packs # Client bundles (publicly served)
1036
- private_output_path: ssr-bundles # Server bundles (not publicly served)
1089
+ public_output_path: packs # Client bundles (publicly served)
1090
+ private_output_path: ssr-bundles # Server bundles (not publicly served)
1037
1091
  ```
1038
1092
 
1039
1093
  2. Update your webpack configuration to use the appropriate output path based on the bundle type
@@ -1059,15 +1113,15 @@ If you are adding Shakapacker to an existing app that has most of the assets ins
1059
1113
  add additional paths that webpack should look up when resolving modules:
1060
1114
 
1061
1115
  ```yml
1062
- additional_paths: ['app/assets', 'vendor/assets']
1116
+ additional_paths: ["app/assets", "vendor/assets"]
1063
1117
  ```
1064
1118
 
1065
1119
  You can then import these items inside your modules like so:
1066
1120
 
1067
1121
  ```js
1068
1122
  // Note it's relative to parent directory i.e. app/assets
1069
- import 'stylesheets/main'
1070
- import 'images/rails.png'
1123
+ import "stylesheets/main"
1124
+ import "images/rails.png"
1071
1125
  ```
1072
1126
 
1073
1127
  Assets put in these folders will also have their path stripped just like with the `source_path`.
@@ -1080,7 +1134,6 @@ A file in `app/assets/images/image.svg` with `additional_paths: ['app/assets']`
1080
1134
 
1081
1135
  **Also note:** While importing assets living outside your `source_path` defined in shakapacker.yml (like, for instance, assets under `app/assets`) from within your packs using _relative_ paths like `import '../../assets/javascripts/file.js'` will work in development, Shakapacker won't recompile the bundle in production unless a file that lives in one of it's watched paths has changed (check out `Shakapacker::MtimeStrategy#latest_modified_timestamp` or `Shakapacker::DigestStrategy#watched_files_digest` depending on strategy configured by `compiler_strategy` option in `shakapacker.yml`). That's why you'd need to add `app/assets` to the additional_paths as stated above and use `import 'javascripts/file.js'` instead.
1082
1136
 
1083
-
1084
1137
  ## Deployment
1085
1138
 
1086
1139
  Shakapacker hooks up a new `shakapacker:compile` task to `assets:precompile`, which gets run whenever you run `assets:precompile`. If you are not using Sprockets, `shakapacker:compile` is automatically aliased to `assets:precompile`. Similar to sprockets both rake tasks will compile packs in production mode but will use `RAILS_ENV` to load configuration from `config/shakapacker.yml` (if available).
@@ -1113,6 +1166,7 @@ Shakapacker supports serving JavaScript bundles and assets from a CDN. The key c
1113
1166
  For detailed CDN setup instructions, including CloudFlare configuration, troubleshooting, and advanced setups, see the [CDN Setup Guide](./docs/cdn_setup.md).
1114
1167
 
1115
1168
  **Quick example:**
1169
+
1116
1170
  ```bash
1117
1171
  export SHAKAPACKER_ASSET_HOST=https://cdn.example.com
1118
1172
  RAILS_ENV=production bundle exec rails assets:precompile
@@ -1121,8 +1175,8 @@ RAILS_ENV=production bundle exec rails assets:precompile
1121
1175
  For more deployment documentation, see [Deployment](./docs/deployment.md).
1122
1176
 
1123
1177
  ## Example Apps
1124
- * [React on Rails Tutorial With SSR, HMR fast refresh, and TypeScript](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh)
1125
1178
 
1179
+ - [React on Rails Tutorial With SSR, HMR fast refresh, and TypeScript](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh)
1126
1180
 
1127
1181
  ## Troubleshooting
1128
1182
 
@@ -1135,7 +1189,7 @@ We encourage you to contribute to Shakapacker! See [CONTRIBUTING](CONTRIBUTING.m
1135
1189
  ## License
1136
1190
 
1137
1191
  Shakapacker is released under the [MIT License](https://opensource.org/licenses/MIT).
1138
-
1192
+
1139
1193
  ## Supporters
1140
1194
 
1141
1195
  The following companies support our Open Source projects, and ShakaCode uses their products!