shakapacker 6.0.0.rc.14 → 6.1.0.beta.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 52b536f1a629b24f309e3b8fa5d12b4f00f3ab8d900072aef7a87310de40dbf2
4
- data.tar.gz: aabac3cce21b2ebffd5cb89d250dcbd5adca8599d96dfe2ad6668bd05a81b5ad
3
+ metadata.gz: 4167db4aea00b8ed494df2151cb5fd7ad414dc6617e8c1b0ee5537d461c7c968
4
+ data.tar.gz: 7cc1c3c5f9c5a39801ac1801b252ee609e01a6c06508541b64d30fadcf7464ed
5
5
  SHA512:
6
- metadata.gz: 7ad0f3e841893c69bc92cb543ed5a96305904b8aa8cc7799c7380bed6979577b60b866ef9d197252d1bbd13ae98e11eae2f8e7e9a8eb22be7a68321389f1826d
7
- data.tar.gz: 86396cb0725037f0153731ed203d8c3840116e8dd40fd1a1eb8eceace8f20e4f0fab7105956d466b49a86cb08b3c5ea9de40c06213c91801d3500ec18a0f973e
6
+ metadata.gz: 56ce966357cbf20bcf9fb92839e94988a9f91768118aca2960ec53b0b0ed377df04b0bbb6801e885a9011eafa63655537dc36c63a50eda6cca4d46cba319beee
7
+ data.tar.gz: 163807c57c4e543967a58a3dc96630d92d50fd798bac7d78536c39eaf055281c150922e98e66ad5af5e41daf3b2739b48a0cc5d1285f3251f875fda3581389f4
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- * For versions prior to v6, see the [5.x stable branch of rails/webpacker](https://github.com/rails/webpacker/tree/5-x-stable).
1
+ * For versions prior to v6, see the [5.x stable branch of rails/webpacker](https://github.com/rails/webpacker/tree/5-x-stable).
2
2
  * Please see [UPGRADE GUIDE](./docs/v6_upgrade.md).
3
3
 
4
4
  ## Versions
@@ -6,18 +6,25 @@
6
6
  Changes since last non-beta release.
7
7
 
8
8
  *Please add entries here for your pull requests that are not yet released.*
9
- ## [v6.0.0.rc.14] - January 20, 2022
9
+ ## [v6.0.2] - January 25, 2022
10
+ ### Improved
11
+ - Fix incorrect command name in warning. [PR 33](https://github.com/shakacode/shakapacker/pull/33) by [tricknotes](https://github.com/tricknotes).
12
+
13
+ ## [v6.0.1] - January 24, 2022
14
+ ### Improved
15
+ - PR #21 removed pnp-webpack-plugin as a dev dependency but did not remove it from the peer dependency list. [PR 30](https://github.com/shakacode/shakapacker/pull/30) by [t27duck](https://github.com/t27duck).
16
+
17
+ ## [v6.0.0 changes from v6.0.0.rc.6] - January 22, 2022
10
18
 
11
19
  ### Improved
12
- - Raise on multiple invocations of javascript_pack_tag and stylesheet_pack_tag helpers. [PR 19](https://github.com/shakacode/shakapacker/pull/19) by [tomdracz](https://github.com/tomdracz].
13
- - Remove automatic addition of node_modules into rails asset load path. [PR 20](https://github.com/shakacode/shakapacker/pull/20) by [tomdracz](https://github.com/tomdracz].
14
- - Remove pnp-webpack-plugin. [PR 21](https://github.com/shakacode/shakapacker/pull/21) by [tomdracz](https://github.com/tomdracz].
20
+ - Raise on multiple invocations of javascript_pack_tag and stylesheet_pack_tag helpers. [PR 19](https://github.com/shakacode/shakapacker/pull/19) by [tomdracz](https://github.com/tomdracz).
21
+ - Remove automatic addition of node_modules into rails asset load path. [PR 20](https://github.com/shakacode/shakapacker/pull/20) by [tomdracz](https://github.com/tomdracz).
22
+ - Remove pnp-webpack-plugin. [PR 21](https://github.com/shakacode/shakapacker/pull/21) by [tomdracz](https://github.com/tomdracz).
15
23
 
16
- ## [v6.0.0.rc.13 changes from v6.0.0.rc.6]
17
24
 
18
25
  ### Merged from rails/webpacker
19
26
 
20
- - Make watched_files_digest thread safe. [rails/webpacker #3233](https://github.com/rails/webpacker/pull/3233)
27
+ - Make watched_files_digest thread safe. [rails/webpacker #3233](https://github.com/rails/webpacker/pull/3233)
21
28
  - Use single webpack config webpack.config.js. [rails/webpacker #3240](https://github.com/rails/webpacker/pull/3240)
22
29
  - Switch to peer dependencies. [rails/webpacker #3234](https://github.com/rails/webpacker/pull/3234)
23
30
 
@@ -52,6 +59,8 @@ Changes since last non-beta release.
52
59
  - CSS extraction enabled by default, except when devServer is configured and running
53
60
 
54
61
 
55
- [Unreleased]: https://github.com/shakacode/shakapacker/compare/6.0.0-rc.13...master
56
- [v6.0.0.rc.13 changes from v6.0.0.rc.6]: https://github.com/shakacode/shakapacker/compare/aba79635e6ff6562ec04d3c446d57ef19a5fef7d...v6.0.0-rc.13
62
+ [Unreleased]: https://github.com/shakacode/shakapacker/compare/6.0.2...master
63
+ [v6.0.2]: https://github.com/shakacode/shakapacker/compare/v6.0.1...v6.0.2
64
+ [v6.0.1]: https://github.com/shakacode/shakapacker/compare/v6.0.0...v6.0.1
65
+ [v6.0.0 changes from v6.0.0.rc.6]: https://github.com/shakacode/shakapacker/compare/aba79635e6ff6562ec04d3c446d57ef19a5fef7d...v6.0.0
57
66
  [v6.0.0.rc.6 changes from v5.4]: https://github.com/rails/webpacker/compare/v5.4.3...aba79635e6ff6562ec04d3c446d57ef19a5fef7d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shakapacker (6.0.0.rc.13)
4
+ shakapacker (6.0.0)
5
5
  activesupport (>= 5.2)
6
6
  rack-proxy (>= 0.6.1)
7
7
  railties (>= 5.2)
data/README.md CHANGED
@@ -1,11 +1,7 @@
1
1
  # Shakapacker
2
2
 
3
- _Official, actively maintained fork of [rails/webpacker](https://github.com/rails/webpacker). For pre v6, see [rails/webpacker 5-x-stable](https://github.com/rails/webpacker/tree/5-x-stable). Be sure to see the [CHANGELOG](./CHANGELOG.md)._
4
-
5
- * Note, internal naming will continue to use `webpacker` where possible.
6
- * See [V6 Upgrade](./docs/v6_upgrade.md) for upgrading from v5 or prior v6 releases. See this [PR from v6.0.0.rc.6 to shakapacker](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/pull/27).
7
- * [Slack discussion channel](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE).
8
-
3
+ _Official, actively maintained fork of [rails/webpacker](https://github.com/rails/webpacker). Internal naming for `shakapacker` will continue to use `webpacker` where possible. Notably, the NPM package name is `shakapacker`._
4
+ * See [V6 Upgrade](./docs/v6_upgrade.md) for upgrading from v5 or prior v6 releases.
9
5
 
10
6
  [![Ruby specs](https://github.com/shakacode/shakapacker/workflows/Ruby%20specs/badge.svg)](https://github.com/shakacode/shakapacker/actions)
11
7
  [![Jest specs](https://github.com/shakacode/shakapacker/workflows/Jest%20specs/badge.svg)](https://github.com/shakacode/shakapacker/actions)
@@ -14,6 +10,7 @@ _Official, actively maintained fork of [rails/webpacker](https://github.com/rail
14
10
 
15
11
  [![node.js](https://img.shields.io/badge/node-%3E%3D%2012.0.0-brightgreen.svg)](https://www.npmjs.com/package/shakapacker)
16
12
  [![Gem](https://img.shields.io/gem/v/shakapacker.svg)](https://rubygems.org/gems/shakapacker)
13
+ [![npm version](https://badge.fury.io/js/shakapacker.svg)](https://badge.fury.io/js/shakapacker)
17
14
 
18
15
  Webpacker makes it easy to use the JavaScript pre-processor and bundler
19
16
  [Webpack v5](https://webpack.js.org/)
@@ -35,16 +32,16 @@ Discussion forums to discuss debugging and troubleshooting tips. Please open iss
35
32
  - [Features](#features)
36
33
  - [Optional support](#optional-support)
37
34
  - [Installation](#installation)
38
- - [Rails v6](#rails-v6)
39
- - [Rails v7](#rails-v7)
40
- - [Manual Installation Steps](#manual-installation-steps)
35
+ - [Rails v6+](#rails-v6)
41
36
  - [Note for Sprockets usage](#note-for-sprockets-usage)
42
37
  - [Usage](#usage)
43
- - [Defer for `javascript_pack_tag`](#defer-for-javascript_pack_tag)
44
- - [Server-Side Rendering (SSR)](#server-side-rendering-ssr)
38
+ - [View Helpers](#view-helpers)
39
+ - [Defer for `javascript_pack_tag`](#defer-for-javascript_pack_tag)
40
+ - [Server-Side Rendering (SSR)](#server-side-rendering-ssr)
45
41
  - [Development](#development)
46
42
  - [Webpack Configuration](#webpack-configuration)
47
43
  - [Babel configuration](#babel-configuration)
44
+ - [SWC configuration](#swc-configuration)
48
45
  - [Integrations](#integrations)
49
46
  - [React](#react)
50
47
  - [Typescript](#typescript)
@@ -58,9 +55,10 @@ Discussion forums to discuss debugging and troubleshooting tips. Please open iss
58
55
  - [Other frameworks](#other-frameworks)
59
56
  - [Custom Rails environments](#custom-rails-environments)
60
57
  - [Upgrading](#upgrading)
61
- - [Paths](#paths)
58
+ - [Paths](#paths)
62
59
  - [Additional paths](#additional-paths)
63
60
  - [Deployment](#deployment)
61
+ - [Example Apps](#example-apps)
64
62
  - [Troubleshooting](#troubleshooting)
65
63
  - [Contributing](#contributing)
66
64
  - [License](#license)
@@ -75,49 +73,40 @@ Discussion forums to discuss debugging and troubleshooting tips. Please open iss
75
73
  - Yarn
76
74
 
77
75
  ## Features
78
-
76
+ - Rails view helpers that fully support webpack output
77
+ - Convenient but not required webpack configuration. The only requirement is that your webpack configuration create a manifest.
78
+ - HMR with the webpack-dev-server, such as for hot-reloading for React!
79
+ - Automatic code splitting using multiple entry points to optimize JavaScript downloads
79
80
  - [Webpack v5](https://webpack.js.org/)
80
81
  - ES6 with [babel](https://babeljs.io/)
81
- - Automatic code splitting using multiple entry points
82
82
  - Asset compression, source-maps, and minification
83
83
  - CDN support
84
- - Rails view helpers
85
- - Extensible and configurable
84
+ - Extensible and configurable. For example, all major dependencies are specified as peers, so you can upgrade easily.
86
85
 
87
86
  ### Optional support
88
-
89
- _requires extra packages to be installed_
90
-
91
- - Stylesheets - Sass, Less, Stylus and Css, PostCSS
92
- - CoffeeScript
93
- - TypeScript
94
- - React
87
+ _Requires extra packages to be installed._
88
+ - React
89
+ - TypeScript
90
+ - Stylesheets - Sass, Less, Stylus and Css, PostCSS
91
+ - CoffeeScript
95
92
 
96
93
  ## Installation
97
94
 
98
- ### Rails v6
99
- With Rails v6, webpacker is installed by default:
100
- ```bash
101
- rails new myapp
102
- ```
103
95
 
104
- ### Rails v7
96
+ ### Rails v6+
105
97
 
106
- With Rails v7, skip JavaScript for a new app and follow below Manual Installation Steps to manually add the `webpacker` gem to your Gemfile.
98
+ With Rails v6+, skip JavaScript for a new app and follow below Manual Installation Steps to manually add the `shakapacker` gem to your Gemfile.
107
99
  ```bash
108
100
  rails new myapp --skip-javascript
109
101
  ```
110
102
 
111
- ### Manual Installation Steps
103
+ _Note, Rails 6 installs the older v5 version of webpacker unless you specify `--skip-javascript`._
104
+
112
105
  Update your `Gemfile`:
113
106
 
114
107
  ```ruby
115
108
  # Gemfile
116
109
  gem 'shakapacker', '~> 6.0'
117
-
118
- # OR if you prefer to use master
119
- gem 'shakapacker', git: 'https://github.com/shakacode/shakapacker.git'
120
- yarn add https://github.com/shakacode/shakapacker.git
121
110
  ```
122
111
 
123
112
  Then running the following to install Webpacker:
@@ -155,6 +144,8 @@ Rails.application.config.assets.paths << Rails.root.join('node_modules')
155
144
 
156
145
  ## Usage
157
146
 
147
+ ### View Helpers
148
+
158
149
  Once installed, you can start writing modern ES6-flavored JavaScript apps right away:
159
150
 
160
151
  ```yml
@@ -192,7 +183,7 @@ The result looks like this:
192
183
  <script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload" defer></script>
193
184
  ```
194
185
 
195
- **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. Be especially careful if you might be calling these view helpers from your view, partials, and the layout for a page. You will need some logic to ensure you call the helpers only once with multiple arguments.
186
+ **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. Be especially careful if you might be calling these view helpers from your view, partials, and the layout for a page. You will need some logic to ensure you call the helpers only once with multiple arguments.
196
187
 
197
188
  ```erb
198
189
  <%# DO %>
@@ -234,10 +225,10 @@ If you want to use images in your stylesheets:
234
225
  background-image: url('../images/logo.svg')
235
226
  }
236
227
  ```
237
- ##### Defer for `javascript_pack_tag`
228
+ ### Defer for `javascript_pack_tag`
238
229
  Note, the default of "defer" for the `javascript_pack_tag`. You can override that to `false`. If you expose jquery globally with `expose-loader,` by using `import $ from "expose-loader?exposes=$,jQuery!jquery"` in your `app/packs/entrypoints/application.js`, pass the option `defer: false` to your `javascript_pack_tag`.
239
230
 
240
- #### Server-Side Rendering (SSR)
231
+ ### Server-Side Rendering (SSR)
241
232
 
242
233
  Note, if you are using server-side rendering of JavaScript with dynamic code-splitting, as is often done with extensions to Webpacker, like [React on Rails](https://github.com/shakacode/react_on_rails), your JavaScript should create the link prefetch HTML tags that you will use, so you won't need to use to `asset_pack_path` in those circumstances.
243
234
 
@@ -298,11 +289,33 @@ end
298
289
 
299
290
  ### Webpack Configuration
300
291
 
301
- Webpacker gives you a default configuration file for your test, development, and production environments in `config/webpack/*.js`.
292
+ 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/webpacker.yml` file which the view helpers also use. If you have your own customized webpack configuration, at the mininmum, you must ensure:
293
+
294
+ 1. Your output files go the right directory
295
+ 2. You provide 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 webpacker!
296
+
297
+ The most practical webpack configuration is to take the default from Shakapacker and then use [webpack-merge](https://github.com/survivejs/webpack-merge) to merge your customizations with the default. For example, suppose you want to add some `resolve.extensions`:
298
+
299
+ ```js
300
+ // use the new NPM package name, `shakapacker`.
301
+ // merge is webpack-merge from https://github.com/survivejs/webpack-merge
302
+ const { webpackConfig: baseWebpackConfig, merge } = require('shakapacker')
303
+
304
+ const options = {
305
+ resolve: {
306
+ extensions: ['.css', '.ts', '.tsx']
307
+ }
308
+ }
302
309
 
303
- By default, you don't need to make any changes to `config/webpack/webpack.config.js` files since it's all standard production-ready configuration. However, if you do need to customize or add a new loader, this is where you would go.
310
+ // Copy the object using merge b/c the baseClientWebpackConfig is a mutable global
311
+ // If you want to use this object for client and server rendering configurations,
312
+ // havaing a new object is essential.
313
+ module.exports = merge({}, baseWebpackConfig, options)
314
+ ```
315
+
316
+ This example is based on [an example project](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/config/webpack/webpack.config.js)
304
317
 
305
- Here is how you can modify webpack configuration:
318
+ Webpacker gives you a default configuration file `config/webpack/webpack.config.js`, which, by default, you don't need to make any changes to `config/webpack/webpack.config.js` since it's a standard production-ready configuration. However, you will probably want to customize or add a new loader by modifying the webpack configuration, as shown above.
306
319
 
307
320
  You might add separate files to keep your code more organized.
308
321
 
@@ -325,6 +338,7 @@ Then `require` this file in your `config/webpack/webpack.config.js`:
325
338
 
326
339
  ```js
327
340
  // config/webpack/webpack.config.js
341
+ // use the new NPM package name, `shakapacker`.
328
342
  const { webpackConfig, merge } = require('shakapacker')
329
343
  const customConfig = require('./custom')
330
344
 
@@ -346,7 +360,7 @@ console.log(JSON.stringify(webpackConfig, undefined, 2))
346
360
 
347
361
  ### Babel configuration
348
362
 
349
- By default, you will find the Webpacker preset in your `package.json`.
363
+ By default, you will find the Webpacker preset in your `package.json`. Note, you need to use the new NPM package name, `shakapacker`.
350
364
 
351
365
  ```json
352
366
  "babel": {
@@ -358,6 +372,12 @@ By default, you will find the Webpacker preset in your `package.json`.
358
372
 
359
373
  Optionally, you can change your Babel configuration by removing these lines in your `package.json` and add [a Babel configuration file](https://babeljs.io/docs/en/config-files) in your project. For an example customization based on the original, see [Customizing Babel Config](./docs/customizing_babel_config.md).
360
374
 
375
+ ### SWC configuration
376
+
377
+ You can try out experimental integration with the SWC loader. You can read more at [SWC usage docs](./docs/using_swc_loader.md).
378
+
379
+ Please note that if you want opt-in to use SWC, you can skip [React](#react) integration instructions as it is supported out of the box.
380
+
361
381
  ### Integrations
362
382
 
363
383
  Webpacker out of the box supports JS and static assets (fonts, images etc.) compilation. To enable support for CoffeeScript or TypeScript install relevant packages:
@@ -533,7 +553,6 @@ const vueConfig = require('./rules/vue')
533
553
  module.exports = merge(vueConfig, webpackConfig)
534
554
  ```
535
555
 
536
-
537
556
  ### Custom Rails environments
538
557
 
539
558
  Out of the box Webpacker ships with - development, test and production environments in `config/webpacker.yml` however, in most production apps extra environments are needed as part of deployment workflow. Webpacker supports this out of the box from version 3.4.0+ onwards.
@@ -586,7 +605,7 @@ You can run following commands to upgrade Webpacker to the latest stable version
586
605
 
587
606
  ```bash
588
607
  # check your Gemfile for version restrictions
589
- bundle update webpacker
608
+ bundle update shakapacker
590
609
 
591
610
  # overwrite your changes to the default install files and revert any unwanted changes from the install
592
611
  rails webpacker:install
@@ -605,7 +624,7 @@ yarn add shakapacker@next
605
624
 
606
625
  Also, consult the [CHANGELOG](./CHANGELOG.md) for additional upgrade links.
607
626
 
608
- ## Paths
627
+ ### Paths
609
628
 
610
629
  By default, Webpacker 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/webpacker.yml` file.
611
630
 
@@ -661,18 +680,17 @@ When compiling assets for production on a remote server, such as a continuous in
661
680
 
662
681
  If you are using a CDN setup, webpacker will use the configured [asset host](https://guides.rubyonrails.org/configuring.html#rails-general-configuration) value to prefix URLs for images or font icons which are included inside JS code or CSS. It is possible to override this value during asset compilation by setting the `WEBPACKER_ASSET_HOST` environment variable.
663
682
 
683
+ ## Example Apps
684
+ * [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)
685
+
664
686
 
665
687
  ## Troubleshooting
666
688
 
667
689
  See the doc page for [Troubleshooting](./docs/troubleshooting.md).
668
690
 
669
-
670
691
  ## Contributing
671
692
 
672
- [![Code Helpers](https://www.codetriage.com/shakacode/shakapacker/badges/users.svg)](https://www.codetriage.com/shakacode/shakapacker)
673
-
674
- We encourage you to contribute to Webpacker! See [CONTRIBUTING](CONTRIBUTING.md) for guidelines about how to proceed.
675
-
693
+ We encourage you to contribute to Shakapacker/Webpacker! See [CONTRIBUTING](CONTRIBUTING.md) for guidelines about how to proceed. We have a [Slack discussion channel](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE).
676
694
 
677
695
  ## License
678
696
 
@@ -39,14 +39,14 @@ module.exports = function (api) {
39
39
  development: isDevelopmentEnv || isTestEnv,
40
40
  useBuiltIns: true
41
41
  }
42
- ],
42
+ ]
43
+ ].filter(Boolean),
44
+ plugins: [
43
45
  isProductionEnv && ['babel-plugin-transform-react-remove-prop-types',
44
46
  {
45
47
  removeImport: true
46
48
  }
47
- ]
48
- ].filter(Boolean),
49
- plugins: [
49
+ ],
50
50
  process.env.WEBPACK_SERVE && 'react-refresh/babel'
51
51
  ].filter(Boolean),
52
52
  }
@@ -0,0 +1,151 @@
1
+ # Using SWC Loader
2
+
3
+ :warning: This feature is currently experimental. If you face any issues, please report at https://github.com/shakacode/shakapacker/issues.
4
+
5
+ ## About SWC
6
+
7
+ [SWC (Speedy Web compiler)](https://swc.rs/) is a Rust-based compilation and bundler tool that can be used for Javascript and Typescript files. It claims to be 20x faster than Babel!
8
+
9
+ It supports all ECMAScript features and it's designed to be a drop-in replacement for Babel and its plugins. Out of the box, it supports TS, JSX syntax, React fast refresh, and much more.
10
+
11
+ For comparison between SWC and Babel, see the docs at https://swc.rs/docs/migrating-from-babel.
12
+
13
+ ## Switching your Shakapacker project to SWC
14
+
15
+ In order to use SWC as your compiler today. You need to do two things:
16
+
17
+ 1. Make sure you've installed `@swc/core` and `swc-loader` packages.
18
+
19
+ ```
20
+ yarn add -D @swc/core swc-loader
21
+ ```
22
+
23
+ 2. Add or change `webpacker_loader` value in your default `webpacker.yml` config to `swc`
24
+ The default configuration of babel is done by using `package.json` to use the file within the `shakapacker` package.
25
+
26
+ ```json
27
+ default: &default
28
+ source_path: app/javascript
29
+ source_entry_path: /
30
+ public_root_path: public
31
+ public_output_path: packs
32
+ cache_path: tmp/webpacker
33
+ webpack_compile_output: true
34
+
35
+ # Additional paths webpack should look up modules
36
+ # ['app/assets', 'engine/foo/app/assets']
37
+ additional_paths: []
38
+
39
+ # Reload manifest.json on all requests so we reload latest compiled packs
40
+ cache_manifest: false
41
+
42
+ # Select loader to use, available options are 'babel' (default) or 'swc'
43
+ webpack_loader: 'swc'
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ ### React
49
+
50
+ React is supported out of the box, provided you use `.jsx` or `.tsx` file extension. Shakapacker config will correctly recognize those and tell SWC to parse the JSX syntax correctly. If you wish to customize the transform options to match any existing `@babel/preset-react` settings, you can do that through customizing loader options as described below. You can see available options at https://swc.rs/docs/configuration/compilation#jsctransformreact.
51
+
52
+ ### Typescript
53
+
54
+ Typescript is supported out of the box, but certain features like decorators need to be enabled through the custom config. You can see available customizations options at https://swc.rs/docs/configuration/compilation, which you can apply through customizing loader options as described below.
55
+
56
+ Please note that SWC is not using the settings from `.tsconfig` file. Any non-default settings you might have there will need to be applied to the custom loader config.
57
+
58
+ ## Customizing loader options
59
+
60
+ You can see the default loader options at [swc/index.js](../package/swc/index.js).
61
+
62
+ If you wish to customize the loader defaults further, for example, if you want to enable support for decorators or React fast refresh, you need to create a `swc.config.js` file in your app config folder.
63
+
64
+ This file should have a single default export which is an object with an `options` key. Your customizations will be merged with default loader options. You can use this to override or add additional configurations.
65
+
66
+ Inside the `options` key, you can use any options available to the SWC compiler. For the options reference, please refer to [official SWC docs](https://swc.rs/docs/configuration/compilation).
67
+
68
+ See some examples below of potential `config/swc.config.js`.
69
+
70
+ ### Example: Enabling top level await and decorators
71
+
72
+
73
+ ```js
74
+ const customConfig = {
75
+ options: {
76
+ jsc: {
77
+ parser: {
78
+ topLevelAwait: true,
79
+ decorators: true
80
+ }
81
+ }
82
+ }
83
+ }
84
+
85
+ module.exports = customConfig
86
+ ```
87
+
88
+ ### Example: Matching existing `@babel/present-env` config
89
+
90
+ ```js
91
+ const { env } = require('shakapacker')
92
+
93
+ const customConfig = {
94
+ options: {
95
+ jsc: {
96
+ transform: {
97
+ react: {
98
+ development: env.isDevelopment,
99
+ useBuiltins: true
100
+ }
101
+ }
102
+ }
103
+ }
104
+ }
105
+
106
+ module.exports = customConfig
107
+ ```
108
+
109
+ ### Example: Enabling React Fast Refresh
110
+
111
+ :warning: Remember that you still need to add [@pmmmwh/react-refresh-webpack-plugin](https://github.com/pmmmwh/react-refresh-webpack-plugin) to your webpack config. The setting below just replaces equivalent `react-refresh/babel` Babel plugin.
112
+
113
+
114
+ ```js
115
+ const { env } = require('shakapacker')
116
+
117
+ const customConfig = {
118
+ options: {
119
+ jsc: {
120
+ transform: {
121
+ react: {
122
+ refresh: env.isDevelopment && env.runningWebpackDevServer
123
+ }
124
+ }
125
+ }
126
+ }
127
+ }
128
+
129
+ module.exports = customConfig
130
+ ```
131
+
132
+ ### Example: Adding browserslist config
133
+
134
+ ```js
135
+
136
+ const customConfig = {
137
+ options: {
138
+ env: {
139
+ targets: '> 0.25%, not dead'
140
+ }
141
+ }
142
+ }
143
+
144
+ module.exports = customConfig
145
+ ```
146
+
147
+
148
+ ## Known limitations
149
+
150
+ - `browserslist` config at the moment is not being picked up automatically. [Related SWC issue](https://github.com/swc-project/swc/issues/3365). You can add your browserlist config through customizing loader options as outlined above.
151
+ - Using `.swcrc` config file is currently not supported. You might face some issues when `.swcrc` config is diverging from the SWC options we're passing in the Webpack rule.
data/docs/v6_upgrade.md CHANGED
@@ -11,12 +11,13 @@ Webpacker used to configure Webpack indirectly, which lead to a [complicated sec
11
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/shakacode/shakapacker#other-frameworks) and scroll to the bottom for [more examples](#examples-of-v5-to-v6).
12
12
 
13
13
  ## webpacker v6.0.0.rc.6 to shakapacker
14
- See example migration, [PR 27](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/pull/27).
14
+ See an example migration here: [PR 27](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/pull/27).
15
15
 
16
16
  ### Update
17
17
  1. Peer dependencies. Run `yarn add @babel/core @babel/plugin-transform-runtime @babel/preset-env @babel/runtime babel-loader compression-webpack-plugin terser-webpack-plugin webpack webpack-assets-manifest webpack-cli webpack-merge webpack-sources webpack-dev-server`
18
- 2. Update your webpack config for a single config file, `config/webpack/webpack.config.js`.
19
- 3. Update `babel.config.js` if you need JSX support.
18
+ 1. Update any scripts that called `bin/webpack` or `bin/webpack-dev-server` to `bin/webpacker` or `bin/webpacker-dev-server`
19
+ 1. Update your webpack config for a single config file, `config/webpack/webpack.config.js`.
20
+ 1. Update `babel.config.js` if you need JSX support.
20
21
 
21
22
  ## How to upgrade to Webpacker v6 from v5
22
23
  1. Ensure you have a clean working git branch. You will be overwriting all your files and reverting the changes that you don't want.
@@ -15,6 +15,9 @@ default: &default
15
15
  # Reload manifest.json on all requests so we reload latest compiled packs
16
16
  cache_manifest: false
17
17
 
18
+ # Select loader to use, available options are 'babel' (default) or 'swc'
19
+ webpack_loader: 'babel'
20
+
18
21
  development:
19
22
  <<: *default
20
23
  compile: true
@@ -57,8 +57,8 @@ class Webpacker::Compiler
57
57
  Webpacker::Compiler - Slow setup for development
58
58
 
59
59
  Prepare JS assets with either:
60
- 1. Running `bin/webpack-dev-server`
61
- 2. Set `compile` to false in webpacker.yml and run `bin/webpack -w`
60
+ 1. Running `bin/webpacker-dev-server`
61
+ 2. Set `compile` to false in webpacker.yml and run `bin/webpacker -w`
62
62
  MSG
63
63
  end
64
64
 
@@ -1,4 +1,4 @@
1
1
  module Webpacker
2
2
  # Change the version in package.json too, please!
3
- VERSION = "6.0.0.rc.14".freeze
3
+ VERSION = "6.1.0.beta.0".freeze
4
4
  end
@@ -1,30 +1,32 @@
1
1
  const { resolve } = require('path')
2
2
  const { realpathSync } = require('fs')
3
+ const { loaderMatches } = require('../utils/helpers')
3
4
 
4
5
  const {
5
6
  source_path: sourcePath,
6
- additional_paths: additionalPaths
7
+ additional_paths: additionalPaths,
8
+ webpack_loader: webpackLoader
7
9
  } = require('../config')
8
10
  const { isProduction } = require('../env')
9
11
 
10
- module.exports = {
11
- test: /\.(js|jsx|mjs|ts|tsx|coffee)?(\.erb)?$/,
12
- include: [sourcePath, ...additionalPaths].map((p) => {
13
- try {
14
- return realpathSync(p)
15
- } catch (e) {
16
- return resolve(p)
17
- }
18
- }),
19
- exclude: /node_modules/,
20
- use: [
21
- {
22
- loader: require.resolve('babel-loader'),
23
- options: {
24
- cacheDirectory: true,
25
- cacheCompression: isProduction,
26
- compact: isProduction
12
+ module.exports = loaderMatches(webpackLoader, 'babel', () => ({
13
+ test: /\.(js|jsx|mjs|ts|tsx|coffee)?(\.erb)?$/,
14
+ include: [sourcePath, ...additionalPaths].map((p) => {
15
+ try {
16
+ return realpathSync(p)
17
+ } catch (e) {
18
+ return resolve(p)
27
19
  }
28
- }
29
- ]
30
- }
20
+ }),
21
+ exclude: /node_modules/,
22
+ use: [
23
+ {
24
+ loader: require.resolve('babel-loader'),
25
+ options: {
26
+ cacheDirectory: true,
27
+ cacheCompression: isProduction,
28
+ compact: isProduction
29
+ }
30
+ }
31
+ ]
32
+ }))
@@ -7,6 +7,7 @@ const rules = {
7
7
  css: require('./css'),
8
8
  sass: require('./sass'),
9
9
  babel: require('./babel'),
10
+ swc: require('./swc'),
10
11
  erb: require('./erb'),
11
12
  coffee: require('./coffee'),
12
13
  less: require('./less'),
@@ -0,0 +1,23 @@
1
+ const { resolve } = require('path')
2
+ const { realpathSync } = require('fs')
3
+ const { loaderMatches } = require('../utils/helpers')
4
+ const { getSwcLoaderConfig } = require('../swc')
5
+
6
+ const {
7
+ source_path: sourcePath,
8
+ additional_paths: additionalPaths,
9
+ webpack_loader: webpackLoader
10
+ } = require('../config')
11
+
12
+ module.exports = loaderMatches(webpackLoader, 'swc', () => ({
13
+ test: /\.(ts|tsx|js|jsx|mjs|coffee)?(\.erb)?$/,
14
+ include: [sourcePath, ...additionalPaths].map((p) => {
15
+ try {
16
+ return realpathSync(p)
17
+ } catch (e) {
18
+ return resolve(p)
19
+ }
20
+ }),
21
+ exclude: /node_modules/,
22
+ use: ({ resource }) => getSwcLoaderConfig(resource)
23
+ }))
@@ -0,0 +1,50 @@
1
+ /* eslint global-require: 0 */
2
+ /* eslint import/no-dynamic-require: 0 */
3
+
4
+ const { resolve } = require('path')
5
+ const { existsSync } = require('fs')
6
+ const { merge } = require('webpack-merge')
7
+
8
+ const isJsxFile = (filename) => !!filename.match(/\.(jsx|tsx)?(\.erb)?$/)
9
+
10
+ const isTypescriptFile = (filename) => !!filename.match(/\.(ts|tsx)?(\.erb)?$/)
11
+
12
+ const getCustomConfig = () => {
13
+ const path = resolve('config', 'swc.config.js')
14
+ if (existsSync(path)) {
15
+ return require(path)
16
+ }
17
+ return {}
18
+ }
19
+
20
+ const getSwcLoaderConfig = (filenameToProcess) => {
21
+ const customConfig = getCustomConfig()
22
+ const defaultConfig = {
23
+ loader: require.resolve('swc-loader'),
24
+ options: {
25
+ jsc: {
26
+ parser: {
27
+ dynamicImport: true,
28
+ syntax: isTypescriptFile(filenameToProcess)
29
+ ? 'typescript'
30
+ : 'ecmascript',
31
+ [isTypescriptFile(filenameToProcess) ? 'tsx' : 'jsx']:
32
+ isJsxFile(filenameToProcess)
33
+ }
34
+ },
35
+ sourceMaps: true,
36
+ env: {
37
+ coreJs: '3.8',
38
+ loose: true,
39
+ exclude: ['transform-typeof-symbol'],
40
+ mode: 'entry'
41
+ }
42
+ }
43
+ }
44
+
45
+ return merge(defaultConfig, customConfig)
46
+ }
47
+
48
+ module.exports = {
49
+ getSwcLoaderConfig
50
+ }
@@ -27,7 +27,7 @@ const resolvedPath = (packageName) => {
27
27
  }
28
28
  }
29
29
 
30
- const moduleExists = (packageName) => (!!resolvedPath(packageName))
30
+ const moduleExists = (packageName) => !!resolvedPath(packageName)
31
31
 
32
32
  const canProcess = (rule, fn) => {
33
33
  const modulePath = resolvedPath(rule)
@@ -39,6 +39,22 @@ const canProcess = (rule, fn) => {
39
39
  return null
40
40
  }
41
41
 
42
+ const loaderMatches = (configLoader, loaderToCheck, fn) => {
43
+ if (configLoader !== loaderToCheck) {
44
+ return null
45
+ }
46
+
47
+ const loaderName = `${configLoader}-loader`
48
+
49
+ if (!moduleExists(loaderName)) {
50
+ throw new Error(
51
+ `Your webpacker config specified using ${configLoader}, but ${loaderName} package is not installed. Please install ${loaderName} first.`
52
+ )
53
+ }
54
+
55
+ return fn()
56
+ }
57
+
42
58
  module.exports = {
43
59
  chdirTestApp,
44
60
  chdirCwd,
@@ -47,5 +63,6 @@ module.exports = {
47
63
  ensureTrailingSlash,
48
64
  canProcess,
49
65
  moduleExists,
50
- resetEnv
66
+ resetEnv,
67
+ loaderMatches
51
68
  }
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shakapacker",
3
- "version": "6.0.0-rc.14",
3
+ "version": "6.1.0-beta.0",
4
4
  "description": "Use webpack to manage app-like JavaScript modules in Rails",
5
5
  "main": "package/index.js",
6
6
  "files": [
@@ -18,7 +18,6 @@
18
18
  "@babel/runtime": "^7.15.4",
19
19
  "babel-loader": "^8.2.2",
20
20
  "compression-webpack-plugin": "^9.0.0",
21
- "pnp-webpack-plugin": "^1.7.0",
22
21
  "terser-webpack-plugin": "^5.2.4",
23
22
  "webpack": "^5.53.0",
24
23
  "webpack-assets-manifest": "^5.0.6",
@@ -40,6 +39,7 @@
40
39
  "eslint-plugin-jsx-a11y": "^6.4.1",
41
40
  "eslint-plugin-react": "^7.26.0",
42
41
  "jest": "^27.2.1",
42
+ "swc-loader": "^0.1.15",
43
43
  "webpack": "^5.53.0",
44
44
  "webpack-assets-manifest": "^5.0.6",
45
45
  "webpack-merge": "^5.8.0"
@@ -5,6 +5,7 @@ default: &default
5
5
  source_entry_path: entrypoints
6
6
  public_output_path: packs
7
7
  cache_path: tmp/webpacker
8
+ webpack_loader: babel
8
9
 
9
10
  # Additional paths webpack should look up modules
10
11
  # ['app/assets', 'engine/foo/app/assets']
@@ -7,6 +7,7 @@ default: &default
7
7
  public_output_path: packs
8
8
  cache_path: tmp/webpacker
9
9
  webpack_compile_output: false
10
+ webpack_loader: babel
10
11
 
11
12
  # Additional paths webpack should look up modules
12
13
  # ['app/assets', 'engine/foo/app/assets']
data/yarn.lock CHANGED
@@ -2841,6 +2841,15 @@ loader-utils@^1.4.0:
2841
2841
  emojis-list "^3.0.0"
2842
2842
  json5 "^1.0.1"
2843
2843
 
2844
+ loader-utils@^2.0.0:
2845
+ version "2.0.2"
2846
+ resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.2.tgz#d6e3b4fb81870721ae4e0868ab11dd638368c129"
2847
+ integrity sha512-TM57VeHptv569d/GKh6TAYdzKblwDNiumOdkFnejjD0XwTH87K90w3O7AiJRqdQoXygvi1VQTJTLGhJl7WqA7A==
2848
+ dependencies:
2849
+ big.js "^5.2.2"
2850
+ emojis-list "^3.0.0"
2851
+ json5 "^2.1.2"
2852
+
2844
2853
  locate-path@^2.0.0:
2845
2854
  version "2.0.0"
2846
2855
  resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e"
@@ -3621,6 +3630,13 @@ supports-preserve-symlinks-flag@^1.0.0:
3621
3630
  resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09"
3622
3631
  integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==
3623
3632
 
3633
+ swc-loader@^0.1.15:
3634
+ version "0.1.15"
3635
+ resolved "https://registry.yarnpkg.com/swc-loader/-/swc-loader-0.1.15.tgz#cb9c630ccfbb46dabc5aebc5560cced658e32992"
3636
+ integrity sha512-cn1WPIeQJvXM4bbo3OwdEIapsQ4uUGOfyFj0h2+2+brT0k76DCGnZXDE2KmcqTd2JSQ+b61z2NPMib7eEwMYYw==
3637
+ dependencies:
3638
+ loader-utils "^2.0.0"
3639
+
3624
3640
  symbol-tree@^3.2.4:
3625
3641
  version "3.2.4"
3626
3642
  resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.4.tgz#430637d248ba77e078883951fb9aa0eed7c63fa2"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shakapacker
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0.rc.14
4
+ version: 6.1.0.beta.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-01-21 00:00:00.000000000 Z
13
+ date: 2022-01-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -143,6 +143,7 @@ files:
143
143
  - docs/deployment.md
144
144
  - docs/developing_webpacker.md
145
145
  - docs/troubleshooting.md
146
+ - docs/using_swc_loader.md
146
147
  - docs/v6_upgrade.md
147
148
  - gemfiles/Gemfile-rails-edge
148
149
  - gemfiles/Gemfile-rails.5.2.x
@@ -220,6 +221,8 @@ files:
220
221
  - package/rules/raw.js
221
222
  - package/rules/sass.js
222
223
  - package/rules/stylus.js
224
+ - package/rules/swc.js
225
+ - package/swc/index.js
223
226
  - package/utils/get_style_rule.js
224
227
  - package/utils/helpers.js
225
228
  - rakelib/release.rake
@@ -269,7 +272,7 @@ homepage: https://github.com/shakacode/shakapacker
269
272
  licenses:
270
273
  - MIT
271
274
  metadata:
272
- source_code_uri: https://github.com/shakacode/shakapacker/tree/v6.0.0-rc.14
275
+ source_code_uri: https://github.com/shakacode/shakapacker/tree/v6.1.0.beta.0
273
276
  post_install_message:
274
277
  rdoc_options: []
275
278
  require_paths: