shakapacker 7.0.3 → 7.2.0.rc.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/dummy.yml +3 -1
- data/.github/workflows/generator.yml +6 -1
- data/.github/workflows/jest.yml +4 -2
- data/.github/workflows/js-lint.yml +4 -2
- data/.github/workflows/rubocop.yml +3 -1
- data/.github/workflows/ruby-backward-compatibility.yml +9 -1
- data/.github/workflows/ruby.yml +11 -2
- data/CHANGELOG.md +16 -3
- data/README.md +58 -23
- data/docs/troubleshooting.md +4 -8
- data/docs/using_esbuild_loader.md +2 -4
- data/docs/v6_upgrade.md +1 -1
- data/lib/install/template.rb +58 -18
- data/lib/shakapacker/compiler.rb +5 -3
- data/lib/shakapacker/configuration.rb +8 -0
- data/lib/shakapacker/deprecation_helper.rb +1 -1
- data/lib/shakapacker/dev_server_runner.rb +13 -6
- data/lib/shakapacker/runner.rb +19 -1
- data/lib/shakapacker/utils/misc.rb +12 -0
- data/lib/shakapacker/version.rb +1 -1
- data/lib/shakapacker/version_checker.rb +35 -2
- data/lib/shakapacker/webpack_runner.rb +16 -8
- data/lib/tasks/shakapacker/binstubs.rake +1 -1
- data/lib/tasks/shakapacker/check_manager.rake +27 -0
- data/lib/tasks/shakapacker/check_yarn.rake +2 -1
- data/lib/tasks/shakapacker/info.rake +20 -3
- data/lib/tasks/shakapacker/install.rake +1 -1
- data/lib/tasks/shakapacker/verify_install.rake +1 -1
- data/lib/tasks/shakapacker.rake +2 -2
- data/lib/tasks/webpacker/check_yarn.rake +1 -1
- data/package/__tests__/index.js +24 -0
- data/package/index.d.ts +1 -1
- data/package/index.js +8 -2
- data/package.json +2 -2
- data/shakapacker.gemspec +1 -0
- data/spec/backward_compatibility_specs/compiler_strategy_spec.rb +5 -3
- data/spec/backward_compatibility_specs/configuration_spec.rb +12 -4
- data/spec/backward_compatibility_specs/dev_server_runner_spec.rb +103 -42
- data/spec/backward_compatibility_specs/dev_server_spec.rb +1 -1
- data/spec/backward_compatibility_specs/digest_strategy_spec.rb +2 -0
- data/spec/backward_compatibility_specs/engine_rake_tasks_spec.rb +30 -7
- data/spec/backward_compatibility_specs/helper_spec.rb +20 -20
- data/spec/backward_compatibility_specs/instance_spec.rb +3 -3
- data/spec/backward_compatibility_specs/manifest_spec.rb +12 -12
- data/spec/backward_compatibility_specs/mtime_strategy_spec.rb +3 -3
- data/spec/backward_compatibility_specs/rake_tasks_spec.rb +9 -5
- data/spec/backward_compatibility_specs/webpack_runner_spec.rb +55 -25
- data/spec/dummy/config/webpack/commonWebpackConfig.js +1 -1
- data/spec/fixtures/beta_pnpm-lock.v7.yaml +116 -0
- data/spec/fixtures/beta_pnpm-lock.v8.yaml +2537 -0
- data/spec/fixtures/git_url_pnpm-lock.v7.yaml +126 -0
- data/spec/fixtures/git_url_pnpm-lock.v8.yaml +3728 -0
- data/spec/fixtures/github_url_pnpm-lock.v7.yaml +126 -0
- data/spec/fixtures/github_url_pnpm-lock.v8.yaml +3728 -0
- data/spec/fixtures/relative_path_pnpm-lock.v7.yaml +18 -0
- data/spec/fixtures/relative_path_pnpm-lock.v8.yaml +22 -0
- data/spec/fixtures/semver_caret_pnpm-lock.v7.yaml +117 -0
- data/spec/fixtures/semver_caret_pnpm-lock.v8.yaml +2558 -0
- data/spec/fixtures/semver_exact_pnpm-lock.v7.yaml +117 -0
- data/spec/fixtures/semver_exact_pnpm-lock.v8.yaml +2558 -0
- data/spec/fixtures/semver_tilde_pnpm-lock.v7.yaml +116 -0
- data/spec/fixtures/semver_tilde_pnpm-lock.v8.yaml +2558 -0
- data/spec/fixtures/without_pnpm-lock.v7.yaml +23 -0
- data/spec/fixtures/without_pnpm-lock.v8.yaml +27 -0
- data/spec/generator_specs/e2e_template/template.rb +31 -10
- data/spec/generator_specs/fake-bin/bun +10 -0
- data/spec/generator_specs/fake-bin/npm +10 -0
- data/spec/generator_specs/fake-bin/pnpm +10 -0
- data/spec/generator_specs/fake-bin/yarn +10 -0
- data/spec/generator_specs/generator_spec.rb +172 -18
- data/spec/mounted_app/package.json +1 -0
- data/spec/shakapacker/compiler_spec.rb +9 -5
- data/spec/shakapacker/compiler_strategy_spec.rb +5 -3
- data/spec/shakapacker/configuration_spec.rb +60 -2
- data/spec/shakapacker/dev_server_runner_spec.rb +108 -43
- data/spec/shakapacker/dev_server_spec.rb +1 -1
- data/spec/shakapacker/digest_strategy_spec.rb +2 -0
- data/spec/shakapacker/engine_rake_tasks_spec.rb +28 -6
- data/spec/shakapacker/helper_spec.rb +20 -20
- data/spec/shakapacker/instance_spec.rb +2 -2
- data/spec/shakapacker/manifest_spec.rb +12 -12
- data/spec/shakapacker/mtime_strategy_spec.rb +3 -3
- data/spec/shakapacker/rake_tasks_spec.rb +10 -6
- data/spec/shakapacker/shakapacker_spec.rb +4 -4
- data/spec/shakapacker/spec_helper_initializer.rb +18 -0
- data/spec/shakapacker/version_checker_spec.rb +468 -121
- data/spec/shakapacker/webpack_runner_spec.rb +55 -25
- data/spec/spec_helper.rb +2 -0
- data/spec/support/package_json_helpers.rb +16 -0
- metadata +42 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7c6cb64c439d97ec52580010225f4b2204ea652e281926da18b21be6c7ef545
|
4
|
+
data.tar.gz: 33adeb8d524cd2c08206bc1b06c3183cd44f469c7c44b453466ea149baceb30d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22c9e5716abf6528ab34f652a6b145cb97897769b7c9f4da09f63b9090ce3a2faea507db94cc6fcd87cdf5be8bc60be0881ffd2f9f1f7a5d218d37d759021ffc
|
7
|
+
data.tar.gz: c3a299a84e15d15216d9e6e8c83513b6a9d0ca805587b80779e7e6b8bafd0e8f7090686a6fd82da1eecd829d25a68bf8df25ebf7bec1f82213918edb83953f92
|
data/.github/workflows/dummy.yml
CHANGED
@@ -10,6 +10,7 @@ jobs:
|
|
10
10
|
matrix:
|
11
11
|
os: [ubuntu-latest]
|
12
12
|
ruby: ['2.6', '2.7', '3.0']
|
13
|
+
use_package_json_gem: ['true', 'false']
|
13
14
|
gemfile:
|
14
15
|
- gemfiles/Gemfile-rails.6.0.x
|
15
16
|
- gemfiles/Gemfile-rails.6.1.x
|
@@ -28,10 +29,14 @@ jobs:
|
|
28
29
|
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
29
30
|
|
30
31
|
steps:
|
31
|
-
- uses: actions/checkout@
|
32
|
+
- uses: actions/checkout@v4
|
33
|
+
with:
|
34
|
+
persist-credentials: false
|
32
35
|
- uses: ruby/setup-ruby@v1
|
33
36
|
with:
|
34
37
|
ruby-version: ${{ matrix.ruby }}
|
35
38
|
- name: Install dependencies
|
36
39
|
run: bundle install
|
37
40
|
- run: bundle exec rake run_spec:generator
|
41
|
+
env:
|
42
|
+
SHAKAPACKER_USE_PACKAGE_JSON_GEM: ${{ matrix.use_package_json_gem }}
|
data/.github/workflows/jest.yml
CHANGED
@@ -13,9 +13,11 @@ jobs:
|
|
13
13
|
runs-on: ${{ matrix.os }}
|
14
14
|
|
15
15
|
steps:
|
16
|
-
- uses: actions/checkout@
|
16
|
+
- uses: actions/checkout@v4
|
17
|
+
with:
|
18
|
+
persist-credentials: false
|
17
19
|
- name: Use Node.js ${{ matrix.node }}
|
18
|
-
uses: actions/setup-node@
|
20
|
+
uses: actions/setup-node@v3
|
19
21
|
with:
|
20
22
|
node-version: ${{ matrix.node }}
|
21
23
|
cache: yarn
|
@@ -13,9 +13,11 @@ jobs:
|
|
13
13
|
runs-on: ${{ matrix.os }}
|
14
14
|
|
15
15
|
steps:
|
16
|
-
- uses: actions/checkout@
|
16
|
+
- uses: actions/checkout@v4
|
17
|
+
with:
|
18
|
+
persist-credentials: false
|
17
19
|
- name: Use Node.js ${{ matrix.node }}
|
18
|
-
uses: actions/setup-node@
|
20
|
+
uses: actions/setup-node@v3
|
19
21
|
with:
|
20
22
|
node-version: ${{ matrix.node }}
|
21
23
|
cache: yarn
|
@@ -29,7 +29,9 @@ jobs:
|
|
29
29
|
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
30
30
|
|
31
31
|
steps:
|
32
|
-
- uses: actions/checkout@
|
32
|
+
- uses: actions/checkout@v4
|
33
|
+
with:
|
34
|
+
persist-credentials: false
|
33
35
|
- uses: ruby/setup-ruby@v1
|
34
36
|
with:
|
35
37
|
ruby-version: ${{ matrix.ruby }}
|
@@ -37,3 +39,9 @@ jobs:
|
|
37
39
|
|
38
40
|
- name: Ruby specs - Backward compatibility
|
39
41
|
run: bundle exec rake run_spec:gem_bc
|
42
|
+
env:
|
43
|
+
SHAKAPACKER_USE_PACKAGE_JSON_GEM: "false"
|
44
|
+
- name: Ruby specs - Backward compatibility
|
45
|
+
run: bundle exec rake run_spec:gem_bc
|
46
|
+
env:
|
47
|
+
SHAKAPACKER_USE_PACKAGE_JSON_GEM: "true"
|
data/.github/workflows/ruby.yml
CHANGED
@@ -29,11 +29,20 @@ jobs:
|
|
29
29
|
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
30
30
|
|
31
31
|
steps:
|
32
|
-
- uses: actions/checkout@
|
32
|
+
- uses: actions/checkout@v4
|
33
|
+
with:
|
34
|
+
persist-credentials: false
|
33
35
|
- uses: ruby/setup-ruby@v1
|
34
36
|
with:
|
35
37
|
ruby-version: ${{ matrix.ruby }}
|
36
38
|
bundler-cache: true
|
37
39
|
|
38
40
|
- name: Ruby specs
|
39
|
-
run: bundle exec rake run_spec:
|
41
|
+
run: bundle exec rake run_spec:gem
|
42
|
+
env:
|
43
|
+
SHAKAPACKER_USE_PACKAGE_JSON_GEM: "false"
|
44
|
+
|
45
|
+
- name: Ruby specs
|
46
|
+
run: bundle exec rake run_spec:gem
|
47
|
+
env:
|
48
|
+
SHAKAPACKER_USE_PACKAGE_JSON_GEM: "true"
|
data/CHANGELOG.md
CHANGED
@@ -5,13 +5,25 @@
|
|
5
5
|
|
6
6
|
## Versions
|
7
7
|
## [Unreleased]
|
8
|
-
Changes since last non-beta release.
|
8
|
+
Changes since the last non-beta release.
|
9
9
|
|
10
10
|
_Please add entries here for your pull requests that are not yet released._
|
11
11
|
|
12
|
+
### Added
|
13
|
+
- Experimental support for other JS package managers using `package_json` gem [PR 349](https://github.com/shakacode/shakapacker/pull/349) by [G-Rath](https://github.com/g-rath).
|
14
|
+
|
15
|
+
## [v7.1.0] - September 30, 2023
|
16
|
+
|
17
|
+
### Added
|
18
|
+
- Support passing custom webpack config directly to `generateWebpackConfig` for merging [PR 343](https://github.com/shakacode/shakapacker/pull/343) by [G-Rath](https://github.com/g-rath).
|
19
|
+
|
20
|
+
### Fixed
|
21
|
+
- Use `NODE_OPTIONS` to enable Node-specific debugging flags [PR 350](https://github.com/shakacode/shakapacker/pull/350).
|
22
|
+
- Add the boilerplate `application.js` into `packs/` [PR 363](https://github.com/shakacode/shakapacker/pull/363).
|
23
|
+
|
12
24
|
## [v7.0.3] - July 7, 2023
|
13
25
|
### Fixed
|
14
|
-
- Fixed commands execution for projects with space in absolute path [PR 322](https://github.com/shakacode/shakapacker/pull/322) by [kukicola](https://github.com/kukicola).
|
26
|
+
- Fixed commands execution for projects with space in the absolute path [PR 322](https://github.com/shakacode/shakapacker/pull/322) by [kukicola](https://github.com/kukicola).
|
15
27
|
|
16
28
|
## [v7.0.2] - July 3, 2023
|
17
29
|
### Fixed
|
@@ -267,7 +279,8 @@ Note: [Rubygem is 6.3.0.pre.rc.1](https://rubygems.org/gems/shakapacker/versions
|
|
267
279
|
## v5.4.3 and prior changes from rails/webpacker
|
268
280
|
See [CHANGELOG.md in rails/webpacker (up to v5.4.3)](https://github.com/rails/webpacker/blob/master/CHANGELOG.md)
|
269
281
|
|
270
|
-
[Unreleased]: https://github.com/shakacode/shakapacker/compare/v7.0
|
282
|
+
[Unreleased]: https://github.com/shakacode/shakapacker/compare/v7.1.0...master
|
283
|
+
[v7.1.0]: https://github.com/shakacode/shakapacker/compare/v7.0.3...v7.1.0
|
271
284
|
[v7.0.3]: https://github.com/shakacode/shakapacker/compare/v7.0.2...v7.0.3
|
272
285
|
[v7.0.2]: https://github.com/shakacode/shakapacker/compare/v7.0.1...v7.0.2
|
273
286
|
[v7.0.1]: https://github.com/shakacode/shakapacker/compare/v7.0.0...v7.0.1
|
data/README.md
CHANGED
@@ -51,6 +51,7 @@ Read the [full review here](https://clutch.co/profile/shakacode#reviews?sort_by=
|
|
51
51
|
- [Optional support](#optional-support)
|
52
52
|
- [Installation](#installation)
|
53
53
|
- [Rails v6+](#rails-v6)
|
54
|
+
- [Using alternative package managers](#using-alternative-package-managers)
|
54
55
|
- [Note for Yarn v2 usage](#note-for-yarn-v2-usage)
|
55
56
|
- [Concepts](#concepts)
|
56
57
|
- [Usage](#usage)
|
@@ -163,9 +164,21 @@ yarn add @babel/core @babel/plugin-transform-runtime @babel/preset-env @babel/ru
|
|
163
164
|
Previously, these "webpack" and "babel" packages were direct dependencies for `shakapacker`. By
|
164
165
|
making these peer dependencies, you have control over the versions used in your webpack and babel configs.
|
165
166
|
|
167
|
+
### Using alternative package managers
|
168
|
+
|
169
|
+
There is experimental support for using package managers besides Yarn classic for managing JavaScript dependencies using the [`package_json`](https://github.com/G-Rath/package_json) gem.
|
170
|
+
|
171
|
+
This can be enabled by setting the environment variable `SHAKAPACKER_USE_PACKAGE_JSON_GEM` to `true`; Shakapacker will then use the `package_json` gem which in turn will look for the [`packageManager`](https://nodejs.org/api/packages.html#packagemanager) property in the `package.json` or otherwise the `PACKAGE_JSON_FALLBACK_MANAGER` environment variable to determine which manager to use, defaulting to `npm` if neither are found.
|
172
|
+
|
173
|
+
See [here](https://github.com/G-Rath/package_json#specifying-a-package-manager) for a list of the supported package managers and more information; note that `package_json` does not handle ensuring the manager is installed.
|
174
|
+
|
175
|
+
> **Note**
|
176
|
+
>
|
177
|
+
> The rest of the documentation assumes that `package_json` is not being used, and so always references `yarn` - you should instead use the package manager of your choice for these commands.
|
178
|
+
|
166
179
|
### Note for Yarn v2 usage
|
167
180
|
|
168
|
-
If you are using Yarn v2 (berry), please note that PnP modules are not supported
|
181
|
+
If you are using Yarn v2 (berry), please note that PnP modules are not supported unless you're using `SHAKAPACKER_USE_PACKAGE_JSON_GEM`.
|
169
182
|
|
170
183
|
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 behavior.
|
171
184
|
|
@@ -272,7 +285,11 @@ Note, the default of "defer" for the `javascript_pack_tag`. You can override tha
|
|
272
285
|
<%= javascript_pack_tag 'calendar' %>
|
273
286
|
<%= javascript_pack_tag 'map' %>
|
274
287
|
```
|
275
|
-
|
288
|
+
|
289
|
+
While this also generally applies to `stylesheet_pack_tag`,
|
290
|
+
you may use multiple calls to stylesheet_pack_tag if,
|
291
|
+
say,
|
292
|
+
you require multiple `<style>` tags for different output media:
|
276
293
|
|
277
294
|
``` erb
|
278
295
|
<%= stylesheet_pack_tag 'application', media: 'screen' %>
|
@@ -417,7 +434,16 @@ In production or CI environments, the `digest` strategy is more suitable, unless
|
|
417
434
|
|
418
435
|
You can control what strategy is used by the `compiler_strategy` option in `shakapacker.yml` config file. By default `mtime` strategy is used in development environment, `digest` is used elsewhere.
|
419
436
|
|
420
|
-
**Note:**
|
437
|
+
**Note:**
|
438
|
+
If you are not using the `shakapacker-dev-server`,
|
439
|
+
your packs will be served by the Rails public file server.
|
440
|
+
If you've enabled caching
|
441
|
+
(Rails application `config.action_controller.perform_caching` setting),
|
442
|
+
your changes will likely not be picked up due to `Cache-Control` header being set
|
443
|
+
and
|
444
|
+
assets being cached in the browser memory.
|
445
|
+
For more details see
|
446
|
+
[issue 88: Caching issues in Development since migrating to Shakapacker](https://github.com/shakacode/shakapacker/issues/88).
|
421
447
|
|
422
448
|
If you want to use live code reloading, or you have enough JavaScript that on-demand compilation is too slow, you'll need to run `./bin/shakapacker-dev-server`. This process will watch for changes in the relevant files, defined by `shakapacker.yml` configuration settings for `source_path`, `source_entry_path`, and `additional_paths`, and it will then automatically reload the browser to match. This feature is also known as [Hot Module Replacement](https://webpack.js.org/concepts/hot-module-replacement/).
|
423
449
|
|
@@ -465,26 +491,40 @@ First, you don't _need_ to use Shakapacker's webpack configuration. However, the
|
|
465
491
|
|
466
492
|
1. Your output files go to the right directory
|
467
493
|
2. Your output includes a manifest, via package [`webpack-assets-manifest`](https://github.com/webdeveric/webpack-assets-manifest) that maps output names (your 'packs') to the fingerprinted versions, including bundle-splitting dependencies. That's the main secret sauce of Shakapacker!
|
494
|
+
|
495
|
+
The webpack configuration used by Shakapacker lives in `config/webpack/webpack.config.js`; this makes it easy to customize the configuration beyond what's available in `config/shakapacker.yml` by giving you complete control of the final configuration. By default, this file exports the result of `generateWebpackConfig` which handles generating a webpack configuration based on `config/shakapacker.yml`.
|
468
496
|
|
469
|
-
The
|
497
|
+
The easiest way to modify this config is to pass your desired customizations to `generateWebpackConfig` which will use [webpack-merge](https://github.com/survivejs/webpack-merge) to merge them with the configuration generated from `config/shakapacker.yml`:
|
470
498
|
|
471
499
|
```js
|
472
|
-
//
|
473
|
-
|
500
|
+
// config/webpack/webpack.config.js
|
501
|
+
const { generateWebpackConfig } = require('shakapacker')
|
502
|
+
|
503
|
+
const options = {
|
504
|
+
resolve: {
|
505
|
+
extensions: ['.css', '.ts', '.tsx']
|
506
|
+
}
|
507
|
+
}
|
508
|
+
|
509
|
+
// This results in a new object copied from the mutable global
|
510
|
+
module.exports = generateWebpackConfig(options)
|
511
|
+
```
|
512
|
+
|
513
|
+
The `shakapacker` package also exports the `merge` function from [webpack-merge](https://github.com/survivejs/webpack-merge) to make it easier to do more advanced customizations:
|
514
|
+
|
515
|
+
```js
|
516
|
+
// config/webpack/webpack.config.js
|
474
517
|
const { generateWebpackConfig, merge } = require('shakapacker')
|
475
518
|
|
476
|
-
const
|
519
|
+
const webpackConfig = generateWebpackConfig()
|
477
520
|
|
478
521
|
const options = {
|
479
522
|
resolve: {
|
480
|
-
|
523
|
+
extensions: ['.css', '.ts', '.tsx']
|
481
524
|
}
|
482
525
|
}
|
483
526
|
|
484
|
-
|
485
|
-
// If you want to use this object for client and server rendering configurations,
|
486
|
-
// having a new object is essential.
|
487
|
-
module.exports = merge({}, baseWebpackConfig, options)
|
527
|
+
module.exports = merge(options, webpackConfig)
|
488
528
|
```
|
489
529
|
|
490
530
|
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)
|
@@ -513,12 +553,11 @@ Then `require` this file in your `config/webpack/webpack.config.js`:
|
|
513
553
|
```js
|
514
554
|
// config/webpack/webpack.config.js
|
515
555
|
// use the new NPM package name, `shakapacker`.
|
516
|
-
const { generateWebpackConfig
|
556
|
+
const { generateWebpackConfig } = require('shakapacker')
|
517
557
|
|
518
|
-
const webpackConfig = generateWebpackConfig()
|
519
558
|
const customConfig = require('./custom')
|
520
559
|
|
521
|
-
module.exports =
|
560
|
+
module.exports = generateWebpackConfig(customConfig)
|
522
561
|
```
|
523
562
|
|
524
563
|
If you need access to configs within Shakapacker's configuration, you can import them like so:
|
@@ -616,12 +655,10 @@ Then modify the webpack config to use it as a plugin:
|
|
616
655
|
|
617
656
|
```js
|
618
657
|
// config/webpack/webpack.config.js
|
619
|
-
const { generateWebpackConfig
|
620
|
-
|
621
|
-
const webpackConfig = generateWebpackConfig()
|
658
|
+
const { generateWebpackConfig } = require("shakapacker");
|
622
659
|
const ForkTSCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
|
623
660
|
|
624
|
-
module.exports =
|
661
|
+
module.exports = generateWebpackConfig({
|
625
662
|
plugins: [new ForkTSCheckerWebpackPlugin()],
|
626
663
|
});
|
627
664
|
```
|
@@ -638,9 +675,7 @@ Optionally, add the `CSS` extension to webpack config for easy resolution.
|
|
638
675
|
|
639
676
|
```js
|
640
677
|
// config/webpack/webpack.config.js
|
641
|
-
const { generateWebpackConfig
|
642
|
-
|
643
|
-
const webpackConfig = generateWebpackConfig()
|
678
|
+
const { generateWebpackConfig } = require('shakapacker')
|
644
679
|
|
645
680
|
const customConfig = {
|
646
681
|
resolve: {
|
@@ -648,7 +683,7 @@ const customConfig = {
|
|
648
683
|
}
|
649
684
|
}
|
650
685
|
|
651
|
-
module.exports =
|
686
|
+
module.exports = generateWebpackConfig(customConfig)
|
652
687
|
```
|
653
688
|
|
654
689
|
To enable `PostCSS`, `Sass` or `Less` support, add `CSS` support first and
|
data/docs/troubleshooting.md
CHANGED
@@ -150,11 +150,9 @@ To silent these warnings, please update `config/webpack/webpack.config.js`:
|
|
150
150
|
```js
|
151
151
|
const webpack = require('webpack')
|
152
152
|
const { resolve } = require('path')
|
153
|
-
const { generateWebpackConfig
|
153
|
+
const { generateWebpackConfig } = require('shakapacker')
|
154
154
|
|
155
|
-
|
156
|
-
|
157
|
-
module.exports = merge(webpackConfig, {
|
155
|
+
module.exports = generateWebpackConfig({
|
158
156
|
plugins: [
|
159
157
|
new webpack.ContextReplacementPlugin(
|
160
158
|
/angular(\\|\/)core(\\|\/)(@angular|esm5)/,
|
@@ -201,11 +199,9 @@ Instead do:
|
|
201
199
|
// config/webpack/webpack.config.js
|
202
200
|
|
203
201
|
const webpack = require('webpack')
|
204
|
-
const { generateWebpackConfig
|
205
|
-
|
206
|
-
const webpackConfig = generateWebpackConfig();
|
202
|
+
const { generateWebpackConfig } = require('shakapacker')
|
207
203
|
|
208
|
-
module.exports =
|
204
|
+
module.exports = generateWebpackConfig({
|
209
205
|
plugins: [
|
210
206
|
new webpack.ProvidePlugin({
|
211
207
|
$: 'jquery',
|
@@ -59,11 +59,9 @@ o do so, you need to modify your webpack configuration and use `ESBuildMinifyPlu
|
|
59
59
|
Example:
|
60
60
|
|
61
61
|
```js
|
62
|
-
const { generateWebpackConfig
|
62
|
+
const { generateWebpackConfig } = require('shakapacker')
|
63
63
|
const { ESBuildMinifyPlugin } = require('esbuild-loader')
|
64
64
|
|
65
|
-
const baseWebpackConfig = generateWebpackConfig()
|
66
|
-
|
67
65
|
const options = {
|
68
66
|
optimization: {
|
69
67
|
minimizer: [
|
@@ -74,7 +72,7 @@ const options = {
|
|
74
72
|
}
|
75
73
|
}
|
76
74
|
|
77
|
-
module.exports =
|
75
|
+
module.exports = generateWebpackConfig(options)
|
78
76
|
```
|
79
77
|
|
80
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.
|
data/docs/v6_upgrade.md
CHANGED
@@ -101,7 +101,7 @@ _If you're on webpacker v5, follow [how to upgrade to webpacker v6.0.0.rc.6 from
|
|
101
101
|
|
102
102
|
1. Update `webpack-dev-server` to the current version, greater than 4.2, updating `package.json`.
|
103
103
|
|
104
|
-
1. Update API usage of the view helpers by changing `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` to `javascript_pack_tag` and `stylesheet_pack_tag`. Ensure that your layouts and views will only have **at most one call** to `javascript_pack_tag` and **at most one call** to `stylesheet_pack_tag`. You can now pass multiple bundles to these view helper methods. If you fail to changes this, you may experience performance issues, and other bugs related to multiple copies of React, like [issue 2932](https://github.com/rails/webpacker/issues/2932). If you expose jquery globally with `expose-loader
|
104
|
+
1. Update API usage of the view helpers by changing `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` to `javascript_pack_tag` and `stylesheet_pack_tag`. Ensure that your layouts and views will only have **at most one call** to `javascript_pack_tag` and **at most one call** to `stylesheet_pack_tag`. You can now pass multiple bundles to these view helper methods. If you fail to changes this, you may experience performance issues, and other bugs related to multiple copies of React, like [issue 2932](https://github.com/rails/webpacker/issues/2932). If you expose jquery globally with `expose-loader` by using `import $ from "expose-loader?exposes=$,jQuery!jquery"` in your `app/javascript/application.js`, pass the option `defer: false` to your `javascript_pack_tag`.
|
105
105
|
|
106
106
|
1. If you are using any integrations like `css`, `postcss`, `React` or `TypeScript`. Please see https://github.com/shakacode/shakapacker#integrations section on how they work in v6.
|
107
107
|
|
data/lib/install/template.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "shakapacker/utils/misc"
|
1
2
|
require "shakapacker/utils/version_syntax_converter"
|
2
3
|
|
3
4
|
# Install Shakapacker
|
@@ -14,8 +15,8 @@ if Dir.exist?(Shakapacker.config.source_path)
|
|
14
15
|
say "The packs app source directory already exists"
|
15
16
|
else
|
16
17
|
say "Creating packs app source directory"
|
17
|
-
empty_directory "app/javascript"
|
18
|
-
copy_file "#{__dir__}/application.js", "app/javascript/application.js"
|
18
|
+
empty_directory "app/javascript/packs"
|
19
|
+
copy_file "#{__dir__}/application.js", "app/javascript/packs/application.js"
|
19
20
|
end
|
20
21
|
|
21
22
|
apply "#{__dir__}/binstubs.rb"
|
@@ -41,12 +42,28 @@ else
|
|
41
42
|
say %( Add <%= javascript_pack_tag "application" %> within the <head> tag in your custom layout.)
|
42
43
|
end
|
43
44
|
|
45
|
+
def package_json
|
46
|
+
if @package_json.nil?
|
47
|
+
Shakapacker::Utils::Misc.require_package_json_gem
|
48
|
+
|
49
|
+
@package_json = PackageJson.read
|
50
|
+
end
|
51
|
+
|
52
|
+
@package_json
|
53
|
+
end
|
54
|
+
|
44
55
|
# Ensure there is `system!("bin/yarn")` command in `./bin/setup` file
|
45
56
|
if (setup_path = Rails.root.join("bin/setup")).exist?
|
46
|
-
|
57
|
+
def native_install_command
|
58
|
+
return "bin/yarn" unless Shakapacker::Utils::Misc.use_package_json_gem
|
59
|
+
|
60
|
+
package_json.manager.native_install_command.join(" ")
|
61
|
+
end
|
62
|
+
|
63
|
+
say "Run #{native_install_command} during bin/setup"
|
47
64
|
|
48
65
|
if File.read(setup_path).match? Regexp.escape(" # system('bin/yarn')\n")
|
49
|
-
gsub_file(setup_path, "# system('bin/yarn')", "system!('
|
66
|
+
gsub_file(setup_path, "# system('bin/yarn')", "system!('#{native_install_command}')")
|
50
67
|
else
|
51
68
|
# Due to the inconsistency of quotation usage in Rails 7 compared to
|
52
69
|
# earlier versions, we check both single and double quotations here.
|
@@ -55,30 +72,58 @@ if (setup_path = Rails.root.join("bin/setup")).exist?
|
|
55
72
|
string_to_add = <<-RUBY
|
56
73
|
|
57
74
|
# Install JavaScript dependencies
|
58
|
-
system!("
|
59
|
-
RUBY
|
75
|
+
system!("#{native_install_command}")
|
76
|
+
RUBY
|
60
77
|
|
61
78
|
if File.read(setup_path).match? pattern
|
62
79
|
insert_into_file(setup_path, string_to_add, after: pattern)
|
63
80
|
else
|
64
81
|
say <<~MSG, :red
|
65
82
|
It seems your `bin/setup` file doesn't have the expected content.
|
66
|
-
Please review the file and manually add `system!("
|
83
|
+
Please review the file and manually add `system!("#{native_install_command}")` before any
|
67
84
|
other command that requires JavaScript dependencies being already installed.
|
68
85
|
MSG
|
69
86
|
end
|
70
87
|
end
|
71
88
|
end
|
72
89
|
|
73
|
-
|
90
|
+
def add_dependencies(dependencies, type)
|
91
|
+
return package_json.manager.add!(dependencies, type: type) if Shakapacker::Utils::Misc.use_package_json_gem
|
92
|
+
|
93
|
+
# TODO: check that run actually errors
|
94
|
+
run("yarn add #{dependencies.join(" ")}") if type == :production
|
95
|
+
run("yarn add --dev #{dependencies.join(" ")}") if type == :dev
|
96
|
+
rescue PackageJson::Error
|
97
|
+
say "Shakapacker installation failed 😭 See above for details.", :red
|
98
|
+
exit 1
|
99
|
+
end
|
100
|
+
|
101
|
+
def fetch_peer_dependencies
|
102
|
+
if Shakapacker::Utils::Misc.use_package_json_gem
|
103
|
+
return PackageJson.read("#{__dir__}/../../").fetch("peerDependencies")
|
104
|
+
end
|
105
|
+
|
106
|
+
package_json = File.read("#{__dir__}/../../package.json")
|
107
|
+
JSON.parse(package_json)["peerDependencies"]
|
108
|
+
end
|
74
109
|
|
75
110
|
Dir.chdir(Rails.root) do
|
76
111
|
npm_version = Shakapacker::Utils::VersionSyntaxConverter.new.rubygem_to_npm(Shakapacker::VERSION)
|
77
112
|
say "Installing shakapacker@#{npm_version}"
|
78
|
-
|
113
|
+
add_dependencies(["shakapacker@#{npm_version}"], :production)
|
114
|
+
|
115
|
+
if Shakapacker::Utils::Misc.use_package_json_gem
|
116
|
+
package_json.merge! do |pj|
|
117
|
+
{
|
118
|
+
"dependencies" => pj["dependencies"].merge({
|
119
|
+
# TODO: workaround for test suite - long-run need to actually account for diff pkg manager behaviour
|
120
|
+
"shakapacker" => pj["dependencies"]["shakapacker"].delete_prefix("^")
|
121
|
+
})
|
122
|
+
}
|
123
|
+
end
|
124
|
+
end
|
79
125
|
|
80
|
-
|
81
|
-
peers = JSON.parse(package_json)["peerDependencies"]
|
126
|
+
peers = fetch_peer_dependencies
|
82
127
|
dev_dependency_packages = ["webpack-dev-server"]
|
83
128
|
|
84
129
|
dependencies_to_add = []
|
@@ -96,13 +141,8 @@ Dir.chdir(Rails.root) do
|
|
96
141
|
end
|
97
142
|
|
98
143
|
say "Adding shakapacker peerDependencies"
|
99
|
-
|
144
|
+
add_dependencies(dependencies_to_add, :production)
|
100
145
|
|
101
146
|
say "Installing webpack-dev-server for live reloading as a development dependency"
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
|
-
unless results.all?
|
106
|
-
say "Shakapacker installation failed 😭 See above for details.", :red
|
107
|
-
exit 1
|
147
|
+
add_dependencies(dev_dependencies_to_add, :dev)
|
108
148
|
end
|
data/lib/shakapacker/compiler.rb
CHANGED
@@ -106,9 +106,11 @@ class Shakapacker::Compiler
|
|
106
106
|
|
107
107
|
Shakapacker.set_shakapacker_env_variables_for_backward_compatibility
|
108
108
|
|
109
|
-
env.merge(
|
110
|
-
|
111
|
-
|
109
|
+
env.merge(
|
110
|
+
"SHAKAPACKER_ASSET_HOST" => instance.config.asset_host,
|
111
|
+
"SHAKAPACKER_RELATIVE_URL_ROOT" => instance.config.relative_url_root,
|
112
|
+
"SHAKAPACKER_CONFIG" => instance.config_path.to_s
|
113
|
+
)
|
112
114
|
end
|
113
115
|
|
114
116
|
def bin_shakapacker_path
|
@@ -116,6 +116,14 @@ class Shakapacker::Configuration
|
|
116
116
|
data.fetch(key, defaults[:shakapacker_precompile])
|
117
117
|
end
|
118
118
|
|
119
|
+
def asset_host
|
120
|
+
ENV.fetch("SHAKAPACKER_ASSET_HOST", ActionController::Base.helpers.compute_asset_host)
|
121
|
+
end
|
122
|
+
|
123
|
+
def relative_url_root
|
124
|
+
ENV.fetch("SHAKAPACKER_RELATIVE_URL_ROOT", ActionController::Base.relative_url_root)
|
125
|
+
end
|
126
|
+
|
119
127
|
private
|
120
128
|
def data
|
121
129
|
@data ||= load
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "thor"
|
2
2
|
|
3
3
|
module Shakapacker
|
4
|
-
DEPRECATION_GUIDE_URL = "https://github.com/shakacode/shakapacker/docs/v7_upgrade.md"
|
4
|
+
DEPRECATION_GUIDE_URL = "https://github.com/shakacode/shakapacker/blob/master/docs/v7_upgrade.md"
|
5
5
|
DEPRECATION_MESSAGE = <<~MSG
|
6
6
|
DEPRECATION NOTICE:
|
7
7
|
|
@@ -66,12 +66,9 @@ module Shakapacker
|
|
66
66
|
env = Shakapacker::Compiler.env
|
67
67
|
env["SHAKAPACKER_CONFIG"] = @shakapacker_config
|
68
68
|
env["WEBPACK_SERVE"] = "true"
|
69
|
+
env["NODE_OPTIONS"] = ENV["NODE_OPTIONS"] || ""
|
69
70
|
|
70
|
-
cmd =
|
71
|
-
["#{@node_modules_bin_path}/webpack", "serve"]
|
72
|
-
else
|
73
|
-
["yarn", "webpack", "serve"]
|
74
|
-
end
|
71
|
+
cmd = build_cmd
|
75
72
|
|
76
73
|
if @argv.include?("--debug-webpacker")
|
77
74
|
Shakapacker.puts_deprecation_message(
|
@@ -83,7 +80,7 @@ module Shakapacker
|
|
83
80
|
end
|
84
81
|
|
85
82
|
if @argv.delete("--debug-shakapacker") || @argv.delete("--debug-webpacker")
|
86
|
-
|
83
|
+
env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --inspect-brk --trace-warnings"
|
87
84
|
end
|
88
85
|
|
89
86
|
cmd += ["--config", @webpack_config]
|
@@ -97,6 +94,16 @@ module Shakapacker
|
|
97
94
|
end
|
98
95
|
end
|
99
96
|
|
97
|
+
def build_cmd
|
98
|
+
if Shakapacker::Utils::Misc.use_package_json_gem
|
99
|
+
return package_json.manager.native_exec_command("webpack", ["serve"])
|
100
|
+
end
|
101
|
+
|
102
|
+
return ["#{@node_modules_bin_path}/webpack", "serve"] if node_modules_bin_exist?
|
103
|
+
|
104
|
+
["yarn", "webpack", "serve"]
|
105
|
+
end
|
106
|
+
|
100
107
|
def node_modules_bin_exist?
|
101
108
|
File.exist?("#{@node_modules_bin_path}/webpack-dev-server")
|
102
109
|
end
|
data/lib/shakapacker/runner.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "shakapacker/utils/misc"
|
2
|
+
|
1
3
|
module Shakapacker
|
2
4
|
class Runner
|
3
5
|
def self.run(argv)
|
@@ -14,7 +16,7 @@ module Shakapacker
|
|
14
16
|
|
15
17
|
Shakapacker.set_shakapacker_env_variables_for_backward_compatibility
|
16
18
|
|
17
|
-
@node_modules_bin_path =
|
19
|
+
@node_modules_bin_path = fetch_node_modules_bin_path
|
18
20
|
@shakapacker_config = ENV["SHAKAPACKER_CONFIG"] || File.join(@app_path, "config/shakapacker.yml")
|
19
21
|
|
20
22
|
@shakapacker_config = Shakapacker.get_config_file_path_with_backward_compatibility(@shakapacker_config)
|
@@ -24,5 +26,21 @@ module Shakapacker
|
|
24
26
|
exit!
|
25
27
|
end
|
26
28
|
end
|
29
|
+
|
30
|
+
def fetch_node_modules_bin_path
|
31
|
+
return nil if Shakapacker::Utils::Misc.use_package_json_gem
|
32
|
+
|
33
|
+
ENV["SHAKAPACKER_NODE_MODULES_BIN_PATH"] || `yarn bin`.chomp
|
34
|
+
end
|
35
|
+
|
36
|
+
def package_json
|
37
|
+
if @package_json.nil?
|
38
|
+
Shakapacker::Utils::Misc.require_package_json_gem
|
39
|
+
|
40
|
+
@package_json = PackageJson.read(@app_path)
|
41
|
+
end
|
42
|
+
|
43
|
+
@package_json
|
44
|
+
end
|
27
45
|
end
|
28
46
|
end
|