shakapacker 6.0.0 → 6.1.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: 8cac929d3e522c5f709b866a582551b00ffd56579f8731e07ed80a5a7b76bb90
4
- data.tar.gz: eaca2ec65c2b9fe16bd50aaa31902fa738448dbaa599cb3db42876d869a23a1c
3
+ metadata.gz: 1ed9a099f6d2af01d86664505f7a8cd13196d666beb526d5f7a360fb1473ce77
4
+ data.tar.gz: 2e87b7d185a54fbbee7f717507c58a77093cc23eaaab500f28ccebde3560c738
5
5
  SHA512:
6
- metadata.gz: 2cc8e0085ffc940e94ad73fd0ff5cff9adca71915eff47df30ea53d55a12853d3fc63dcb055456011f65c9e869bfbfd16c4299ac864d3dee60b977dd77e38587
7
- data.tar.gz: 5a3ff00245fdd839eb843492fb948047dffaf07cd7e4f3d92d4c5e1ac1bd3ba3c94624050a185af5f9d9e580e4b949a682f4333bee837c724c7f83d0412d390b
6
+ metadata.gz: ad534bf595ba05e3b4a2bb1eb44132c2eb0762b61de98390745940043873878d70cc1e391f4a8e51432c51e433463a9ca01f0fb6a205e990e1cf77daa0c68214
7
+ data.tar.gz: a53836485058bf673e8fecd3db4f22660dd104fef0c71be543bfada101c0cce20ad83706f9ceb8e50057cce79d6e24a921d8bf8965a87a32e3f24d66d5773a17
@@ -20,11 +20,8 @@ jobs:
20
20
  node-version: ${{ matrix.node }}
21
21
  cache: yarn
22
22
 
23
- - name: Install yarn maybe
24
- run: which yarn || npm install -g yarn
25
-
26
23
  - name: Install dependencies
27
- run: yarn --frozen-lockfile
24
+ run: yarn --frozen-lockfile --non-interactive --prefer-offline
28
25
 
29
26
  - name: Jest Specs
30
27
  run: yarn test
@@ -3,13 +3,12 @@ name: JS lint
3
3
  on: [push, pull_request]
4
4
 
5
5
  jobs:
6
- js-lint:
6
+ lint:
7
7
  name: JS Lint
8
-
9
8
  strategy:
10
9
  matrix:
11
10
  os: [ubuntu-latest]
12
- node: [14]
11
+ node: [12.x, 14.x, 16.x]
13
12
 
14
13
  runs-on: ${{ matrix.os }}
15
14
 
@@ -21,11 +20,8 @@ jobs:
21
20
  node-version: ${{ matrix.node }}
22
21
  cache: yarn
23
22
 
24
- - name: Install yarn maybe
25
- run: which yarn || npm install -g yarn
26
-
27
23
  - name: Install dependencies
28
- run: yarn --frozen-lockfile
24
+ run: yarn --frozen-lockfile --non-interactive --prefer-offline
29
25
 
30
26
  - name: Lint
31
27
  run: yarn lint
@@ -6,34 +6,17 @@ jobs:
6
6
  rubocop:
7
7
  name: Rubocop
8
8
  runs-on: ${{ matrix.os }}
9
- env:
10
- BUNDLE_JOBS: 4
11
- BUNDLE_RETRY: 3
12
9
  strategy:
13
10
  matrix:
14
11
  os: [ubuntu-latest]
15
- ruby: [
16
- 2.7
17
- ]
12
+ ruby: ['2.7', '3.0']
18
13
 
19
14
  steps:
20
15
  - uses: actions/checkout@v2
21
- - uses: actions/cache@v2
22
- with:
23
- path: /home/runner/bundle
24
- key: bundle-use-ruby-gems-${{ hashFiles('**/Gemfile.lock') }}
25
- restore-keys: |
26
- bundle-use-ruby-gems-
27
-
28
16
  - uses: ruby/setup-ruby@v1
29
17
  with:
30
18
  ruby-version: ${{ matrix.ruby }}
19
+ bundler-cache: true
31
20
 
32
- - name: Bundle install
33
- run: |
34
- gem install bundler -v 2.1.4
35
- bundle config path /home/runner/bundle
36
- bundle install
37
-
38
- - name: Ruby linter
21
+ - name: Ruby rubocop
39
22
  run: bundle exec rubocop
