shakapacker 6.0.0.rc.12 → 6.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ba657aae9dfeb59090b6199029f76386c42623c57f3a97a95f91ef34e6aafc6
4
- data.tar.gz: 26ee13bf4652772256fd0ef3e2e1e2013a08bde979172660ec4c17778fe8f582
3
+ metadata.gz: 3ecb405340a0fa5b44d13390860eaccbaf8ec55524e1e7ce56189274abbd400c
4
+ data.tar.gz: '0288c90b0b9675d165aad967b0c9ae7d9b4af2a59d788f1dde34434db0e37c36'
5
5
  SHA512:
6
- metadata.gz: 95e60f443c8cff3af9c486e5654b6c57ee6a8a47458659ba6df09c4ed59eef16822c8de9d39b4e877b93e7a235230c9a176763ae1c2e6bb762fd721a99a5edf9
7
- data.tar.gz: ae7fcfed84f078ad216b48dcd4d5f227819132e30f642ffaa2fbe5b566aa6c29e4ae46d49da7e769947228be877829bac60ae13e93cb359e9400a0a6fa2786f1
6
+ metadata.gz: ccd9911ec6c1a53ddc173bb86d5d87e714c174c41a28c4d6211544c25b2e39a7b72c85ed19cd7306ec7bcdeece73435071a86c1ae905fb2a8f995a0da8650b78
7
+ data.tar.gz: db5eff828636edf6a341c1aa2e0f89a6e58e7a476da0b908d38fbabe5b967b7dd1cee5a7fca6771fc5bc0dfc544ddcd64dc5e0fc72765b1f9f0116614c159bbf
data/CHANGELOG.md CHANGED
@@ -1,13 +1,22 @@
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
-
1
+ * For versions prior to v6, see the [5.x stable branch of rails/webpacker](https://github.com/rails/webpacker/tree/5-x-stable).
2
+ * Please see [UPGRADE GUIDE](./docs/v6_upgrade.md).
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
+ ## [v6.0.1] - January 24, 2022
10
+ ### Improved
11
+ - PR #21 removed pnp-webpack-plugin as a dev dependency but did not remove it from the peer dependency list. [PR 30](https://github.com/shakacode/shakapacker/pull/19) by [t27duck](https://github.com/t27duck].
12
+
13
+ ## [v6.0.0 changes from v6.0.0.rc.6] - January 22, 2022
14
+
15
+ ### Improved
16
+ - Raise on multiple invocations of javascript_pack_tag and stylesheet_pack_tag helpers. [PR 19](https://github.com/shakacode/shakapacker/pull/19) by [tomdracz](https://github.com/tomdracz].
17
+ - Remove automatic addition of node_modules into rails asset load path. [PR 20](https://github.com/shakacode/shakapacker/pull/20) by [tomdracz](https://github.com/tomdracz].
18
+ - Remove pnp-webpack-plugin. [PR 21](https://github.com/shakacode/shakapacker/pull/21) by [tomdracz](https://github.com/tomdracz].
9
19
 
10
- ## [6.0.0.rc.12]
11
20
 
12
21
  ### Merged from rails/webpacker
13
22
 
@@ -20,11 +29,9 @@ Changes since last non-beta release.
20
29
  to `config/webpack/#{NODE_ENV}.js`.
21
30
  - Changed all package.json dependencies to peerDependencies, so upgrading requires adding the dependencies, per the [UPGRADE GUIDE](./docs/v6_upgrade.md).
22
31
 
23
- ## [6.0.0.rc.6] - Forked January 16, 2022
32
+ ## [v6.0.0.rc.6 changes from v5.4] - Forked January 16, 2022
24
33
 
25
- Latest is rc.9.
26
34
 
27
- Please see [UPGRADE GUIDE](./docs/v6_upgrade.md) for more information.
28
35
  - `node_modules` will no longer be babel transfomed compiled by default. This primarily fixes [rails issue #35501](https://github.com/rails/rails/issues/35501) as well as [numerous other webpacker issues](https://github.com/rails/webpacker/issues/2131#issuecomment-581618497). The disabled loader can still be required explicitly via:
29
36
 
30
37
  ```js
@@ -48,6 +55,7 @@ Please see [UPGRADE GUIDE](./docs/v6_upgrade.md) for more information.
48
55
  - CSS extraction enabled by default, except when devServer is configured and running
49
56
 
50
57
 
51
- [Unreleased]: https://github.com/shakacode/shakapacker/compare/6.0.0-rc.11...master
52
- [6.0.0.rc.12]: https://github.com/shakacode/shakapacker/compare/aba79635e6ff6562ec04d3c446d57ef19a5fef7d...6.0.0-rc.12
53
- [6.0.0.rc.6]: https://github.com/rails/webpacker/compare/v5.4.3...aba79635e6ff6562ec04d3c446d57ef19a5fef7d
58
+ [Unreleased]: https://github.com/shakacode/shakapacker/compare/6.0.1...master
59
+ [v6.0.1]: https://github.com/shakacode/shakapacker/compare/v6.0.0...v6.0.1
60
+ [v6.0.0 changes from v6.0.0.rc.6]: https://github.com/shakacode/shakapacker/compare/aba79635e6ff6562ec04d3c446d57ef19a5fef7d...v6.0.0
61
+ [v6.0.0.rc.6 changes from v5.4]: https://github.com/rails/webpacker/compare/v5.4.3...aba79635e6ff6562ec04d3c446d57ef19a5fef7d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shakapacker (6.0.0.rc.6)
4
+ shakapacker (6.0.0.rc.13)
5
5
  activesupport (>= 5.2)
6
6
  rack-proxy (>= 0.6.1)
7
7
  railties (>= 5.2)
data/README.md CHANGED
@@ -1,16 +1,16 @@
1
1
  # Shakapacker
2
2
 
3
- _Actively maintained fork of [rails/webpacker](https://github.com/rails/webpacker). For pre v6, see [rails/webpacker 5-x-stable](https://github.com/rails/webpacker/tree/5-x-stable). Be sure to see the [CHANGELOG](./CHANGELOG.md)._
4
-
5
- Note, internal naming will continue to use `webpacker` where possible.
3
+ _Official, actively maintained fork of [rails/webpacker](https://github.com/rails/webpacker). Internal naming for `shakapacker` will continue to use `webpacker` where possible. Notably, the NPM package name is `shakapacker`._
4
+ * See [V6 Upgrade](./docs/v6_upgrade.md) for upgrading from v5 or prior v6 releases.
6
5
 
7
6
  [![Ruby specs](https://github.com/shakacode/shakapacker/workflows/Ruby%20specs/badge.svg)](https://github.com/shakacode/shakapacker/actions)
8
7
  [![Jest specs](https://github.com/shakacode/shakapacker/workflows/Jest%20specs/badge.svg)](https://github.com/shakacode/shakapacker/actions)
9
8
  [![Rubocop](https://github.com/shakacode/shakapacker/workflows/Rubocop/badge.svg)](https://github.com/shakacode/shakapacker/actions)
10
9
  [![JS lint](https://github.com/shakacode/shakapacker/workflows/JS%20lint/badge.svg)](https://github.com/shakacode/shakapacker/actions)
11
10
 
12
- [![node.js](https://img.shields.io/badge/node-%3E%3D%2012.0.0-brightgreen.svg)](https://www.npmjs.com/package/@shakacode/shakapacker)
11
+ [![node.js](https://img.shields.io/badge/node-%3E%3D%2012.0.0-brightgreen.svg)](https://www.npmjs.com/package/shakapacker)
13
12
  [![Gem](https://img.shields.io/gem/v/shakapacker.svg)](https://rubygems.org/gems/shakapacker)
13
+ [![npm version](https://badge.fury.io/js/shakapacker.svg)](https://badge.fury.io/js/shakapacker)
14
14
 
15
15
  Webpacker makes it easy to use the JavaScript pre-processor and bundler
16
16
  [Webpack v5](https://webpack.js.org/)
@@ -19,8 +19,6 @@ leaving Webpack responsible solely for app-like JavaScript, or it can be used ex
19
19
 
20
20
  See a comparison of [webpacker with jsbundling-rails](https://github.com/rails/jsbundling-rails/blob/main/docs/comparison_with_webpacker.md).
21
21
 
22
- Visit [Shipping Webpacker v6 – Status](https://discuss.rubyonrails.org/t/shipping-webpacker-v6-status/79683) for the latest news on a v6 release.
23
-
24
22
  Discussion forums to discuss debugging and troubleshooting tips. Please open issues for bugs and feature requests:
25
23
  1. [rails/webpacker discussion forum](https://discuss.rubyonrails.org/c/webpacker/10)
26
24
  2. [Discussions tab](https://github.com/shakacode/shakapacker/discussions)
@@ -37,9 +35,11 @@ Discussion forums to discuss debugging and troubleshooting tips. Please open iss
37
35
  - [Rails v6](#rails-v6)
38
36
  - [Rails v7](#rails-v7)
39
37
  - [Manual Installation Steps](#manual-installation-steps)
38
+ - [Note for Sprockets usage](#note-for-sprockets-usage)
40
39
  - [Usage](#usage)
41
- - [Defer for `javascript_pack_tag`](#defer-for-javascript_pack_tag)
42
- - [Server-Side Rendering (SSR)](#server-side-rendering-ssr)
40
+ - [View Helpers](#view-helpers)
41
+ - [Defer for `javascript_pack_tag`](#defer-for-javascript_pack_tag)
42
+ - [Server-Side Rendering (SSR)](#server-side-rendering-ssr)
43
43
  - [Development](#development)
44
44
  - [Webpack Configuration](#webpack-configuration)
45
45
  - [Babel configuration](#babel-configuration)
@@ -56,9 +56,10 @@ Discussion forums to discuss debugging and troubleshooting tips. Please open iss
56
56
  - [Other frameworks](#other-frameworks)
57
57
  - [Custom Rails environments](#custom-rails-environments)
58
58
  - [Upgrading](#upgrading)
59
- - [Paths](#paths)
59
+ - [Paths](#paths)
60
60
  - [Additional paths](#additional-paths)
61
61
  - [Deployment](#deployment)
62
+ - [Example Apps](#example-apps)
62
63
  - [Troubleshooting](#troubleshooting)
63
64
  - [Contributing](#contributing)
64
65
  - [License](#license)
@@ -73,49 +74,40 @@ Discussion forums to discuss debugging and troubleshooting tips. Please open iss
73
74
  - Yarn
74
75
 
75
76
  ## Features
76
-
77
+ - Rails view helpers that fully support webpack output
78
+ - Convenient but not required webpack configuration. The only requirement is that your webpack configuration create a manifest.
79
+ - HMR with the webpack-dev-server, such as for hot-reloading for React!
80
+ - Automatic code splitting using multiple entry points to optimize JavaScript downloads
77
81
  - [Webpack v5](https://webpack.js.org/)
78
82
  - ES6 with [babel](https://babeljs.io/)
79
- - Automatic code splitting using multiple entry points
80
83
  - Asset compression, source-maps, and minification
81
84
  - CDN support
82
- - Rails view helpers
83
- - Extensible and configurable
85
+ - Extensible and configurable. For example, all major dependencies are specified as peers, so you can upgrade easily.
84
86
 
85
87
  ### Optional support
86
-
87
- _requires extra packages to be installed_
88
-
89
- - Stylesheets - Sass, Less, Stylus and Css, PostCSS
90
- - CoffeeScript
91
- - TypeScript
92
- - React
88
+ _Requires extra packages to be installed._
89
+ - React
90
+ - TypeScript
91
+ - Stylesheets - Sass, Less, Stylus and Css, PostCSS
92
+ - CoffeeScript
93
93
 
94
94
  ## Installation
95
95
 
96
- ### Rails v6
97
- With Rails v6, webpacker is installed by default:
98
- ```bash
99
- rails new myapp
100
- ```
101
96
 
102
- ### Rails v7
97
+ ### Rails v6+
103
98
 
104
- With Rails v7, skip JavaScript for a new app and follow below Manual Installation Steps to manually add the `webpacker` gem to your Gemfile.
99
+ With Rails v6+, skip JavaScript for a new app and follow below Manual Installation Steps to manually add the `shakapacker` gem to your Gemfile.
105
100
  ```bash
106
101
  rails new myapp --skip-javascript
107
102
  ```
108
103
 
109
- ### Manual Installation Steps
104
+ _Note, Rails 6 installs the older v5 version of webpacker unless you specify `--skip-javascript`._
105
+
110
106
  Update your `Gemfile`:
111
107
 
112
108
  ```ruby
113
109
  # Gemfile
114
- gem 'webpacker', '~> 6.0'
115
-
116
- # OR if you prefer to use master
117
- gem 'webpacker', git: 'https://github.com/shakacode/shakapacker.git'
118
- yarn add https://github.com/shakacode/shakapacker.git
110
+ gem 'shakapacker', '~> 6.0'
119
111
  ```
120
112
 
121
113
  Then running the following to install Webpacker:
@@ -135,15 +127,26 @@ Note, in v6, most JS packages are peer dependencies. Thus, the installer will ad
135
127
 
136
128
  ```bash
137
129
  yarn add @babel/core @babel/plugin-transform-runtime @babel/preset-env @babel/runtime babel-loader \
138
- compression-webpack-plugin pnp-webpack-plugin terser-webpack-plugin \
130
+ compression-webpack-plugin terser-webpack-plugin \
139
131
  webpack webpack-assets-manifest webpack-cli webpack-merge webpack-sources webpack-dev-server
140
132
  ```
141
133
 
142
- Previously, these "webpack" and "babel" packages were direct dependencies for `@shakacode/shakapacker`. By
134
+ Previously, these "webpack" and "babel" packages were direct dependencies for `webpacker`. By
143
135
  making these peer dependencies, you have control over the versions used in your webpack and babel configs.
144
136
 
137
+ ### Note for Sprockets usage
138
+
139
+ If you are still using Sprockets for some of your assets, you might want to include files from `node_modules` directory in your asset pipeline. This is useful, for example, if you want to reference a stylesheet from a node package in your `.scss` stylesheet.
140
+
141
+ In order to enable this, make sure you add `node_modules` to the asset load path by adding the following in an initializer (for example `config/initializers/assets.rb`)
142
+ ```ruby
143
+ Rails.application.config.assets.paths << Rails.root.join('node_modules')
144
+ ```
145
+
145
146
  ## Usage
146
147
 
148
+ ### View Helpers
149
+
147
150
  Once installed, you can start writing modern ES6-flavored JavaScript apps right away:
148
151
 
149
152
  ```yml
@@ -181,7 +184,7 @@ The result looks like this:
181
184
  <script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload" defer></script>
182
185
  ```
183
186
 
184
- **Important:** Pass all your pack names as multiple arguments, not multiple calls, when using `javascript_pack_tag` and the **`stylesheet_pack_tag`. Otherwise, you will get duplicated chunks on the page. Be especially careful if you might be calling these view helpers from your view, partials, and the layout for a page. You will need some logic to ensure you call the helpers only once with multiple arguments.
187
+ **Important:** Pass all your pack names as multiple arguments, not multiple calls, when using `javascript_pack_tag` and the `stylesheet_pack_tag`. Otherwise, you will get duplicated chunks on the page. Be especially careful if you might be calling these view helpers from your view, partials, and the layout for a page. You will need some logic to ensure you call the helpers only once with multiple arguments.
185
188
 
186
189
  ```erb
187
190
  <%# DO %>
@@ -223,10 +226,10 @@ If you want to use images in your stylesheets:
223
226
  background-image: url('../images/logo.svg')
224
227
  }
225
228
  ```
226
- ##### Defer for `javascript_pack_tag`
229
+ ### Defer for `javascript_pack_tag`
227
230
  Note, the default of "defer" for the `javascript_pack_tag`. You can override that to `false`. If you expose jquery globally with `expose-loader,` by using `import $ from "expose-loader?exposes=$,jQuery!jquery"` in your `app/packs/entrypoints/application.js`, pass the option `defer: false` to your `javascript_pack_tag`.
228
231
 
229
- #### Server-Side Rendering (SSR)
232
+ ### Server-Side Rendering (SSR)
230
233
 
231
234
  Note, if you are using server-side rendering of JavaScript with dynamic code-splitting, as is often done with extensions to Webpacker, like [React on Rails](https://github.com/shakacode/react_on_rails), your JavaScript should create the link prefetch HTML tags that you will use, so you won't need to use to `asset_pack_path` in those circumstances.
232
235
 
@@ -287,11 +290,33 @@ end
287
290
 
288
291
  ### Webpack Configuration
289
292
 
290
- Webpacker gives you a default configuration file for your test, development, and production environments in `config/webpack/*.js`.
293
+ First, you don't _need_ to use Shakapacker's webpack configuration. However, the `shakapacker` NPM package provides convenient access to configuration code that reads the `config/webpacker.yml` file which the view helpers also use. If you have your own customized webpack configuration, at the mininmum, you must ensure:
291
294
 
292
- By default, you don't need to make any changes to `config/webpack/webpack.config.js` files since it's all standard production-ready configuration. However, if you do need to customize or add a new loader, this is where you would go.
295
+ 1. Your output files go the right directory
296
+ 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!
293
297
 
294
- Here is how you can modify webpack configuration:
298
+ The most practical webpack configuration is to take the default from Shakapacker and then use [webpack-merge](https://github.com/survivejs/webpack-merge) to merge your customizations with the default. For example, suppose you want to add some `resolve.extensions`:
299
+
300
+ ```js
301
+ // use the new NPM package name, `shakapacker`.
302
+ // merge is webpack-merge from https://github.com/survivejs/webpack-merge
303
+ const { webpackConfig: baseWebpackConfig, merge } = require('shakapacker')
304
+
305
+ const options = {
306
+ resolve: {
307
+ extensions: ['.css', '.ts', '.tsx']
308
+ }
309
+ }
310
+
311
+ // Copy the object using merge b/c the baseClientWebpackConfig is a mutable global
312
+ // If you want to use this object for client and server rendering configurations,
313
+ // havaing a new object is essential.
314
+ module.exports = merge({}, baseWebpackConfig, options)
315
+ ```
316
+
317
+ 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)
318
+
319
+ Webpacker gives you a default configuration file `config/webpack/webpack.config.js`, which, by default, you don't need to make any changes to `config/webpack/webpack.config.js` since it's a standard production-ready configuration. However, you will probably want to customize or add a new loader by modifying the webpack configuration, as shown above.
295
320
 
296
321
  You might add separate files to keep your code more organized.
297
322
 
@@ -314,7 +339,8 @@ Then `require` this file in your `config/webpack/webpack.config.js`:
314
339
 
315
340
  ```js
316
341
  // config/webpack/webpack.config.js
317
- const { webpackConfig, merge } = require('@shakacode/shakapacker')
342
+ // use the new NPM package name, `shakapacker`.
343
+ const { webpackConfig, merge } = require('shakapacker')
318
344
  const customConfig = require('./custom')
319
345
 
320
346
  module.exports = merge(webpackConfig, customConfig)
@@ -324,7 +350,7 @@ If you need access to configs within Webpacker's configuration, you can import t
324
350
 
325
351
  ```js
326
352
  // config/webpack/webpack.config.js
327
- const { webpackConfig } = require('@shakacode/shakapacker')
353
+ const { webpackConfig } = require('shakapacker')
328
354
 
329
355
  console.log(webpackConfig.output_path)
330
356
  console.log(webpackConfig.source_path)
@@ -335,12 +361,12 @@ console.log(JSON.stringify(webpackConfig, undefined, 2))
335
361
 
336
362
  ### Babel configuration
337
363
 
338
- By default, you will find the Webpacker preset in your `package.json`.
364
+ By default, you will find the Webpacker preset in your `package.json`. Note, you need to use the new NPM package name, `shakapacker`.
339
365
 
340
366
  ```json
341
367
  "babel": {
342
368
  "presets": [
343
- "./node_modules/@shakacode/shakapacker/package/babel/preset.js"
369
+ "./node_modules/shakapacker/package/babel/preset.js"
344
370
  ]
345
371
  },
346
372
  ```
@@ -423,7 +449,7 @@ Then modify the webpack config to use it as a plugin:
423
449
 
424
450
  ```js
425
451
  // config/webpack/webpack.config.js
426
- const { webpackConfig, merge } = require("@shakacode/shakapacker");
452
+ const { webpackConfig, merge } = require("shakapacker");
427
453
  const ForkTSCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
428
454
 
429
455
  module.exports = merge(webpackConfig, {
@@ -443,7 +469,7 @@ Optionally, add the `CSS` extension to webpack config for easy resolution.
443
469
 
444
470
  ```js
445
471
  // config/webpack/webpack.config.js
446
- const { webpackConfig, merge } = require('@shakacode/shakapacker')
472
+ const { webpackConfig, merge } = require('shakapacker')
447
473
  const customConfig = {
448
474
  resolve: {
449
475
  extensions: ['.css']
@@ -516,13 +542,12 @@ module.exports = {
516
542
 
517
543
  ```js
518
544
  // config/webpack/webpack.config.js
519
- const { webpackConfig, merge } = require('@shakacode/shakapacker')
545
+ const { webpackConfig, merge } = require('shakapacker')
520
546
  const vueConfig = require('./rules/vue')
521
547
 
522
548
  module.exports = merge(vueConfig, webpackConfig)
523
549
  ```
524
550
 
525
-
526
551
  ### Custom Rails environments
527
552
 
528
553
  Out of the box Webpacker ships with - development, test and production environments in `config/webpacker.yml` however, in most production apps extra environments are needed as part of deployment workflow. Webpacker supports this out of the box from version 3.4.0+ onwards.
@@ -575,26 +600,26 @@ You can run following commands to upgrade Webpacker to the latest stable version
575
600
 
576
601
  ```bash
577
602
  # check your Gemfile for version restrictions
578
- bundle update webpacker
603
+ bundle update shakapacker
579
604
 
580
605
  # overwrite your changes to the default install files and revert any unwanted changes from the install
581
606
  rails webpacker:install
582
607
 
583
608
  # yarn 1 instructions
584
- yarn upgrade @shakacode/shakapacker --latest
609
+ yarn upgrade shakapacker --latest
585
610
  yarn upgrade webpack-dev-server --latest
586
611
 
587
612
  # yarn 2 instructions
588
- yarn up @shakacode/shakapacker@latest
613
+ yarn up shakapacker@latest
589
614
  yarn up webpack-dev-server@latest
590
615
 
591
616
  # Or to install the latest release (including pre-releases)
592
- yarn add @shakacode/shakapacker@next
617
+ yarn add shakapacker@next
593
618
  ```
594
619
 
595
620
  Also, consult the [CHANGELOG](./CHANGELOG.md) for additional upgrade links.
596
621
 
597
- ## Paths
622
+ ### Paths
598
623
 
599
624
  By default, Webpacker ships with simple conventions for where the JavaScript app files and compiled webpack bundles will go in your Rails app. All these options are configurable from `config/webpacker.yml` file.
600
625
 
@@ -650,18 +675,17 @@ When compiling assets for production on a remote server, such as a continuous in
650
675
 
651
676
  If you are using a CDN setup, webpacker will use the configured [asset host](https://guides.rubyonrails.org/configuring.html#rails-general-configuration) value to prefix URLs for images or font icons which are included inside JS code or CSS. It is possible to override this value during asset compilation by setting the `WEBPACKER_ASSET_HOST` environment variable.
652
677
 
678
+ ## Example Apps
679
+ * [React on Rails Tutorial With SSR, HMR fast refresh, and TypeScript](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh)
680
+
653
681
 
654
682
  ## Troubleshooting
655
683
 
656
684
  See the doc page for [Troubleshooting](./docs/troubleshooting.md).
657
685
 
658
-
659
686
  ## Contributing
660
687
 
661
- [![Code Helpers](https://www.codetriage.com/shakacode/shakapacker/badges/users.svg)](https://www.codetriage.com/shakacode/shakapacker)
662
-
663
- We encourage you to contribute to Webpacker! See [CONTRIBUTING](CONTRIBUTING.md) for guidelines about how to proceed.
664
-
688
+ We encourage you to contribute to Shakapacker/Webpacker! See [CONTRIBUTING](CONTRIBUTING.md) for guidelines about how to proceed. We have a [Slack discussion channel](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE).
665
689
 
666
690
  ## License
667
691
 
@@ -1,13 +1,13 @@
1
1
  # Customizing Babel Config
2
2
 
3
3
  ## Default Configuration
4
- The default configuration of babel is done by using `package.json` to use the file within the `@shakacode/shakapacker` package.
4
+ The default configuration of babel is done by using `package.json` to use the file within the `shakapacker` package.
5
5
 
6
6
  ```json
7
7
  {
8
8
  "babel": {
9
9
  "presets": [
10
- "./node_modules/@shakacode/shakapacker/package/babel/preset.js"
10
+ "./node_modules/shakapacker/package/babel/preset.js"
11
11
  ]
12
12
  }
13
13
  }
@@ -27,7 +27,7 @@ yarn add --dev @pmmmwh/react-refresh-webpack-plugin react-refresh
27
27
  ```js
28
28
  // babel.config.js
29
29
  module.exports = function (api) {
30
- const defaultConfigFunc = require('@shakacode/shakapacker/package/babel/preset.js')
30
+ const defaultConfigFunc = require('shakapacker/package/babel/preset.js')
31
31
  const resultConfig = defaultConfigFunc(api)
32
32
  const isProductionEnv = api.env('production')
33
33
 
@@ -13,7 +13,7 @@ Let's call the shakacode/shakapacker directory `WEBPACKER_DIR` which has shakaco
13
13
  ### Setup with Yalc
14
14
  Use [`yalc`](https://github.com/wclr/yalc) unless you like yak shaving weird errors.
15
15
  1. In `WEBPACKER_DIR`, run `yalc publish`
16
- 2. In `TEST_APP_DIR`, run `yalc link @shakacode/shakapacker`
16
+ 2. In `TEST_APP_DIR`, run `yalc link shakapacker`
17
17
 
18
18
  ## Update the Package Code
19
19
  1. Make some JS change in WEBPACKER_DIR
@@ -132,7 +132,7 @@ To silent these warnings, please update `config/webpack/webpack.config.js`:
132
132
  ```js
133
133
  const webpack = require('webpack')
134
134
  const { resolve } = require('path')
135
- const { webpackConfig, merge } = require('@shakacode/shakapacker')
135
+ const { webpackConfig, merge } = require('shakapacker')
136
136
 
137
137
  module.exports = merge(webpackConfig, {
138
138
  plugins: [
@@ -181,7 +181,7 @@ Instead do:
181
181
  // config/webpack/webpack.config.js
182
182
 
183
183
  const webpack = require('webpack')
184
- const { webpackConfig, merge } = require('@shakacode/shakapacker')
184
+ const { webpackConfig, merge } = require('shakapacker')
185
185
 
186
186
  module.exports = merge(webpackConfig, {
187
187
  plugins: [
data/docs/v6_upgrade.md CHANGED
@@ -10,6 +10,15 @@ Webpacker used to configure Webpack indirectly, which lead to a [complicated sec
10
10
 
11
11
  This means you have to configure integration with frameworks yourself, but webpack-merge helps with this. See this example for [Vue](https://github.com/shakacode/shakapacker#other-frameworks) and scroll to the bottom for [more examples](#examples-of-v5-to-v6).
12
12
 
13
+ ## webpacker v6.0.0.rc.6 to shakapacker
14
+ See an example migration here: [PR 27](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/pull/27).
15
+
16
+ ### Update
17
+ 1. Peer dependencies. Run `yarn add @babel/core @babel/plugin-transform-runtime @babel/preset-env @babel/runtime babel-loader compression-webpack-plugin terser-webpack-plugin webpack webpack-assets-manifest webpack-cli webpack-merge webpack-sources webpack-dev-server`
18
+ 1. Update any scripts that called `bin/webpack` or `bin/webpack-dev-server` to `bin/webpacker` or `bin/webpacker-dev-server`
19
+ 1. Update your webpack config for a single config file, `config/webpack/webpack.config.js`.
20
+ 1. Update `babel.config.js` if you need JSX support.
21
+
13
22
  ## How to upgrade to Webpacker v6 from v5
14
23
  1. Ensure you have a clean working git branch. You will be overwriting all your files and reverting the changes that you don't want.
15
24
 
@@ -33,13 +42,13 @@ This means you have to configure integration with frameworks yourself, but webpa
33
42
 
34
43
  1. Upgrade the Webpacker Ruby gem and the NPM package
35
44
 
36
- Note: [Check the releases page to verify the latest version](https://github.com/rails/webpacker/releases), and make sure to install identical version numbers of webpacker gem and `@shakacode/shakapacker` npm package. (Gems use a period and packages use a dot between the main version number and the beta version.)
45
+ Note: [Check the gem page to verify the latest version](https://rubygems.org/gems/shakapacker), and make sure to install identical version numbers of `shakapacker` gem and package. (Gems use a period and packages use a dot between the main version number and the beta version.)
37
46
 
38
47
  Example going to a specific version:
39
48
 
40
49
  ```ruby
41
50
  # Gemfile
42
- gem 'webpacker', '6.0.0.rc.7'
51
+ gem 'shakapacker', '6.0.0.rc.13'
43
52
  ```
44
53
 
45
54
  ```bash
@@ -47,7 +56,7 @@ This means you have to configure integration with frameworks yourself, but webpa
47
56
  ```
48
57
 
49
58
  ```bash
50
- yarn add @shakacode/shakapacker@6.0.0-rc.7 --exact
59
+ yarn add shakapacker@6.0.0-rc.13 --exact
51
60
  ```
52
61
 
53
62
  ```bash
@@ -58,13 +67,13 @@ This means you have to configure integration with frameworks yourself, but webpa
58
67
 
59
68
  Note, the webpacker:install will install the peer dependencies:
60
69
  ```bash
61
- yarn add @babel/core @babel/plugin-transform-runtime @babel/preset-env @babel/runtime babel-loader compression-webpack-plugin pnp-webpack-plugin terser-webpack-plugin webpack webpack-assets-manifest webpack-cli webpack-merge webpack-sources webpack-dev-server
70
+ yarn add @babel/core @babel/plugin-transform-runtime @babel/preset-env @babel/runtime babel-loader compression-webpack-plugin terser-webpack-plugin webpack webpack-assets-manifest webpack-cli webpack-merge webpack-sources webpack-dev-server
62
71
  ```
63
72
 
64
73
  1. There is now a single default configuration file of `config/webpack/webpack.config.js`. Previously, the config file was set
65
74
  to `config/webpack/#{NODE_ENV}.js`. In the `config/webpack/` directory, you can either refactor your code in `test.js`, `development.js`, and `production.js` to a single file, `webpack.config.js` or you can replace the contents of `config/webpack/config.webpack.js` to conditionally load the old file based on the NODE_ENV with this snippet:
66
75
  ```js
67
- const { env, webpackConfig } = require('@shakacode/shakapacker')
76
+ const { env, webpackConfig } = require('shakapacker')
68
77
  const { existsSync } = require('fs')
69
78
  const { resolve } = require('path')
70
79
 
@@ -109,7 +118,7 @@ This means you have to configure integration with frameworks yourself, but webpa
109
118
  1. Import `environment` changed to `webpackConfig`. For example, the new code looks like:
110
119
  ```js
111
120
  // config/webpack/webpack.config.js
112
- const { webpackConfig, merge } = require('@shakacode/shakapacker')
121
+ const { webpackConfig, merge } = require('shakapacker')
113
122
  const customConfig = require('./custom')
114
123
 
115
124
  module.exports = merge(webpackConfig, customConfig)
@@ -1,4 +1,4 @@
1
- const { webpackConfig } = require('@shakacode/shakapacker')
1
+ const { webpackConfig } = require('shakapacker')
2
2
 
3
3
  // See the shakacode/shakapacker README and docs directory for advice on customizing your webpackConfig.
4
4
 
@@ -6,7 +6,7 @@
6
6
  "version": "0.1.0",
7
7
  "babel": {
8
8
  "presets": [
9
- "./node_modules/@shakacode/shakapacker/package/babel/preset.js"
9
+ "./node_modules/shakapacker/package/babel/preset.js"
10
10
  ]
11
11
  },
12
12
  "browserslist": [
@@ -45,15 +45,6 @@ if (setup_path = Rails.root.join("bin/setup")).exist?
45
45
  RUBY
46
46
  end
47
47
 
48
- if (asset_config_path = Rails.root.join("config/initializers/assets.rb")).exist?
49
- say "Add node_modules to the asset load path"
50
- append_to_file asset_config_path, <<-RUBY
51
-
52
- # Add node_modules folder to the asset load path.
53
- Rails.application.config.assets.paths << Rails.root.join("node_modules")
54
- RUBY
55
- end
56
-
57
48
  if (csp_config_path = Rails.root.join("config/initializers/content_security_policy.rb")).exist?
58
49
  say "Make note of webpack-dev-server exemption needed to csp"
59
50
  insert_into_file csp_config_path, <<-RUBY, after: %(# Rails.application.config.content_security_policy do |policy|)
@@ -66,11 +57,11 @@ results = []
66
57
 
67
58
  Dir.chdir(Rails.root) do
68
59
  if Webpacker::VERSION.match?(/^[0-9]+\.[0-9]+\.[0-9]+$/)
69
- say "Installing @shakacode/shakapacker@#{Webpacker::VERSION}"
70
- results << run("yarn add @shakacode/shakapacker@#{Webpacker::VERSION}")
60
+ say "Installing shakapacker@#{Webpacker::VERSION}"
61
+ results << run("yarn add shakapacker@#{Webpacker::VERSION}")
71
62
  else
72
- say "Installing @shakacode/shakapacker@next"
73
- results << run("yarn add @shakacode/shakapacker@next")
63
+ say "Installing shakapacker@next"
64
+ results << run("yarn add shakapacker@next")
74
65
  end
75
66
 
76
67
  package_json = File.read("#{__dir__}/../../package.json")
@@ -80,7 +71,7 @@ Dir.chdir(Rails.root) do
80
71
  result << "#{package}@#{major_version}"
81
72
  end.join(" ")
82
73
 
83
- say "Adding @shakacode/shakapacker peerDependencies"
74
+ say "Adding shakapacker peerDependencies"
84
75
  results << run("yarn add #{peers_to_add}")
85
76
 
86
77
  say "Installing webpack-dev-server for live reloading as a development dependency"
@@ -0,0 +1 @@
1
+ require "webpacker"
@@ -11,7 +11,7 @@ namespace :webpacker do
11
11
  $stdout.puts "Yarn: #{`yarn --version`}"
12
12
 
13
13
  $stdout.puts "\n"
14
- $stdout.puts "@shakacode/shakapacker: \n#{`npm list @shakacode/shakapacker version`}"
14
+ $stdout.puts "shakapacker: \n#{`npm list shakapacker version`}"
15
15
 
16
16
  $stdout.puts "Is bin/webpacker present?: #{File.exist? 'bin/webpacker'}"
17
17
  $stdout.puts "Is bin/webpacker-dev-server present?: #{File.exist? 'bin/webpacker-dev-server'}"
@@ -96,6 +96,13 @@ module Webpacker::Helper
96
96
  # <%= javascript_pack_tag 'calendar' %>
97
97
  # <%= javascript_pack_tag 'map' %>
98
98
  def javascript_pack_tag(*names, defer: true, **options)
99
+ if @javascript_pack_tag_loaded
100
+ raise "To prevent duplicated chunks on the page, you should call javascript_pack_tag only once on the page. " \
101
+ "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#usage for the usage guide"
102
+ end
103
+
104
+ @javascript_pack_tag_loaded = true
105
+
99
106
  javascript_include_tag(*sources_from_manifest_entrypoints(names, type: :javascript), **options.tap { |o| o[:defer] = defer })
100
107
  end
101
108
 
@@ -141,6 +148,13 @@ module Webpacker::Helper
141
148
  # <%= stylesheet_pack_tag 'calendar' %>
142
149
  # <%= stylesheet_pack_tag 'map' %>
143
150
  def stylesheet_pack_tag(*names, **options)
151
+ if @stylesheet_pack_tag_loaded
152
+ raise "To prevent duplicated chunks on the page, you should call stylesheet_pack_tag only once on the page. " \
153
+ "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#usage for the usage guide"
154
+ end
155
+
156
+ @stylesheet_pack_tag_loaded = true
157
+
144
158
  return "" if Webpacker.inlining_css?
145
159
 
146
160
  stylesheet_link_tag(*sources_from_manifest_entrypoints(names, type: :stylesheet), **options)
@@ -1,4 +1,4 @@
1
1
  module Webpacker
2
2
  # Change the version in package.json too, please!
3
- VERSION = "6.0.0.rc.12".freeze
3
+ VERSION = "6.0.1".freeze
4
4
  end
@@ -1,4 +1,4 @@
1
- const { moduleExists } = require('@shakacode/shakapacker')
1
+ const { moduleExists } = require('shakapacker')
2
2
 
3
3
  module.exports = function config(api) {
4
4
  const validEnv = ['development', 'test', 'production']
@@ -3,7 +3,6 @@
3
3
 
4
4
  const { basename, dirname, join, relative, resolve } = require('path')
5
5
  const extname = require('path-complete-extname')
6
- const PnpWebpackPlugin = require('pnp-webpack-plugin')
7
6
  const { sync: globSync } = require('glob')
8
7
  const WebpackAssetsManifest = require('webpack-assets-manifest')
9
8
  const webpack = require('webpack')
@@ -92,15 +91,13 @@ module.exports = {
92
91
  entry: getEntryObject(),
93
92
  resolve: {
94
93
  extensions: ['.js', '.jsx', '.mjs', '.ts', '.tsx', '.coffee'],
95
- modules: getModulePaths(),
96
- plugins: [PnpWebpackPlugin]
94
+ modules: getModulePaths()
97
95
  },
98
96
 
99
97
  plugins: getPlugins(),
100
98
 
101
99
  resolveLoader: {
102
- modules: ['node_modules'],
103
- plugins: [PnpWebpackPlugin.moduleLoader(module)]
100
+ modules: ['node_modules']
104
101
  },
105
102
 
106
103
  optimization: {
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "name": "@shakacode/shakapacker",
3
- "version": "6.0.0-rc.12",
2
+ "name": "shakapacker",
3
+ "version": "6.0.1",
4
4
  "description": "Use webpack to manage app-like JavaScript modules in Rails",
5
5
  "main": "package/index.js",
6
6
  "files": [
@@ -18,7 +18,6 @@
18
18
  "@babel/runtime": "^7.15.4",
19
19
  "babel-loader": "^8.2.2",
20
20
  "compression-webpack-plugin": "^9.0.0",
21
- "pnp-webpack-plugin": "^1.7.0",
22
21
  "terser-webpack-plugin": "^5.2.4",
23
22
  "webpack": "^5.53.0",
24
23
  "webpack-assets-manifest": "^5.0.6",
@@ -40,7 +39,6 @@
40
39
  "eslint-plugin-jsx-a11y": "^6.4.1",
41
40
  "eslint-plugin-react": "^7.26.0",
42
41
  "jest": "^27.2.1",
43
- "pnp-webpack-plugin": "^1.7.0",
44
42
  "webpack": "^5.53.0",
45
43
  "webpack-assets-manifest": "^5.0.6",
46
44
  "webpack-merge": "^5.8.0"
data/test/helper_test.rb CHANGED
@@ -12,6 +12,9 @@ class HelperTest < ActionView::TestCase
12
12
  "https://example.com"
13
13
  end
14
14
  end.new
15
+
16
+ @javascript_pack_tag_loaded = nil
17
+ @stylesheet_pack_tag_loaded = nil
15
18
  end
16
19
 
17
20
  def test_asset_pack_path
@@ -129,6 +132,18 @@ class HelperTest < ActionView::TestCase
129
132
  javascript_pack_tag(:application)
130
133
  end
131
134
 
135
+ def test_javascript_pack_tag_multiple_invocations
136
+ error = assert_raises do
137
+ javascript_pack_tag(:application)
138
+ javascript_pack_tag(:bootstrap)
139
+ end
140
+
141
+ assert_equal \
142
+ "To prevent duplicated chunks on the page, you should call javascript_pack_tag only once on the page. " +
143
+ "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#usage for the usage guide",
144
+ error.message
145
+ end
146
+
132
147
  def application_stylesheet_chunks
133
148
  %w[/packs/1-c20632e7baf2c81200d3.chunk.css /packs/application-k344a6d59eef8632c9d1.chunk.css]
134
149
  end
@@ -156,4 +171,16 @@ class HelperTest < ActionView::TestCase
156
171
  (application_stylesheet_chunks).map { |chunk| stylesheet_link_tag(chunk, media: "all") }.join("\n"),
157
172
  stylesheet_pack_tag("application", media: "all")
158
173
  end
174
+
175
+ def test_stylesheet_pack_tag_multiple_invocations
176
+ error = assert_raises do
177
+ stylesheet_pack_tag(:application)
178
+ stylesheet_pack_tag(:hello_stimulus)
179
+ end
180
+
181
+ assert_equal \
182
+ "To prevent duplicated chunks on the page, you should call stylesheet_pack_tag only once on the page. " +
183
+ "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#usage for the usage guide",
184
+ error.message
185
+ end
159
186
  end
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": true,
3
3
  "dependencies": {
4
- "@shakacode/shakapacker": "file:../../../../"
4
+ "shakapacker": "file:../../../../"
5
5
  },
6
6
  "license": "MIT"
7
7
  }
data/yarn.lock CHANGED
@@ -3215,13 +3215,6 @@ pkg-dir@^4.1.0, pkg-dir@^4.2.0:
3215
3215
  dependencies:
3216
3216
  find-up "^4.0.0"
3217
3217
 
3218
- pnp-webpack-plugin@^1.7.0:
3219
- version "1.7.0"
3220
- resolved "https://registry.yarnpkg.com/pnp-webpack-plugin/-/pnp-webpack-plugin-1.7.0.tgz#65741384f6d8056f36e2255a8d67ffc20866f5c9"
3221
- integrity sha512-2Rb3vm+EXble/sMXNSu6eoBx8e79gKqhNq9F5ZWW6ERNCTE/Q0wQNne5541tE5vKjfM8hpNCYL+LGc1YTfI0dg==
3222
- dependencies:
3223
- ts-pnp "^1.1.6"
3224
-
3225
3218
  prelude-ls@^1.2.1:
3226
3219
  version "1.2.1"
3227
3220
  resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396"
@@ -3730,11 +3723,6 @@ tr46@^2.1.0:
3730
3723
  dependencies:
3731
3724
  punycode "^2.1.1"
3732
3725
 
3733
- ts-pnp@^1.1.6:
3734
- version "1.2.0"
3735
- resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.2.0.tgz#a500ad084b0798f1c3071af391e65912c86bca92"
3736
- integrity sha512-csd+vJOb/gkzvcCHgTGSChYpy5f1/XKNsmvBGO4JXS+z1v2HobugDz4s1IeFXM3wZB44uczs+eazB5Q/ccdhQw==
3737
-
3738
3726
  tsconfig-paths@^3.12.0:
3739
3727
  version "3.12.0"
3740
3728
  resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.12.0.tgz#19769aca6ee8f6a1a341e38c8fa45dd9fb18899b"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shakapacker
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0.rc.12
4
+ version: 6.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-01-18 00:00:00.000000000 Z
13
+ date: 2022-01-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -157,6 +157,7 @@ files:
157
157
  - lib/install/config/webpacker.yml
158
158
  - lib/install/package.json
159
159
  - lib/install/template.rb
160
+ - lib/shakapacker.rb
160
161
  - lib/shakapacker/utils/misc.rb
161
162
  - lib/shakapacker/utils/version_syntax_converter.rb
162
163
  - lib/tasks/webpacker.rake
@@ -268,7 +269,7 @@ homepage: https://github.com/shakacode/shakapacker
268
269
  licenses:
269
270
  - MIT
270
271
  metadata:
271
- source_code_uri: https://github.com/shakacode/shakapacker/tree/v6.0.0-rc.12
272
+ source_code_uri: https://github.com/shakacode/shakapacker/tree/v6.0.1
272
273
  post_install_message:
273
274
  rdoc_options: []
274
275
  require_paths:
@@ -280,9 +281,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
280
281
  version: 2.7.0
281
282
  required_rubygems_version: !ruby/object:Gem::Requirement
282
283
  requirements:
283
- - - ">"
284
+ - - ">="
284
285
  - !ruby/object:Gem::Version
285
- version: 1.3.1
286
+ version: '0'
286
287
  requirements: []
287
288
  rubygems_version: 3.2.32
288
289
  signing_key: