shakapacker 6.1.0 → 6.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +1 -1
- data/.github/ISSUE_TEMPLATE/feature-request.md +1 -1
- data/.node-version +1 -1
- data/CHANGELOG.md +26 -2
- data/Gemfile.lock +1 -1
- data/README.md +42 -16
- data/docs/customizing_babel_config.md +2 -0
- data/docs/deployment.md +2 -2
- data/docs/style_loader_vs_mini_css.md +48 -0
- data/docs/troubleshooting.md +18 -0
- data/docs/using_esbuild_loader.md +128 -0
- data/docs/using_swc_loader.md +2 -2
- data/docs/v6_upgrade.md +72 -74
- data/lib/install/config/webpacker.yml +15 -1
- data/lib/install/template.rb +2 -2
- data/lib/webpacker/commands.rb +2 -2
- data/lib/webpacker/compiler.rb +2 -2
- data/lib/webpacker/configuration.rb +16 -4
- data/lib/webpacker/dev_server.rb +11 -2
- data/lib/webpacker/helper.rb +0 -7
- data/lib/webpacker/instance.rb +1 -1
- data/lib/webpacker/manifest.rb +3 -3
- data/lib/webpacker/railtie.rb +7 -0
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/version_checker.rb +152 -0
- data/package/__tests__/config.js +11 -0
- data/package/config.js +6 -0
- data/package/environments/base.js +1 -1
- data/package/esbuild/index.js +40 -0
- data/package/inliningCss.js +1 -1
- data/package/rules/__tests__/file.js +35 -0
- data/package/rules/__tests__/index.js +11 -0
- data/package/rules/__tests__/raw.js +18 -0
- data/package/rules/esbuild.js +23 -0
- data/package/rules/file.js +2 -17
- data/package/rules/index.js +1 -0
- data/package/rules/raw.js +2 -2
- data/package/swc/index.js +3 -3
- data/package.json +2 -1
- data/test/configuration_test.rb +26 -0
- data/test/fixtures/beta_package.json +13 -0
- data/test/fixtures/git_url_package.json +13 -0
- data/test/fixtures/github_url_package.json +13 -0
- data/test/fixtures/normal_package.json +13 -0
- data/test/fixtures/relative_path_package.json +13 -0
- data/test/fixtures/semver_caret_package.json +13 -0
- data/test/fixtures/semver_tilde_package.json +13 -0
- data/test/fixtures/without_package.json +13 -0
- data/test/helper_test.rb +12 -12
- data/test/test_app/config/webpacker.yml +4 -0
- data/test/test_app/config/webpacker_manifest_path.yml +80 -0
- data/test/version_checker_test.rb +271 -0
- data/test/webpacker_test.rb +15 -0
- data/yarn.lock +145 -1
- metadata +31 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd1ab6b39f1ae6a30d35edb3ce88f505aa982751ce798cbc02a7ff1e6d1b1fd4
|
4
|
+
data.tar.gz: 389b31b8cd3e24b9cbe39e7fef24257037ec3195229d2fae9d35146f82f6c594
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44e0784025695f8d6686c9c4fecd551da50f4c47c48939abe0c93b55e6e6f9407b68fba15e88c7dfe2169e981248e31c93e240fa1be342f58ffa368a1a6dc4ac
|
7
|
+
data.tar.gz: 8b51a5b4c2870bea948801afe3db35f24bf79bdfb543f098e63bbdc62dd3be1a23241dc8ebccefceb0a92d0c51e50bc0d75553e1eb9c93f0c362ae7a91ea3b47
|
@@ -7,7 +7,7 @@ assignees: ''
|
|
7
7
|
|
8
8
|
---
|
9
9
|
|
10
|
-
A bug is a crash or incorrect behavior. If you have a debugging or troubleshooting question, please open a discussion on
|
10
|
+
A bug is a crash or incorrect behavior. If you have a debugging or troubleshooting question, please open a discussion on [Discussions Tab](https://github.com/shakacode/shakapacker/discussions).
|
11
11
|
|
12
12
|
Ruby version:
|
13
13
|
Rails version:
|
@@ -7,7 +7,7 @@ assignees: ''
|
|
7
7
|
|
8
8
|
---
|
9
9
|
|
10
|
-
A feature request
|
10
|
+
A feature request describes a suggested improvement. If you have a debugging or troubleshooting question, please open a discussion on the [Discussions tab](https://github.com/shakacode/shakapacker/discussions).
|
11
11
|
|
12
12
|
Ruby version:
|
13
13
|
Rails version:
|
data/.node-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
16
|
1
|
+
16.14.0
|
data/CHANGELOG.md
CHANGED
@@ -7,7 +7,29 @@ Changes since last non-beta release.
|
|
7
7
|
|
8
8
|
*Please add entries here for your pull requests that are not yet released.*
|
9
9
|
|
10
|
-
## [v6.1
|
10
|
+
## [v6.2.1] - April 15, 2022
|
11
|
+
### Fixed
|
12
|
+
- Put back config.public_manifest_path, removed in 6.2.0 in PR 78. [PR 104](https://github.com/shakacode/shakapacker/pull/104) by [justin808](https://github.com/justin808).
|
13
|
+
|
14
|
+
## [v6.2.0] - March 22, 2022
|
15
|
+
|
16
|
+
### Added
|
17
|
+
- Make manifest_path configurable, to keep manifest.json private if desired. [PR 78](https://github.com/shakacode/shakapacker/pull/78) by [jdelStrother](https://github.com/jdelStrother).
|
18
|
+
- Rewrite webpack module rules as regular expressions. Allows for easy iteration during config customization. [PR 60](https://github.com/shakacode/shakapacker/pull/60) by [blnoonan](https://github.com/blnoonan).
|
19
|
+
- Initialization check to ensure shakapacker gem and NPM package version are consistent. Opt-in behaviour enabled by setting `ensure_consistent_versioning` configuration variable. [PR 51](https://github.com/shakacode/shakapacker/pull/51) by [tomdracz](https://github.com/tomdracz).
|
20
|
+
- Add `dev_server.inline_css: bool` config option to allow for opting out of style-loader and into mini-extract-css-plugin for CSS HMR in development. [PR 69](https://github.com/shakacode/shakapacker/pull/69) by [cheald](https://github.com/cheald).
|
21
|
+
|
22
|
+
### Improved
|
23
|
+
- Increase default connect timeout for dev server connections, establishing connections more reliably for busy machines. [PR 74](https://github.com/shakacode/shakapacker/pull/74) by [stevecrozz](https://github.com/stevecrozz).
|
24
|
+
- Allow multiple invocations of stylesheet_pack_tag (eg for a regular stylesheet & a print stylesheet). [PR 82](https://github.com/shakacode/shakapacker/pull/82) by [jdelStrother](https://github.com/jdelStrother).
|
25
|
+
- Tweak swc config for parity with Babel. [PR 79](https://github.com/shakacode/shakapacker/pull/79) by [dleavitt](https://github.com/dleavitt).
|
26
|
+
|
27
|
+
## [v6.1.1] - February 6, 2022
|
28
|
+
|
29
|
+
### Added
|
30
|
+
- Support for esbuild-loader. [PR 53](https://github.com/shakacode/shakapacker/pull/53) by [tomdracz](https://github.com/tomdracz).
|
31
|
+
|
32
|
+
## [v6.1.0] - February 4, 2022
|
11
33
|
### Added
|
12
34
|
- Support for SWC loader. [PR 29](https://github.com/shakacode/shakapacker/pull/29) by [tomdracz](https://github.com/tomdracz).
|
13
35
|
|
@@ -69,7 +91,9 @@ Changes since last non-beta release.
|
|
69
91
|
## v5.4.3 and prior changes from rails/webpacker
|
70
92
|
See [CHANGELOG.md in rails/webpacker (up to v5.4.3)](https://github.com/rails/webpacker/blob/master/CHANGELOG.md)
|
71
93
|
|
72
|
-
[Unreleased]: https://github.com/shakacode/shakapacker/compare/v6.
|
94
|
+
[Unreleased]: https://github.com/shakacode/shakapacker/compare/v6.2.0...master
|
95
|
+
[v6.2.0]: https://github.com/shakacode/shakapacker/compare/v6.1.1...v6.2.0
|
96
|
+
[v6.1.1]: https://github.com/shakacode/shakapacker/compare/v6.1.0...v6.1.1
|
73
97
|
[v6.1.0]: https://github.com/shakacode/shakapacker/compare/v6.0.2...v6.1.0
|
74
98
|
[v6.0.2]: https://github.com/shakacode/shakapacker/compare/v6.0.1...v6.0.2
|
75
99
|
[v6.0.1]: https://github.com/shakacode/shakapacker/compare/v6.0.0...v6.0.1
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,8 +2,7 @@
|
|
2
2
|
|
3
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
|
-
|
6
|
-
* See [V6 Upgrade](./docs/v6_upgrade.md) for upgrading from v5 or prior v6 releases.
|
5
|
+
* See [V6 Upgrade](./docs/v6_upgrade.md) for upgrading from v5 or prior v6 releases.
|
7
6
|
|
8
7
|
[![Ruby specs](https://github.com/shakacode/shakapacker/workflows/Ruby%20specs/badge.svg)](https://github.com/shakacode/shakapacker/actions)
|
9
8
|
[![Jest specs](https://github.com/shakacode/shakapacker/workflows/Jest%20specs/badge.svg)](https://github.com/shakacode/shakapacker/actions)
|
@@ -18,13 +17,16 @@ Webpacker makes it easy to use the JavaScript pre-processor and bundler [Webpack
|
|
18
17
|
to manage application-like JavaScript in Rails. It can coexist with the asset pipeline,
|
19
18
|
leaving Webpack responsible solely for app-like JavaScript, or it can be used exclusively, making it also responsible for images, fonts, and CSS.
|
20
19
|
|
21
|
-
Check out 6.1.
|
20
|
+
Check out 6.1.1+ for [SWC](https://swc.rs/) and [esbuild-loader](https://github.com/privatenumber/esbuild-loader) support! They are faster than Babel!
|
22
21
|
|
23
22
|
See a comparison of [webpacker with jsbundling-rails](https://github.com/rails/jsbundling-rails/blob/main/docs/comparison_with_webpacker.md).
|
24
23
|
|
25
|
-
Discussion
|
26
|
-
1. [
|
27
|
-
2. [
|
24
|
+
Discussion forum and Slack to discuss debugging and troubleshooting tips. Please open issues for bugs and feature requests:
|
25
|
+
1. [Discussions tab](https://github.com/shakacode/shakapacker/discussions)
|
26
|
+
2. [Slack discussion channel](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE)
|
27
|
+
3. [Tweets with tag `#shakapacker`](https://twitter.com/hashtag/shakapacker?src=hashtag_click)
|
28
|
+
|
29
|
+
[ShakaCode](https://www.shakacode.com) offers suppport for upgrading from webpacker or using Shakapacker. If interested, contact [justin@shakacode.com](mailto:justin@shakacode.com). ShakaCode is [hiring passionate engineers](https://jobs.lever.co/shakacode/3bdbfdb3-4495-4611-a279-01dddb351abe) that love open source.
|
28
30
|
|
29
31
|
---
|
30
32
|
|
@@ -46,6 +48,7 @@ Discussion forums to discuss debugging and troubleshooting tips. Please open iss
|
|
46
48
|
- [Webpack Configuration](#webpack-configuration)
|
47
49
|
- [Babel configuration](#babel-configuration)
|
48
50
|
- [SWC configuration](#swc-configuration)
|
51
|
+
- [esbuild loader configuration](#esbuild-loader-configuration)
|
49
52
|
- [Integrations](#integrations)
|
50
53
|
- [React](#react)
|
51
54
|
- [Typescript](#typescript)
|
@@ -77,12 +80,12 @@ Discussion forums to discuss debugging and troubleshooting tips. Please open iss
|
|
77
80
|
- Yarn
|
78
81
|
|
79
82
|
## Features
|
80
|
-
- Rails view helpers that fully support
|
83
|
+
- Rails view helpers that fully support Webpack output, including HMR and code splitting.
|
81
84
|
- Convenient but not required webpack configuration. The only requirement is that your webpack configuration create a manifest.
|
82
85
|
- HMR with the webpack-dev-server, such as for hot-reloading for React!
|
83
86
|
- Automatic code splitting using multiple entry points to optimize JavaScript downloads
|
84
|
-
- [Webpack v5](https://webpack.js.org/)
|
85
|
-
- ES6 with [babel](https://babeljs.io/)
|
87
|
+
- [Webpack v5+](https://webpack.js.org/)
|
88
|
+
- ES6 with [babel](https://babeljs.io/), [SWC](https://swc.rs/), or [Esbuild](https://github.com/privatenumber/esbuild-loader)
|
86
89
|
- Asset compression, source-maps, and minification
|
87
90
|
- CDN support
|
88
91
|
- Extensible and configurable. For example, all major dependencies are specified as peers, so you can upgrade easily.
|
@@ -106,11 +109,10 @@ rails new myapp --skip-javascript
|
|
106
109
|
|
107
110
|
_Note, Rails 6 installs the older v5 version of webpacker unless you specify `--skip-javascript`._
|
108
111
|
|
109
|
-
|
112
|
+
Add `shakapacker` gem to your `Gemfile`:
|
110
113
|
|
111
|
-
```
|
112
|
-
|
113
|
-
gem 'shakapacker', '~> 6.0'
|
114
|
+
```bash
|
115
|
+
bundle add shakapacker --strict
|
114
116
|
```
|
115
117
|
|
116
118
|
Then running the following to install Webpacker:
|
@@ -207,9 +209,18 @@ The result looks like this:
|
|
207
209
|
<%= stylesheet_pack_tag 'map' %>
|
208
210
|
```
|
209
211
|
|
212
|
+
However, you may use multiple calls to stylesheet_pack_tag if, say, you require multiple <style> tags for different output media:
|
213
|
+
|
214
|
+
``` erb
|
215
|
+
<%= stylesheet_pack_tag 'application', media: 'screen' %>
|
216
|
+
<%= stylesheet_pack_tag 'print', media: 'print' %>
|
217
|
+
```
|
218
|
+
|
219
|
+
If you need to setup the pack name args in partials, [see this discussion](https://github.com/shakacode/shakapacker/issues/39).
|
220
|
+
|
210
221
|
If you want to link a static asset for `<img />` tag, you can use the `asset_pack_path` helper:
|
211
222
|
```erb
|
212
|
-
<img src="<%= asset_pack_path '
|
223
|
+
<img src="<%= asset_pack_path 'static/logo.svg' %>" />
|
213
224
|
```
|
214
225
|
|
215
226
|
Or use the dedicated helper:
|
@@ -299,7 +310,7 @@ end
|
|
299
310
|
|
300
311
|
### Webpack Configuration
|
301
312
|
|
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
|
313
|
+
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 minimum, you must ensure:
|
303
314
|
|
304
315
|
1. Your output files go the right directory
|
305
316
|
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!
|
@@ -368,6 +379,13 @@ console.log(webpackConfig.source_path)
|
|
368
379
|
console.log(JSON.stringify(webpackConfig, undefined, 2))
|
369
380
|
```
|
370
381
|
|
382
|
+
You may want to modify 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:
|
383
|
+
|
384
|
+
```js
|
385
|
+
const svgRule = config.module.rules.find(rule => rule.test.test('.svg'));
|
386
|
+
svgRule.test = svgRule.test.filter(t => !t.test('.svg'))
|
387
|
+
```
|
388
|
+
|
371
389
|
### Babel configuration
|
372
390
|
|
373
391
|
By default, you will find the Webpacker preset in your `package.json`. Note, you need to use the new NPM package name, `shakapacker`.
|
@@ -388,6 +406,12 @@ You can try out experimental integration with the SWC loader. You can read more
|
|
388
406
|
|
389
407
|
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
408
|
|
409
|
+
### esbuild loader configuration
|
410
|
+
|
411
|
+
You can try out experimental integration with the esbuild-loader. You can read more at [esbuild-loader usage docs](./docs/using_esbuild_loader.md).
|
412
|
+
|
413
|
+
Please note that if you want opt-in to use esbuild-loader, you can skip [React](#react) integration instructions as it is supported out of the box.
|
414
|
+
|
391
415
|
### Integrations
|
392
416
|
|
393
417
|
Webpacker out of the box supports JS and static assets (fonts, images etc.) compilation. To enable support for CoffeeScript or TypeScript install relevant packages:
|
@@ -658,7 +682,9 @@ development:
|
|
658
682
|
port: 3035
|
659
683
|
```
|
660
684
|
|
661
|
-
If you have `hmr` turned to true, then the `stylesheet_pack_tag` generates no output, as you will want to configure your styles to be inlined in your JavaScript for hot reloading. During production and testing, the `stylesheet_pack_tag` will create the appropriate HTML tags.
|
685
|
+
If you have `hmr` turned to true and `inline_css` is not false, then the `stylesheet_pack_tag` generates no output, as you will want to configure your styles to be inlined in your JavaScript for hot reloading. During production and testing, the `stylesheet_pack_tag` will create the appropriate HTML tags.
|
686
|
+
|
687
|
+
If you want to have HMR and separate link tags, set `hmr: true` and `inline_css: false`. This will cause styles to be extracted and reloaded with the `mini-css-extract-plugin` loader. Note that in this scenario, you do not need to include style-loader in your project dependencies.
|
662
688
|
|
663
689
|
### Additional paths
|
664
690
|
|
@@ -29,7 +29,9 @@ yarn add --dev @pmmmwh/react-refresh-webpack-plugin react-refresh
|
|
29
29
|
module.exports = function (api) {
|
30
30
|
const defaultConfigFunc = require('shakapacker/package/babel/preset.js')
|
31
31
|
const resultConfig = defaultConfigFunc(api)
|
32
|
+
const isDevelopmentEnv = api.env('development')
|
32
33
|
const isProductionEnv = api.env('production')
|
34
|
+
const isTestEnv = api.env('test')
|
33
35
|
|
34
36
|
const changesOnDefault = {
|
35
37
|
presets: [
|
data/docs/deployment.md
CHANGED
@@ -93,10 +93,10 @@ you don't need to do anything extra for Webpacker, it just works.
|
|
93
93
|
|
94
94
|
### Assets compiling on every deployment even if JavaScript and CSS files are not changed
|
95
95
|
|
96
|
-
Make sure you have `public/packs` and `node_modules` in `:linked_dirs`
|
96
|
+
Make sure you have your public outputh path (default `public/packs`), the webpacker cache path (default `tmp/webpacker`) and `node_modules` in `:linked_dirs`
|
97
97
|
|
98
98
|
```ruby
|
99
|
-
append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/packs", ".bundle", "node_modules"
|
99
|
+
append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "tmp/webpacker", "public/packs", ".bundle", "node_modules"
|
100
100
|
```
|
101
101
|
|
102
102
|
If you have `node_modules` added to `:linked_dirs` you'll need to run yarn install before `deploy:assets:precompile`, so you can add this code snippet at the bottom deploy.rb
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# CSS Delivery In Development
|
2
|
+
|
3
|
+
You have two options for serving CSS in development:
|
4
|
+
|
5
|
+
1. You can opt to serve CSS via style-loader (as was traditionally done in a Webpack setup), where CSS is written by Javascript served by Webpacker into a `<style>` tag, or
|
6
|
+
2. You can opt to serve CSS as a full CSS file via mini-css-extract-plugin, which uses a standard `<link>` tag to load a fully separate CSS file.
|
7
|
+
|
8
|
+
Both options support HMR. The default is style-loader. If you want to use mini-css-extract-plugin in development, set `inline_css: false` in the development dev_server section of your webpacker.yml:
|
9
|
+
|
10
|
+
```yml
|
11
|
+
development:
|
12
|
+
<<: *default
|
13
|
+
dev_server:
|
14
|
+
hmr: true
|
15
|
+
inline_css: false # Use mini-css-extract-plugin for CSS delivery
|
16
|
+
```
|
17
|
+
|
18
|
+
## Why would I pick style-loader?
|
19
|
+
|
20
|
+
style-loader is how you are probably are used to serving CSS in development with HMR in Webpack.
|
21
|
+
|
22
|
+
### benefits
|
23
|
+
|
24
|
+
* No [Flash Of Unstyled Content (FOUC)](https://en.wikipedia.org/wiki/Flash_of_unstyled_content) on HMR refreshes
|
25
|
+
* Smaller/faster incremental updates.
|
26
|
+
|
27
|
+
### drawbacks
|
28
|
+
|
29
|
+
* Inflated JS deliverable size; requires JS execution before CSS is available
|
30
|
+
* FOUC on initial page load
|
31
|
+
* Adds an extra dependency
|
32
|
+
* Divergence in delivery mechanism from production
|
33
|
+
|
34
|
+
## Why would I pick mini-extract-css-plugin?
|
35
|
+
|
36
|
+
mini-css-extract-plugin's behavior is much more true to a production deployment's behavior, in that CSS is loaded via `link rel=stylsheet` tags, rather than injected by Javascript into `style` tags.
|
37
|
+
|
38
|
+
### benefits
|
39
|
+
|
40
|
+
* Required for production, so it's going to be in play anyhow. Using only it simplifies the config and eliminates the style-loader dependency.
|
41
|
+
* No FOUC on initial page loads
|
42
|
+
* CSS delivered via `<link>` tags matches the mechanism used in production (I have been guilty of omitting my `stylesheet_pack_tag` for my first deploy because CSS worked fine with just the `javascript_pack_tag` in development.)
|
43
|
+
|
44
|
+
### drawbacks
|
45
|
+
|
46
|
+
* Invokes a separate HTTP request, compared to style-loader
|
47
|
+
* Potential for FOUC on HMR refreshes
|
48
|
+
* More data transferred per refresh (full stylesheet reload, rather than just an incremental patch). Not likely to be noticed for local development, but still a technical difference. This may only be the case [when you're using local CSS modules](https://github.com/webpack-contrib/mini-css-extract-plugin/blob/master/src/hmr/hotModuleReplacement.js#L267-L273).
|
data/docs/troubleshooting.md
CHANGED
@@ -17,6 +17,24 @@
|
|
17
17
|
|
18
18
|
4. You can also pass additional options to the command to run the webpack-dev-server and start the webpack-dev-server with the option `--debug-webpacker`
|
19
19
|
|
20
|
+
## Incorrect peer dependencies
|
21
|
+
The latest version of Shakapacker uses peer dependencies to make upgrading easier. However, there's a catch.
|
22
|
+
|
23
|
+
If you fail to update peer dependencies, you'll see an easy-to-overlook warning from `yarn install`.
|
24
|
+
|
25
|
+
```
|
26
|
+
warning " > shakapacker@6.1.1" has incorrect peer dependency "compression-webpack-plugin@^9.0.0".
|
27
|
+
```
|
28
|
+
|
29
|
+
This omission resulted in an error in the browser:
|
30
|
+
```
|
31
|
+
Failed to load resource: net::ERR_CONTENT_DECODING_FAILED
|
32
|
+
```
|
33
|
+
|
34
|
+
The error was caused by an old version of the peer dependency webpack-compression-plugin.
|
35
|
+
|
36
|
+
So, be sure to investigate warnings from `yarn install`!
|
37
|
+
|
20
38
|
## ENOENT: no such file or directory - node-sass
|
21
39
|
|
22
40
|
If you get the error `ENOENT: no such file or directory - node-sass` on deploy with
|
@@ -0,0 +1,128 @@
|
|
1
|
+
# Using esbuild-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 them at https://github.com/shakacode/shakapacker/issues.
|
6
|
+
|
7
|
+
## About esbuild
|
8
|
+
|
9
|
+
[esbuild](https://esbuild.github.io/) is a Go-based bundler tool that can offer [significant improvement](https://esbuild.github.io/faq/#benchmark-details) over other similar tools.
|
10
|
+
|
11
|
+
While esbuild is a complete bundler, through the usage of [esbuild-loader](https://github.com/privatenumber/esbuild-loader), you can still leverage esbuild's speedy transpilation and minifcation in your Webpack-based configs.
|
12
|
+
|
13
|
+
Please note, that unlike Babel or SWC loader, esbuild-loader has got no support for things like:
|
14
|
+
- React Hot Module reload
|
15
|
+
- ES5 as a compilation target
|
16
|
+
- Automatic polyfills for missing browser features
|
17
|
+
|
18
|
+
Those are limitations of esbuild itself and might make use of esbuild-loader in your project unfeasible. If you don't care about HMR and don't need to support older browsers, esbuild-loader might be a suitable option for you.
|
19
|
+
|
20
|
+
## Switching your Shakapacker project to esbuild-loader
|
21
|
+
|
22
|
+
To use esbuild as your transpiler today. You need to do two things:
|
23
|
+
|
24
|
+
1. Make sure you've installed `esbuild` and `esbuild-loader` packages.
|
25
|
+
|
26
|
+
```
|
27
|
+
yarn add esbuild esbuild-loader
|
28
|
+
```
|
29
|
+
|
30
|
+
2. Add or change `webpacker_loader` value in your default `webpacker.yml` config to `esbuild`
|
31
|
+
The default configuration of babel is done by using `package.json` to use the file within the `shakapacker` package.
|
32
|
+
|
33
|
+
```yml
|
34
|
+
default: &default
|
35
|
+
source_path: app/javascript
|
36
|
+
source_entry_path: /
|
37
|
+
public_root_path: public
|
38
|
+
public_output_path: packs
|
39
|
+
cache_path: tmp/webpacker
|
40
|
+
webpack_compile_output: true
|
41
|
+
|
42
|
+
# Additional paths webpack should look up modules
|
43
|
+
# ['app/assets', 'engine/foo/app/assets']
|
44
|
+
additional_paths: []
|
45
|
+
|
46
|
+
# Reload manifest.json on all requests so we reload latest compiled packs
|
47
|
+
cache_manifest: false
|
48
|
+
|
49
|
+
# Select loader to use, available options are 'babel' (default), 'swc' or 'esbuild'
|
50
|
+
webpack_loader: 'esbuild'
|
51
|
+
```
|
52
|
+
|
53
|
+
### (Optional) Replace minification with esbuild
|
54
|
+
|
55
|
+
You can gain an additional performance boost if you replace the default Terser minification with esbuild plugin.
|
56
|
+
|
57
|
+
o do so, you need to modify your webpack configuration and use `ESBuildMinifyPlugin` provided by `esbuild-loader`.
|
58
|
+
|
59
|
+
Example:
|
60
|
+
|
61
|
+
```js
|
62
|
+
const { webpackConfig: baseWebpackConfig, merge } = require('shakapacker')
|
63
|
+
const { ESBuildMinifyPlugin } = require('esbuild-loader')
|
64
|
+
|
65
|
+
const options = {
|
66
|
+
optimization: {
|
67
|
+
minimizer: [
|
68
|
+
new ESBuildMinifyPlugin({
|
69
|
+
target: 'es2015'
|
70
|
+
})
|
71
|
+
]
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
module.exports = merge({}, baseWebpackConfig, options)
|
76
|
+
```
|
77
|
+
|
78
|
+
For more details, see instructions at https://github.com/shakacode/shakapacker#webpack-configuration and https://github.com/privatenumber/esbuild-loader#js-minification-eg-terser.
|
79
|
+
|
80
|
+
## Usage
|
81
|
+
|
82
|
+
### React
|
83
|
+
|
84
|
+
React is supported out of the box, provided you use `.jsx` or `.tsx` file extension. Shakapacker config will correctly recognize those and tell esbuild to parse the JSX syntax correctly. If you wish to customize the likes of JSX fragment function, you can do that through customizing loader options as described below. You can see available options at https://github.com/privatenumber/esbuild-loader#%EF%B8%8F-options.
|
85
|
+
|
86
|
+
### Typescript
|
87
|
+
|
88
|
+
Typescript is supported out of the box and `.tsconfig.json` root file is automatically detected. Only a subset of `.tsconfig.json` options is supported. Please refer to the [loader docs](https://github.com/privatenumber/esbuild-loader#configuration) for additional information.
|
89
|
+
|
90
|
+
## Customizing loader options
|
91
|
+
|
92
|
+
You can see the default loader options at [esbuild/index.js](../package/esbuild/index.js).
|
93
|
+
|
94
|
+
If you wish to customize the loader defaults further, you need to create a `esbuild.config.js` file in your app config folder.
|
95
|
+
|
96
|
+
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.
|
97
|
+
|
98
|
+
Inside the `options` key, you can use any options available to the esbuild-loader. For the options reference, please refer to [esbuild-loader docs](https://github.com/privatenumber/esbuild-loader#%EF%B8%8F-options).
|
99
|
+
|
100
|
+
See some examples below of potential `config/babel.config.js`.
|
101
|
+
|
102
|
+
### Example: Specifying esnext target environment
|
103
|
+
|
104
|
+
|
105
|
+
```js
|
106
|
+
const customConfig = {
|
107
|
+
options: {
|
108
|
+
target: 'esnext'
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
module.exports = customConfig
|
113
|
+
```
|
114
|
+
|
115
|
+
### Example: Using custom jsxFragment and jsxFactory
|
116
|
+
|
117
|
+
```js
|
118
|
+
const { env } = require('shakapacker')
|
119
|
+
|
120
|
+
const customConfig = {
|
121
|
+
options: {
|
122
|
+
jsxFragment: 'Fragment',
|
123
|
+
jsxFactory: 'h'
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
module.exports = customConfig
|
128
|
+
```
|
data/docs/using_swc_loader.md
CHANGED
@@ -19,10 +19,10 @@ In order to use SWC as your compiler today. You need to do two things:
|
|
19
19
|
1. Make sure you've installed `@swc/core` and `swc-loader` packages.
|
20
20
|
|
21
21
|
```
|
22
|
-
yarn add
|
22
|
+
yarn add @swc/core swc-loader
|
23
23
|
```
|
24
24
|
|
25
|
-
2. Add or change `
|
25
|
+
2. Add or change `webpack_loader` value in your default `webpacker.yml` config to `swc`
|
26
26
|
The default configuration of babel is done by using `package.json` to use the file within the `shakapacker` package.
|
27
27
|
|
28
28
|
```yml
|