@@ -6,43 +6,36 @@ jobs:
6
6
  test:
7
7
  name: Ruby specs
8
8
  runs-on: ${{ matrix.os }}
9
- continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' || matrix.experimental }}
10
9
  strategy:
11
- fail-fast: false
12
10
  matrix:
13
11
  os: [ubuntu-latest]
14
- ruby:
15
- - 2.7
16
- - "3.0"
12
+ ruby: ['2.6', '2.7', '3.0']
17
13
  gemfile:
18
14
  - gemfiles/Gemfile-rails.5.2.x
19
15
  - gemfiles/Gemfile-rails.6.0.x
20
16
  - gemfiles/Gemfile-rails.6.1.x
17
+ - gemfiles/Gemfile-rails.7.0.x
18
+ - gemfiles/Gemfile-rails-edge
21
19
  exclude:
22
- - ruby: 2.5
23
- gemfile: gemfiles/Gemfile-rails.6.1.x
24
- - ruby: "3.0"
25
- gemfile: gemfiles/Gemfile-rails.5.2.x
26
- experimental: [false]
27
- include:
28
- - ruby: 2.7
20
+ - ruby: 2.6
29
21
  os: ubuntu-latest
30
- gemfile: gemfiles/Gemfile-rails-edge
31
- experimental: true
32
- - ruby: "3.0"
22
+ gemfile: gemfiles/Gemfile-rails.7.0.x
23
+ - ruby: 2.6
33
24
  os: ubuntu-latest
34
25
  gemfile: gemfiles/Gemfile-rails-edge
35
- experimental: true
26
+ - ruby: 3.0
27
+ os: ubuntu-latest
28
+ gemfile: gemfiles/Gemfile-rails.5.2.x
36
29
 
37
30
  env:
38
31
  BUNDLE_GEMFILE: ${{ matrix.gemfile }}
32
+
39
33
  steps:
40
34
  - uses: actions/checkout@v2
41
-
42
35
  - uses: ruby/setup-ruby@v1
43
36
  with:
44
37
  ruby-version: ${{ matrix.ruby }}
45
- bundler-cache: true # Run "bundle install", and cache the result automatically.
38
+ bundler-cache: true
46
39
 
47
40
  - name: Ruby specs
48
- run: bundle exec rake
41
+ run: bundle exec rake test
data/.node-version CHANGED
@@ -1 +1 @@
1
- 16.7.0
1
+ 16
data/.rubocop.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  require: rubocop-performance
2
2
  AllCops:
3
- TargetRubyVersion: 2.7
4
3
  # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
5
4
  # to ignore them, so only the ones explicitly set in this file are enabled.
6
5
  DisabledByDefault: true
data/CHANGELOG.md CHANGED
@@ -1,23 +1,38 @@
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
- * Please see [UPGRADE GUIDE](./docs/v6_upgrade.md).
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
+ * Please see [v6 Upgrade Guide](./docs/v6_upgrade.md) to go from version prior to v6.
3
3
 
4
4
  ## Versions
