shakapacker 6.1.0.beta.0 → 6.2.0
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/.github/workflows/jest.yml +1 -4
- data/.github/workflows/js-lint.yml +3 -7
- data/.github/workflows/rubocop.yml +3 -20
- data/.github/workflows/ruby.yml +12 -19
- data/.node-version +1 -1
- data/.rubocop.yml +0 -1
- data/CHANGELOG.md +34 -3
- data/Gemfile.lock +1 -1
- data/README.md +50 -17
- data/docs/customizing_babel_config.md +2 -0
- data/docs/style_loader_vs_mini_css.md +48 -0
- data/docs/using_esbuild_loader.md +128 -0
- data/docs/using_swc_loader.md +6 -4
- data/docs/v6_upgrade.md +95 -79
- data/gemfiles/Gemfile-rails.7.0.x +12 -0
- 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 +1 -1
- data/lib/webpacker/configuration.rb +12 -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 +14 -18
- 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 +24 -3
- 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/webpacker.gemspec +1 -1
- data/yarn.lock +145 -1
- metadata +35 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6e31a49e348719f7663178aee3ec877d3a53f6bd9e264fd8e82278ac17070e7
|
4
|
+
data.tar.gz: c2d9294063be7bab761baf8f10eeb82c350dfcc0bfc322cac52fa06fdb4cbef5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cb3b71113fd1c7aad90098a4b0927830347feafe9cb9ef245aa6551950d67b9488be5d9aa411fcb6f775260856189d9cbfc5899732113fffbd7549aee84b7ef
|
7
|
+
data.tar.gz: 1729dccb33de9f34a2c3ca26268c79255e813a71fae548acd5066d7faaef30e4a58123955a32e7b48c19bb988cd078f407cbdcebae6bcf817522451914fbac7e
|
@@ -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/.github/workflows/jest.yml
CHANGED
@@ -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
|
-
|
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:
|
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
|
data/.github/workflows/ruby.yml
CHANGED
@@ -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.
|
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
|
31
|
-
|
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
|
-
|
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
|
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.
|
1
|
+
16.14.0
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,37 @@
|
|
1
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 [
|
2
|
+
* Please see [v6 Upgrade Guide](./docs/v6_upgrade.md) to go from version prior to v6.
|
3
3
|
|
4
4
|
## Versions
|
5
|
-
|
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
|
+
|
10
|
+
## [v6.2.0] - March 22, 2022
|
11
|
+
|
12
|
+
### Added
|
13
|
+
- 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).
|
14
|
+
- 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).
|
15
|
+
- 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).
|
16
|
+
- 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).
|
17
|
+
|
18
|
+
### Improved
|
19
|
+
- 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).
|
20
|
+
- 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).
|
21
|
+
- Tweak swc config for parity with Babel. [PR 79](https://github.com/shakacode/shakapacker/pull/79) by [dleavitt](https://github.com/dleavitt).
|
22
|
+
|
23
|
+
## [v6.1.1] - February 6, 2022
|
24
|
+
|
25
|
+
### Added
|
26
|
+
- Support for esbuild-loader. [PR 53](https://github.com/shakacode/shakapacker/pull/53) by [tomdracz](https://github.com/tomdracz).
|
27
|
+
|
28
|
+
## [v6.1.0] - February 4, 2022
|
29
|
+
### Added
|
30
|
+
- Support for SWC loader. [PR 29](https://github.com/shakacode/shakapacker/pull/29) by [tomdracz](https://github.com/tomdracz).
|
31
|
+
|
32
|
+
### Fixed
|
33
|
+
- 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).
|
34
|
+
|
9
35
|
## [v6.0.2] - January 25, 2022
|
10
36
|
### Improved
|
11
37
|
- Fix incorrect command name in warning. [PR 33](https://github.com/shakacode/shakapacker/pull/33) by [tricknotes](https://github.com/tricknotes).
|
@@ -58,8 +84,13 @@ Changes since last non-beta release.
|
|
58
84
|
- Splitchunks enabled by default
|
59
85
|
- CSS extraction enabled by default, except when devServer is configured and running
|
60
86
|
|
87
|
+
## v5.4.3 and prior changes from rails/webpacker
|
88
|
+
See [CHANGELOG.md in rails/webpacker (up to v5.4.3)](https://github.com/rails/webpacker/blob/master/CHANGELOG.md)
|
61
89
|
|
62
|
-
[Unreleased]: https://github.com/shakacode/shakapacker/compare/
|
90
|
+
[Unreleased]: https://github.com/shakacode/shakapacker/compare/v6.2.0...master
|
91
|
+
[v6.2.0]: https://github.com/shakacode/shakapacker/compare/v6.1.1...v6.2.0
|
92
|
+
[v6.1.1]: https://github.com/shakacode/shakapacker/compare/v6.1.0...v6.1.1
|
93
|
+
[v6.1.0]: https://github.com/shakacode/shakapacker/compare/v6.0.2...v6.1.0
|
63
94
|
[v6.0.2]: https://github.com/shakacode/shakapacker/compare/v6.0.1...v6.0.2
|
64
95
|
[v6.0.1]: https://github.com/shakacode/shakapacker/compare/v6.0.0...v6.0.1
|
65
96
|
[v6.0.0 changes from v6.0.0.rc.6]: https://github.com/shakacode/shakapacker/compare/aba79635e6ff6562ec04d3c446d57ef19a5fef7d...v6.0.0
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# Shakapacker
|
2
2
|
|
3
|
-
_Official, actively maintained
|
4
|
-
|
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
|
+
|
5
|
+
* See [V6 Upgrade](./docs/v6_upgrade.md) for upgrading from v5 or prior v6 releases.
|
5
6
|
|
6
7
|
[![Ruby specs](https://github.com/shakacode/shakapacker/workflows/Ruby%20specs/badge.svg)](https://github.com/shakacode/shakapacker/actions)
|
7
8
|
[![Jest specs](https://github.com/shakacode/shakapacker/workflows/Jest%20specs/badge.svg)](https://github.com/shakacode/shakapacker/actions)
|
@@ -12,16 +13,17 @@ _Official, actively maintained fork of [rails/webpacker](https://github.com/rail
|
|
12
13
|
[![Gem](https://img.shields.io/gem/v/shakapacker.svg)](https://rubygems.org/gems/shakapacker)
|
13
14
|
[![npm version](https://badge.fury.io/js/shakapacker.svg)](https://badge.fury.io/js/shakapacker)
|
14
15
|
|
15
|
-
Webpacker makes it easy to use the JavaScript pre-processor and bundler
|
16
|
-
[Webpack v5](https://webpack.js.org/)
|
16
|
+
Webpacker makes it easy to use the JavaScript pre-processor and bundler [Webpack v5+](https://webpack.js.org/)
|
17
17
|
to manage application-like JavaScript in Rails. It can coexist with the asset pipeline,
|
18
18
|
leaving Webpack responsible solely for app-like JavaScript, or it can be used exclusively, making it also responsible for images, fonts, and CSS.
|
19
19
|
|
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!
|
21
|
+
|
20
22
|
See a comparison of [webpacker with jsbundling-rails](https://github.com/rails/jsbundling-rails/blob/main/docs/comparison_with_webpacker.md).
|
21
23
|
|
22
|
-
Discussion
|
23
|
-
1. [
|
24
|
-
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)
|
25
27
|
|
26
28
|
---
|
27
29
|
|
@@ -34,6 +36,7 @@ Discussion forums to discuss debugging and troubleshooting tips. Please open iss
|
|
34
36
|
- [Installation](#installation)
|
35
37
|
- [Rails v6+](#rails-v6)
|
36
38
|
- [Note for Sprockets usage](#note-for-sprockets-usage)
|
39
|
+
- [Note for Yarn v2 usage](#note-for-yarn-v2-usage)
|
37
40
|
- [Usage](#usage)
|
38
41
|
- [View Helpers](#view-helpers)
|
39
42
|
- [Defer for `javascript_pack_tag`](#defer-for-javascript_pack_tag)
|
@@ -42,6 +45,7 @@ Discussion forums to discuss debugging and troubleshooting tips. Please open iss
|
|
42
45
|
- [Webpack Configuration](#webpack-configuration)
|
43
46
|
- [Babel configuration](#babel-configuration)
|
44
47
|
- [SWC configuration](#swc-configuration)
|
48
|
+
- [esbuild loader configuration](#esbuild-loader-configuration)
|
45
49
|
- [Integrations](#integrations)
|
46
50
|
- [React](#react)
|
47
51
|
- [Typescript](#typescript)
|
@@ -67,18 +71,18 @@ Discussion forums to discuss debugging and troubleshooting tips. Please open iss
|
|
67
71
|
|
68
72
|
## Prerequisites
|
69
73
|
|
70
|
-
- Ruby 2.
|
74
|
+
- Ruby 2.6+
|
71
75
|
- Rails 5.2+
|
72
76
|
- Node.js 12.13.0+ || 14+
|
73
77
|
- Yarn
|
74
78
|
|
75
79
|
## Features
|
76
|
-
- Rails view helpers that fully support
|
80
|
+
- Rails view helpers that fully support Webpack output, including HMR and code splitting.
|
77
81
|
- Convenient but not required webpack configuration. The only requirement is that your webpack configuration create a manifest.
|
78
82
|
- HMR with the webpack-dev-server, such as for hot-reloading for React!
|
79
83
|
- Automatic code splitting using multiple entry points to optimize JavaScript downloads
|
80
|
-
- [Webpack v5](https://webpack.js.org/)
|
81
|
-
- ES6 with [babel](https://babeljs.io/)
|
84
|
+
- [Webpack v5+](https://webpack.js.org/)
|
85
|
+
- ES6 with [babel](https://babeljs.io/), [SWC](https://swc.rs/), or [Esbuild](https://github.com/privatenumber/esbuild-loader)
|
82
86
|
- Asset compression, source-maps, and minification
|
83
87
|
- CDN support
|
84
88
|
- Extensible and configurable. For example, all major dependencies are specified as peers, so you can upgrade easily.
|
@@ -102,11 +106,10 @@ rails new myapp --skip-javascript
|
|
102
106
|
|
103
107
|
_Note, Rails 6 installs the older v5 version of webpacker unless you specify `--skip-javascript`._
|
104
108
|
|
105
|
-
|
109
|
+
Add `shakapacker` gem to your `Gemfile`:
|
106
110
|
|
107
|
-
```
|
108
|
-
|
109
|
-
gem 'shakapacker', '~> 6.0'
|
111
|
+
```bash
|
112
|
+
bundle add shakapacker --strict
|
110
113
|
```
|
111
114
|
|
112
115
|
Then running the following to install Webpacker:
|
@@ -142,6 +145,12 @@ In order to enable this, make sure you add `node_modules` to the asset load path
|
|
142
145
|
Rails.application.config.assets.paths << Rails.root.join('node_modules')
|
143
146
|
```
|
144
147
|
|
148
|
+
### Note for Yarn v2 usage
|
149
|
+
|
150
|
+
If you are using Yarn v2 (berry), please note that PnP modules are not supported.
|
151
|
+
|
152
|
+
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.
|
153
|
+
|
145
154
|
## Usage
|
146
155
|
|
147
156
|
### View Helpers
|
@@ -197,9 +206,18 @@ The result looks like this:
|
|
197
206
|
<%= stylesheet_pack_tag 'map' %>
|
198
207
|
```
|
199
208
|
|
209
|
+
However, you may use multiple calls to stylesheet_pack_tag if, say, you require multiple <style> tags for different output media:
|
210
|
+
|
211
|
+
``` erb
|
212
|
+
<%= stylesheet_pack_tag 'application', media: 'screen' %>
|
213
|
+
<%= stylesheet_pack_tag 'print', media: 'print' %>
|
214
|
+
```
|
215
|
+
|
216
|
+
If you need to setup the pack name args in partials, [see this discussion](https://github.com/shakacode/shakapacker/issues/39).
|
217
|
+
|
200
218
|
If you want to link a static asset for `<img />` tag, you can use the `asset_pack_path` helper:
|
201
219
|
```erb
|
202
|
-
<img src="<%= asset_pack_path '
|
220
|
+
<img src="<%= asset_pack_path 'static/logo.svg' %>" />
|
203
221
|
```
|
204
222
|
|
205
223
|
Or use the dedicated helper:
|
@@ -358,6 +376,13 @@ console.log(webpackConfig.source_path)
|
|
358
376
|
console.log(JSON.stringify(webpackConfig, undefined, 2))
|
359
377
|
```
|
360
378
|
|
379
|
+
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:
|
380
|
+
|
381
|
+
```js
|
382
|
+
const svgRule = config.module.rules.find(rule => rule.test.test('.svg'));
|
383
|
+
svgRule.test = svgRule.test.filter(t => !t.test('.svg'))
|
384
|
+
```
|
385
|
+
|
361
386
|
### Babel configuration
|
362
387
|
|
363
388
|
By default, you will find the Webpacker preset in your `package.json`. Note, you need to use the new NPM package name, `shakapacker`.
|
@@ -378,6 +403,12 @@ You can try out experimental integration with the SWC loader. You can read more
|
|
378
403
|
|
379
404
|
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
405
|
|
406
|
+
### esbuild loader configuration
|
407
|
+
|
408
|
+
You can try out experimental integration with the esbuild-loader. You can read more at [esbuild-loader usage docs](./docs/using_esbuild_loader.md).
|
409
|
+
|
410
|
+
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.
|
411
|
+
|
381
412
|
### Integrations
|
382
413
|
|
383
414
|
Webpacker out of the box supports JS and static assets (fonts, images etc.) compilation. To enable support for CoffeeScript or TypeScript install relevant packages:
|
@@ -648,7 +679,9 @@ development:
|
|
648
679
|
port: 3035
|
649
680
|
```
|
650
681
|
|
651
|
-
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.
|
682
|
+
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.
|
683
|
+
|
684
|
+
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.
|
652
685
|
|
653
686
|
### Additional paths
|
654
687
|
|
@@ -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: [
|
@@ -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).
|
@@ -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
@@ -1,6 +1,8 @@
|
|
1
1
|
# Using SWC Loader
|
2
2
|
|
3
|
-
:warning: This feature is currently experimental.
|
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.
|
4
6
|
|
5
7
|
## About SWC
|
6
8
|
|
@@ -17,13 +19,13 @@ In order to use SWC as your compiler today. You need to do two things:
|
|
17
19
|
1. Make sure you've installed `@swc/core` and `swc-loader` packages.
|
18
20
|
|
19
21
|
```
|
20
|
-
yarn add
|
22
|
+
yarn add @swc/core swc-loader
|
21
23
|
```
|
22
24
|
|
23
|
-
2. Add or change `
|
25
|
+
2. Add or change `webpack_loader` value in your default `webpacker.yml` config to `swc`
|
24
26
|
The default configuration of babel is done by using `package.json` to use the file within the `shakapacker` package.
|
25
27
|
|
26
|
-
```
|
28
|
+
```yml
|
27
29
|
default: &default
|
28
30
|
source_path: app/javascript
|
29
31
|
source_entry_path: /
|