5
- ### [Unreleased]
5
+ ## [Unreleased]
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
+
10
+ ## [v6.1.0] - February 4, 2020
11
+ ### Added
12
+ - Support for SWC loader. [PR 29](https://github.com/shakacode/shakapacker/pull/29) by [tomdracz](https://github.com/tomdracz).
13
+
14
+ ### Fixed
15
+ - Static asset subdirectories are retained after compilation, matching Webpacker v5 behaviour. [PR 47](https://github.com/shakacode/shakapacker/pull/47) by [tomdracz](https://github.com/tomdracz). Fixes issues [rails/webpacker#2956](https://github.com/rails/webpacker/issues/2956) which broke in [rails/webpacker#2802](https://github.com/rails/webpacker/pull/2802).
16
+
17
+ ## [v6.0.2] - January 25, 2022
18
+ ### Improved
19
+ - Fix incorrect command name in warning. [PR 33](https://github.com/shakacode/shakapacker/pull/33) by [tricknotes](https://github.com/tricknotes).
20
+
21
+ ## [v6.0.1] - January 24, 2022
22
+ ### Improved
23
+ - 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).
24
+
25
+ ## [v6.0.0 changes from v6.0.0.rc.6] - January 22, 2022
10
26
 
11
27
  ### 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].
28
+ - 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).
29
+ - 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).
30
+ - Remove pnp-webpack-plugin. [PR 21](https://github.com/shakacode/shakapacker/pull/21) by [tomdracz](https://github.com/tomdracz).
15
31
 
16
- ## [v6.0.0.rc.13 changes from v6.0.0.rc.6]
17
32
 
18
33
  ### Merged from rails/webpacker
19
34
 
20
- - Make watched_files_digest thread safe. [rails/webpacker #3233](https://github.com/rails/webpacker/pull/3233)
35
+ - Make watched_files_digest thread safe. [rails/webpacker #3233](https://github.com/rails/webpacker/pull/3233)
21
36
  - Use single webpack config webpack.config.js. [rails/webpacker #3240](https://github.com/rails/webpacker/pull/3240)
22
37
  - Switch to peer dependencies. [rails/webpacker #3234](https://github.com/rails/webpacker/pull/3234)
23
38
 
@@ -51,8 +66,12 @@ Changes since last non-beta release.
51
66
  - Splitchunks enabled by default
52
67
  - CSS extraction enabled by default, except when devServer is configured and running
53
68
 
69
+ ## v5.4.3 and prior changes from rails/webpacker
70
+ See [CHANGELOG.md in rails/webpacker (up to v5.4.3)](https://github.com/rails/webpacker/blob/master/CHANGELOG.md)
54
71
 
55
- [Unreleased]: https://github.com/shakacode/shakapacker/compare/6.0.0-rc.14...master
56
- [v6.0.0.rc.14]: https://github.com/shakacode/shakapacker/compare/v6.0.0-rc.13...v6.0.0-rc.14
57
- [v6.0.0.rc.13 changes from v6.0.0.rc.6]: https://github.com/shakacode/shakapacker/compare/aba79635e6ff6562ec04d3c446d57ef19a5fef7d...v6.0.0-rc.13
72
+ [Unreleased]: https://github.com/shakacode/shakapacker/compare/v6.1.0...master
73
+ [v6.1.0]: https://github.com/shakacode/shakapacker/compare/v6.0.2...v6.1.0
74
+ [v6.0.2]: https://github.com/shakacode/shakapacker/compare/v6.0.1...v6.0.2
75
+ [v6.0.1]: https://github.com/shakacode/shakapacker/compare/v6.0.0...v6.0.1
76
+ [v6.0.0 changes from v6.0.0.rc.6]: https://github.com/shakacode/shakapacker/compare/aba79635e6ff6562ec04d3c446d57ef19a5fef7d...v6.0.0
58
77
  [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.1.0.beta.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,9 @@
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)._
3
+ _Official, actively maintained successor to [rails/webpacker](https://github.com/rails/webpacker). Internal naming for `shakapacker` will continue to use `webpacker` where possible for v6. ShakaCode stands behind long-term maintainence and development of this project for the Rails community._
4
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
5
 
6
+ * See [V6 Upgrade](./docs/v6_upgrade.md) for upgrading from v5 or prior v6 releases.
9
7
 
10
8
  [![Ruby specs](https://github.com/shakacode/shakapacker/workflows/Ruby%20specs/badge.svg)](https://github.com/shakacode/shakapacker/actions)
11
9
  [![Jest specs](https://github.com/shakacode/shakapacker/workflows/Jest%20specs/badge.svg)](https://github.com/shakacode/shakapacker/actions)
@@ -14,12 +12,14 @@ _Official, actively maintained fork of [rails/webpacker](https://github.com/rail
14
12
 
15
13
  [![node.js](https://img.shields.io/badge/node-%3E%3D%2012.0.0-brightgreen.svg)](https://www.npmjs.com/package/shakapacker)
16
14
  [![Gem](https://img.shields.io/gem/v/shakapacker.svg)](https://rubygems.org/gems/shakapacker)
15
+ [![npm version](https://badge.fury.io/js/shakapacker.svg)](https://badge.fury.io/js/shakapacker)
17
16
 
18
- Webpacker makes it easy to use the JavaScript pre-processor and bundler
19
- [Webpack v5](https://webpack.js.org/)
17
+ Webpacker makes it easy to use the JavaScript pre-processor and bundler [Webpack v5+](https://webpack.js.org/)
20
18
  to manage application-like JavaScript in Rails. It can coexist with the asset pipeline,
21
19
  leaving Webpack responsible solely for app-like JavaScript, or it can be used exclusively, making it also responsible for images, fonts, and CSS.
22
20
 
21
+ Check out 6.1.0.beta.0 for [SWC](https://swc.rs/) support! It's way faster than babel.
22
+
23
23
  See a comparison of [webpacker with jsbundling-rails](https://github.com/rails/jsbundling-rails/blob/main/docs/comparison_with_webpacker.md).
24
24
 
25
25
  Discussion forums to discuss debugging and troubleshooting tips. Please open issues for bugs and feature requests:
@@ -35,16 +35,17 @@ Discussion forums to discuss debugging and troubleshooting tips. Please open iss
35
35
  - [Features](#features)
36
36
  - [Optional support](#optional-support)
37
37
  - [Installation](#installation)
38
- - [Rails v6](#rails-v6)
39
- - [Rails v7](#rails-v7)
40
- - [Manual Installation Steps](#manual-installation-steps)
38
+ - [Rails v6+](#rails-v6)
41
39
  - [Note for Sprockets usage](#note-for-sprockets-usage)
40
+ - [Note for Yarn v2 usage](#note-for-yarn-v2-usage)
42
41
  - [Usage](#usage)
43
- - [Defer for `javascript_pack_tag`](#defer-for-javascript_pack_tag)
44
- - [Server-Side Rendering (SSR)](#server-side-rendering-ssr)
42
+ - [View Helpers](#view-helpers)
43
+ - [Defer for `javascript_pack_tag`](#defer-for-javascript_pack_tag)
44
+ - [Server-Side Rendering (SSR)](#server-side-rendering-ssr)
45
45
  - [Development](#development)
46
46
  - [Webpack Configuration](#webpack-configuration)
47
47
  - [Babel configuration](#babel-configuration)
48
+ - [SWC configuration](#swc-configuration)
48
49
  - [Integrations](#integrations)
49
50
  - [React](#react)
50
51
  - [Typescript](#typescript)
@@ -58,7 +59,7 @@ Discussion forums to discuss debugging and troubleshooting tips. Please open iss
58
59
  - [Other frameworks](#other-frameworks)
59
60
  - [Custom Rails environments](#custom-rails-environments)
60
61
  - [Upgrading](#upgrading)
61
- - [Paths](#paths)
62
+ - [Paths](#paths)
62
63
  - [Additional paths](#additional-paths)
63
64
  - [Deployment](#deployment)
64
65
  - [Example Apps](#example-apps)
@@ -70,63 +71,46 @@ Discussion forums to discuss debugging and troubleshooting tips. Please open iss
70
71
 
71
72
  ## Prerequisites
72
73
 
73
- - Ruby 2.7+
74
+ - Ruby 2.6+
74
75
  - Rails 5.2+
75
76
  - Node.js 12.13.0+ || 14+
76
77
  - Yarn
77
78
 
78
79
  ## Features
79
-
80
+ - Rails view helpers that fully support webpack output
81
+ - Convenient but not required webpack configuration. The only requirement is that your webpack configuration create a manifest.
82
+ - HMR with the webpack-dev-server, such as for hot-reloading for React!
83
+ - Automatic code splitting using multiple entry points to optimize JavaScript downloads
80
84
  - [Webpack v5](https://webpack.js.org/)
81
85
  - ES6 with [babel](https://babeljs.io/)
82
- - Automatic code splitting using multiple entry points
83
86
  - Asset compression, source-maps, and minification
84
87
  - CDN support
85
- - Rails view helpers
86
- - Extensible and configurable
88
+ - Extensible and configurable. For example, all major dependencies are specified as peers, so you can upgrade easily.
87
89
 
88
90
  ### Optional support
89
-
90
- _requires extra packages to be installed_
91
-
92
- - Stylesheets - Sass, Less, Stylus and Css, PostCSS
93
- - CoffeeScript
94
- - TypeScript
95
- - React
91
+ _Requires extra packages to be installed._
92
+ - React
93
+ - TypeScript
94
+ - Stylesheets - Sass, Less, Stylus and Css, PostCSS
95
+ - CoffeeScript
96
96
 
97
97
  ## Installation
98
98
 
99
- ### Rails v6
100
- With Rails v6, [rails/webpacker v5](https://github.com/rails/webpacker/tree/5-x-stable) is installed by default:
101
- ```bash
102
- rails new myapp
103
- ```
104
99
 
105
- If you wish to migrate to Shakapacker, please follow the [V6 Upgrade](./docs/v6_upgrade.md) instructions.
106
-
107
- Alternatively, you can skip the default webpacker installation and then follow the [Manual Installation Steps](#manual-installation-steps) below.
100
+ ### Rails v6+
108
101
 
102
+ With Rails v6+, skip JavaScript for a new app and follow below Manual Installation Steps to manually add the `shakapacker` gem to your Gemfile.
109
103
  ```bash
110
104
  rails new myapp --skip-javascript
111
105
  ```
112
106
 
113
- ### Rails v7
114
-
115
- With Rails v7, skip JavaScript for a new app and follow below Manual Installation Steps to manually add the `shakapacker` gem to your Gemfile.
116
- ```bash
117
- rails new myapp --skip-javascript
118
- ```
107
+ _Note, Rails 6 installs the older v5 version of webpacker unless you specify `--skip-javascript`._
119
108
 
120
- ### Manual Installation Steps
121
109
  Update your `Gemfile`:
122
110
 
123
111
  ```ruby
124
112
  # Gemfile
125
113
  gem 'shakapacker', '~> 6.0'
126
-
127
- # OR if you prefer to use master
128
- gem 'shakapacker', git: 'https://github.com/shakacode/shakapacker.git'
129
- yarn add https://github.com/shakacode/shakapacker.git
130
114
  ```
131
115
 
132
116
  Then running the following to install Webpacker:
@@ -162,8 +146,16 @@ In order to enable this, make sure you add `node_modules` to the asset load path
162
146
  Rails.application.config.assets.paths << Rails.root.join('node_modules')
163
147
  ```
164
148
 
149
+ ### Note for Yarn v2 usage
150
+
151
+ If you are using Yarn v2 (berry), please note that PnP modules are not supported.
152
+
153
+ In order to use Shakapacker with Yarn v2, make sure you set `nodeLinker: node-modules` in your `.yarnrc.yml` file as per the [Yarn docs](https://yarnpkg.com/getting-started/migration#step-by-step) to opt out of Plug'n'Play behaviour.
154
+
165
155
  ## Usage
166
156
 
157
+ ### View Helpers
158
+
167
159
  Once installed, you can start writing modern ES6-flavored JavaScript apps right away:
168
160
 
169
161
  ```yml
@@ -201,7 +193,7 @@ The result looks like this:
201
193
  <script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload" defer></script>
202
194
  ```
203
195
 
204
- **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
+ **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.
205
197
 
206
198
  ```erb
207
199
  <%# DO %>
@@ -243,10 +235,10 @@ If you want to use images in your stylesheets:
243
235
  background-image: url('../images/logo.svg')
244
236
  }
245
237
  ```
246
- ##### Defer for `javascript_pack_tag`
238
+ ### Defer for `javascript_pack_tag`
247
239
  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`.
248
240
 
249
- #### Server-Side Rendering (SSR)
241
+ ### Server-Side Rendering (SSR)
250
242
 
251
243
  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.
252
244
 
@@ -307,11 +299,33 @@ end
307
299
 
308
300
  ### Webpack Configuration
309
301
 
310
- Webpacker gives you a default configuration file for your test, development, and production environments in `config/webpack/*.js`.
302
+ 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:
311
303
 
312
- 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.
304
+ 1. Your output files go the right directory
305
+ 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!
313
306
 
314
- Here is how you can modify webpack configuration:
307
+ 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`:
308
+
309
+ ```js
310
+ // use the new NPM package name, `shakapacker`.
311
+ // merge is webpack-merge from https://github.com/survivejs/webpack-merge
312
+ const { webpackConfig: baseWebpackConfig, merge } = require('shakapacker')
313
+
314
+ const options = {
315
+ resolve: {
316
+ extensions: ['.css', '.ts', '.tsx']
317
+ }
318
+ }
319
+
320
+ // Copy the object using merge b/c the baseClientWebpackConfig is a mutable global
321
+ // If you want to use this object for client and server rendering configurations,
322
+ // havaing a new object is essential.
323
+ module.exports = merge({}, baseWebpackConfig, options)
324
+ ```
325
+
326
+ 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)
327
+
328
+ 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.
315
329
 
316
330
  You might add separate files to keep your code more organized.
317
331
 
@@ -334,6 +348,7 @@ Then `require` this file in your `config/webpack/webpack.config.js`:
334
348
 
335
349
  ```js
336
350
  // config/webpack/webpack.config.js
351
+ // use the new NPM package name, `shakapacker`.
337
352
  const { webpackConfig, merge } = require('shakapacker')
338
353
  const customConfig = require('./custom')
339
354
 
@@ -355,7 +370,7 @@ console.log(JSON.stringify(webpackConfig, undefined, 2))
355
370
 
356
371
  ### Babel configuration
357
372
 
358
- By default, you will find the Webpacker preset in your `package.json`.
373
+ By default, you will find the Webpacker preset in your `package.json`. Note, you need to use the new NPM package name, `shakapacker`.
359
374
 
360
375
  ```json
361
376
  "babel": {
@@ -367,6 +382,12 @@ By default, you will find the Webpacker preset in your `package.json`.
367
382
 
368
383
  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).
369
384
 
385
+ ### SWC configuration
386
+
387
+ You can try out experimental integration with the SWC loader. You can read more at [SWC usage docs](./docs/using_swc_loader.md).
388
+
389
+ 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.
390
+
370
391
  ### Integrations
371
392
 
372
393
  Webpacker out of the box supports JS and static assets (fonts, images etc.) compilation. To enable support for CoffeeScript or TypeScript install relevant packages:
@@ -542,7 +563,6 @@ const vueConfig = require('./rules/vue')
542
563
  module.exports = merge(vueConfig, webpackConfig)
543
564
  ```
544
565
 
545
-
546
566
  ### Custom Rails environments
547
567
 
548
568
  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.
@@ -614,7 +634,7 @@ yarn add shakapacker@next
614
634
 
615
635
  Also, consult the [CHANGELOG](./CHANGELOG.md) for additional upgrade links.
616
636
 
617
- ## Paths
637
+ ### Paths
618
638
 
619
639
  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.
620
640
 
@@ -678,10 +698,9 @@ If you are using a CDN setup, webpacker will use the configured [asset host](htt
678
698
 
679
699
  See the doc page for [Troubleshooting](./docs/troubleshooting.md).
680
700
 
681
-
682
701
  ## Contributing
683
702
 
684
- We encourage you to contribute to Webpacker! See [CONTRIBUTING](CONTRIBUTING.md) for guidelines about how to proceed.
703
+ 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).
685
704
 
686
705
  ## License
687
706
 
@@ -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,153 @@
1
+ # Using SWC Loader
2
+
3
+ :warning: This feature is currently experimental. The configuration and API are subject to change during the beta release cycle.
4
+
5
+ If you face any issues, please report at https://github.com/shakacode/shakapacker/issues.
6
+
7
+ ## About SWC
8
+
9
+ [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!
10
+
11
+ 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.
12
+
13
+ For comparison between SWC and Babel, see the docs at https://swc.rs/docs/migrating-from-babel.
14
+
15
+ ## Switching your Shakapacker project to SWC
16
+
17
+ In order to use SWC as your compiler today. You need to do two things:
18
+
19
+ 1. Make sure you've installed `@swc/core` and `swc-loader` packages.
20
+
21
+ ```
22
+ yarn add -D @swc/core swc-loader
23
+ ```
24
+
25
+ 2. Add or change `webpacker_loader` value in your default `webpacker.yml` config to `swc`
26
+ The default configuration of babel is done by using `package.json` to use the file within the `shakapacker` package.
27
+
28
+ ```yml
29
+ default: &default
30
+ source_path: app/javascript
31
+ source_entry_path: /
32
+ public_root_path: public
33
+ public_output_path: packs
34
+ cache_path: tmp/webpacker
35
+ webpack_compile_output: true
36
+
37
+ # Additional paths webpack should look up modules
38
+ # ['app/assets', 'engine/foo/app/assets']
39
+ additional_paths: []
40
+
41
+ # Reload manifest.json on all requests so we reload latest compiled packs
42
+ cache_manifest: false
43
+
44
+ # Select loader to use, available options are 'babel' (default) or 'swc'
45
+ webpack_loader: 'swc'
46
+ ```
47
+
48
+ ## Usage
49
+
50
+ ### React
51
+
52
+ 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.
53
+
54
+ ### Typescript
55
+
56
+ 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.
57
+
58
+ 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.
59
+
60
+ ## Customizing loader options
61
+
62
+ You can see the default loader options at [swc/index.js](../package/swc/index.js).
63
+
64
+ 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.
65
+
66
+ 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.
67
+
68
+ 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).
69
+
70
+ See some examples below of potential `config/swc.config.js`.
71
+
72
+ ### Example: Enabling top level await and decorators
73
+
74
+
75
+ ```js
76
+ const customConfig = {
77
+ options: {
78
+ jsc: {
79
+ parser: {
80
+ topLevelAwait: true,
81
+ decorators: true
82
+ }
83
+ }
84
+ }
85
+ }
86
+
87
+ module.exports = customConfig
88
+ ```
89
+
90
+ ### Example: Matching existing `@babel/present-env` config
91
+
92
+ ```js
93
+ const { env } = require('shakapacker')
94
+
95
+ const customConfig = {
96
+ options: {
97
+ jsc: {
98
+ transform: {
99
+ react: {
100
+ development: env.isDevelopment,
101
+ useBuiltins: true
102
+ }
103
+ }
104
+ }
105
+ }
106
+ }
107
+
108
+ module.exports = customConfig
109
+ ```
110
+
111
+ ### Example: Enabling React Fast Refresh
112
+
113
+ :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.
114
+
115
+
116
+ ```js
117
+ const { env } = require('shakapacker')
118
+
119
+ const customConfig = {
120
+ options: {
121
+ jsc: {
122
+ transform: {
123
+ react: {
124
+ refresh: env.isDevelopment && env.runningWebpackDevServer
125
+ }
126
+ }
127
+ }
128
+ }
129
+ }
130
+
131
+ module.exports = customConfig
132
+ ```
133
+
134
+ ### Example: Adding browserslist config
135
+
136
+ ```js
137
+
138
+ const customConfig = {
139
+ options: {
140
+ env: {
141
+ targets: '> 0.25%, not dead'
142
+ }
143
+ }
144
+ }
145
+
146
+ module.exports = customConfig
147
+ ```
148
+
149
+
150
+ ## Known limitations
151
+
152
+ - `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.
153
+ - 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
@@ -1,25 +1,45 @@
1
- # Upgrading from Webpacker 5 to 6
1
+ # Upgrading from Webpacker v5 to Shakapacker v6
2
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.
3
+ There are several substantial changes in Shakapacker v6 that you need to manually account for when coming from Webpacker 5. This guide will help you through it.
4
4
 
5
- ## Webpacker has become a slimmer wrapper around Webpack
5
+ ## Webpacker/Shakapacker has become a slimmer wrapper around Webpack
6
6
 
7
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/shakacode/shakapacker#integrations) for more information.
8
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.
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. Additionally, all major dependencies, like `webpack` and `babel` are now **peer** dependencies, so you are free to upgrade those.
10
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/shakacode/shakapacker#other-frameworks) and scroll to the bottom for [more examples](#examples-of-v5-to-v6).
11
+ While you have to configure integration with frameworks yourself, [`webpack-merge`](https://github.com/survivejs/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
- ## 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).
13
+ ## webpacker v6.0.0.rc.6 to shakapacker v6.0.0
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
- ### Update
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`
16
+ ### Update Steps to v6.0.0 from v6.0.0.rc.6
17
+ _If you're on webpacker v5, follow below steps to get to v6.0.0.rc.6 first._
18
+
19
+ 1. Change the gem name from `webpacker` to `shakapacker` and the NPM package from `@rails/webpacker` to `shakapacker`.
20
+ 1. Install the 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
21
  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.
22
+ 1. Update your webpack config for a single config file, `config/webpack/webpack.config.js`. If you want to use the prior style of having a separate file for each NODE_ENV, you can use this shim for `config/webpack/webpack.config.js`:
23
+ ```js
24
+ const { env, webpackConfig } = require('shakapacker')
25
+ const { existsSync } = require('fs')
26
+ const { resolve } = require('path')
27
+
28
+ const envSpecificConfig = () => {
29
+ const path = resolve(__dirname, `${env.nodeEnv}.js`)
30
+ if (existsSync(path)) {
31
+ console.log(`Loading ENV specific webpack configuration file ${path}`)
32
+ return require(path)
33
+ } else {
34
+ return webpackConfig
35
+ }
36
+ }
37
+
38
+ module.exports = envSpecificConfig()
39
+ ```
40
+ 1. Update `babel.config.js` if you need JSX support. See [Customizing Babel Config](./customizing_babel_config.md)
21
41
 
22
- ## How to upgrade to Webpacker v6 from v5
42
+ ## How to upgrade to Webpacker v6.0.0.rc.6 from v5
23
43
  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.
24
44
 
25
45
  1. Consider changing from the v5 default for `source_entry_path` in `webpacker.yml`.
@@ -159,7 +179,7 @@ See example migration, [PR 27](https://github.com/shakacode/react_on_rails_tutor
159
179
 
160
180
  1. Update any scripts that called `/bin/webpack` or `bin/webpack-dev-server` to `/bin/webpacker` or `bin/webpacker-dev-server`
161
181
 
162
- 1. Try your app!
182
+ 1. Now, follow the steps above to get to shakapacker v6 from webpacker v6.0.0.rc.6[
163
183
 
164
184
  ## Examples of v5 to v6
165
185
 
@@ -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", '~>7.0.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"
@@ -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".freeze
3
+ VERSION = "6.1.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
+ }))
@@ -1,3 +1,6 @@
1
+ const { dirname, join } = require('path')
2
+ const { source_path: sourcePath } = require('../config')
3
+
1
4
  module.exports = {
2
5
  test: [
3
6
  /\.bmp$/,
@@ -18,6 +21,14 @@ module.exports = {
18
21
  exclude: [/\.(js|mjs|jsx|ts|tsx)$/],
19
22
  type: 'asset/resource',
20
23
  generator: {
21
- filename: 'static/[name]-[hash][ext][query]'
24
+ filename: (pathData) => {
25
+ const folders = dirname(pathData.filename)
26
+ .replace(`${sourcePath}/`, '')
27
+ .split('/')
28
+ .slice(1)
29
+
30
+ const foldersWithStatic = join('static', ...folders)
31
+ return `${foldersWithStatic}/[name]-[hash][ext][query]`
32
+ }
22
33
  }
23
34
  }
@@ -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",
3
+ "version": "6.1.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/webpacker.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  "source_code_uri" => "https://github.com/shakacode/shakapacker/tree/v#{npm_version}",
16
16
  }
17
17
 
18
- s.required_ruby_version = ">= 2.7.0"
18
+ s.required_ruby_version = ">= 2.6.0"
19
19
 
20
20
  s.add_dependency "activesupport", ">= 5.2"
21
21
  s.add_dependency "railties", ">= 5.2"
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
4
+ version: 6.1.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-23 00:00:00.000000000 Z
13
+ date: 2022-02-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -143,11 +143,13 @@ 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
149
150
  - gemfiles/Gemfile-rails.6.0.x
150
151
  - gemfiles/Gemfile-rails.6.1.x
152
+ - gemfiles/Gemfile-rails.7.0.x
151
153
  - lib/install/application.js
152
154
  - lib/install/bin/webpacker
153
155
  - lib/install/bin/webpacker-dev-server
@@ -220,6 +222,8 @@ files:
220
222
  - package/rules/raw.js
221
223
  - package/rules/sass.js
222
224
  - package/rules/stylus.js
225
+ - package/rules/swc.js
226
+ - package/swc/index.js
223
227
  - package/utils/get_style_rule.js
224
228
  - package/utils/helpers.js
225
229
  - rakelib/release.rake
@@ -269,7 +273,7 @@ homepage: https://github.com/shakacode/shakapacker
269
273
  licenses:
270
274
  - MIT
271
275
  metadata:
272
- source_code_uri: https://github.com/shakacode/shakapacker/tree/v6.0.0
276
+ source_code_uri: https://github.com/shakacode/shakapacker/tree/v6.1.0
273
277
  post_install_message:
274
278
  rdoc_options: []
275
279
  require_paths:
@@ -278,7 +282,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
278
282
  requirements:
279
283
  - - ">="
280
284
  - !ruby/object:Gem::Version
281
- version: 2.7.0
285
+ version: 2.6.0
282
286
  required_rubygems_version: !ruby/object:Gem::Requirement
283
287
  requirements:
284
288
  - - ">="