shakapacker 9.3.0 → 9.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.claude/commands/update-changelog.md +224 -0
  3. data/.github/actionlint-matcher.json +17 -0
  4. data/.github/workflows/dummy.yml +9 -0
  5. data/.github/workflows/generator.yml +13 -0
  6. data/.github/workflows/node.yml +83 -0
  7. data/.github/workflows/ruby.yml +11 -0
  8. data/.github/workflows/test-bundlers.yml +10 -0
  9. data/CHANGELOG.md +15 -8
  10. data/CLAUDE.md +6 -10
  11. data/CONTRIBUTING.md +57 -0
  12. data/Gemfile.lock +1 -1
  13. data/README.md +58 -33
  14. data/docs/api-reference.md +519 -0
  15. data/docs/configuration.md +11 -5
  16. data/docs/css-modules-export-mode.md +40 -6
  17. data/docs/transpiler-migration.md +12 -9
  18. data/docs/using_swc_loader.md +13 -10
  19. data/docs/v9_upgrade.md +11 -2
  20. data/eslint.config.fast.js +120 -8
  21. data/eslint.config.js +50 -31
  22. data/lib/install/config/shakapacker.yml +14 -1
  23. data/lib/shakapacker/configuration.rb +47 -4
  24. data/lib/shakapacker/dev_server_runner.rb +4 -0
  25. data/lib/shakapacker/doctor.rb +1 -1
  26. data/lib/shakapacker/version.rb +1 -1
  27. data/package/config.ts +2 -3
  28. data/package/configExporter/cli.ts +29 -24
  29. data/package/dev_server.ts +2 -2
  30. data/package/env.ts +1 -1
  31. data/package/environments/__type-tests__/rspack-plugin-compatibility.ts +6 -6
  32. data/package/environments/base.ts +2 -2
  33. data/package/environments/development.ts +3 -6
  34. data/package/environments/production.ts +2 -2
  35. data/package/environments/test.ts +2 -1
  36. data/package/esbuild/index.ts +0 -2
  37. data/package/index.d.ts +1 -0
  38. data/package/index.d.ts.template +1 -0
  39. data/package/index.ts +0 -1
  40. data/package/plugins/rspack.ts +3 -1
  41. data/package/plugins/webpack.ts +5 -3
  42. data/package/rspack/index.ts +3 -3
  43. data/package/rules/file.ts +1 -1
  44. data/package/rules/raw.ts +3 -1
  45. data/package/rules/rspack.ts +0 -2
  46. data/package/rules/sass.ts +0 -2
  47. data/package/rules/webpack.ts +0 -1
  48. data/package/swc/index.ts +0 -2
  49. data/package/types.ts +8 -11
  50. data/package/utils/debug.ts +0 -4
  51. data/package/utils/getStyleRule.ts +17 -9
  52. data/package/utils/helpers.ts +8 -3
  53. data/package/utils/pathValidation.ts +10 -11
  54. data/package/utils/requireOrError.ts +4 -3
  55. data/package/webpackDevServerConfig.ts +4 -4
  56. data/package.json +1 -1
  57. data/test/package/transpiler-defaults.test.js +42 -0
  58. metadata +5 -2
data/README.md CHANGED
@@ -85,7 +85,7 @@ Read the [full review here](https://clutch.co/profile/shakacode#reviews?sort_by=
85
85
  - [Automatic Webpack Code Building](#automatic-webpack-code-building)
86
86
  - [Compiler strategies](#compiler-strategies)
87
87
  - [Common Development Commands](#common-development-commands)
88
- - [API Documentation](#api-documentation)
88
+ - [Ruby API Reference](#ruby-api-reference)
89
89
  - [Webpack Configuration](#webpack-configuration)
90
90
  - [Babel configuration](#babel-configuration)
91
91
  - [SWC configuration](#swc-configuration)
@@ -673,47 +673,55 @@ end
673
673
 
674
674
  **Note:** Don't forget to prefix `ruby` when running these binstubs on Windows
675
675
 
676
- ### API Documentation
676
+ ### Ruby API Reference
677
677
 
678
- Shakapacker's Ruby API is documented using RDoc comments. You can generate the API documentation locally using either RDoc or YARD:
678
+ **📚 For comprehensive Ruby API documentation, see the [API Reference Guide](./docs/api-reference.md).**
679
679
 
680
- #### Using RDoc (Standard Ruby Documentation)
680
+ This guide covers:
681
681
 
682
- ```bash
683
- # Generate documentation in the doc/ directory
684
- rdoc lib/
682
+ - **Main Shakapacker Module** - Configuration, compilation, and manifest access
683
+ - **Configuration API** - Accessing `config/shakapacker.yml` settings programmatically
684
+ - **View Helpers** - Complete reference for all Rails helpers
685
+ - **Manifest API** - Asset lookup and resolution methods
686
+ - **Dev Server API** - Development server status and management
687
+ - **Advanced Usage** - Multiple instances, testing, custom configurations
685
688
 
686
- # View the generated documentation
687
- open doc/index.html
689
+ #### Quick Examples
690
+
691
+ ```ruby
692
+ # Access configuration
693
+ Shakapacker.config.source_path
694
+ # => #<Pathname:/app/app/javascript>
695
+
696
+ # Get raw configuration hash
697
+ Shakapacker.config.data
698
+ # => { "source_path" => "app/javascript", ... }
699
+
700
+ # Look up compiled assets
701
+ Shakapacker.manifest.lookup("application.js")
702
+ # => "/packs/application-abc123.js"
703
+
704
+ # Check dev server status
705
+ Shakapacker.dev_server.running?
706
+ # => true
688
707
  ```
689
708
 
690
- #### Using YARD (Enhanced Documentation)
709
+ #### Generating Full API Documentation
691
710
 
692
- YARD provides better formatting and supports additional tags used in the codebase:
711
+ For complete API documentation with all methods and parameters:
693
712
 
694
713
  ```bash
695
- # Install YARD if you don't have it
714
+ # Using YARD (recommended - better formatting)
696
715
  gem install yard
697
-
698
- # Generate documentation
699
716
  yard doc
717
+ yard server # Browse at http://localhost:8808
700
718
 
701
- # View the generated documentation
719
+ # Using RDoc (standard Ruby documentation)
720
+ rdoc lib/
702
721
  open doc/index.html
703
-
704
- # Or start a local documentation server
705
- yard server
706
722
  ```
707
723
 
708
- The API documentation covers:
709
-
710
- - **Shakapacker** - Main module with configuration, compilation, and manifest access
711
- - **Shakapacker::Configuration** - All configuration options from `shakapacker.yml`
712
- - **Shakapacker::Manifest** - Asset lookup methods used by view helpers
713
- - **Shakapacker::DevServer** - Development server status and configuration
714
- - **Shakapacker::Instance** - Instance management and lifecycle
715
-
716
- For the most up-to-date API reference, generate the documentation from the source code as shown above.
724
+ The generated documentation includes all public and private methods with detailed descriptions.
717
725
 
718
726
  ### Webpack Configuration
719
727
 
@@ -724,6 +732,21 @@ First, you don't _need_ to use Shakapacker's webpack configuration. However, the
724
732
 
725
733
  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`.
726
734
 
735
+ #### Using a Completely Custom Webpack Configuration
736
+
737
+ If you're providing a completely custom webpack configuration without using `generateWebpackConfig()`, you should set `javascript_transpiler: 'none'` in your `config/shakapacker.yml` to skip Shakapacker's transpiler validation and dependency checks:
738
+
739
+ ```yml
740
+ # config/shakapacker.yml
741
+ default: &default
742
+ javascript_transpiler: "none" # Skip Shakapacker's transpiler setup
743
+ # ... other config
744
+ ```
745
+
746
+ This is useful when you're managing your own transpiler configuration entirely outside of Shakapacker's defaults.
747
+
748
+ **Note:** Only use `javascript_transpiler: 'none'` if you're providing a completely custom webpack configuration without using `generateWebpackConfig()`. If you're using Shakapacker's webpack generation (which is the common case), use one of the supported transpilers (`'babel'`, `'swc'`, or `'esbuild'`) instead.
749
+
727
750
  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`:
728
751
 
729
752
  ```js
@@ -818,7 +841,7 @@ fileRule.type = "asset"
818
841
 
819
842
  ### Babel configuration
820
843
 
821
- By default, you will find the Shakapacker preset in your `package.json`. Note, you need to use the new NPM package name, `shakapacker`.
844
+ If you choose to use Babel instead of the default SWC transpiler, you will need to configure it in your `package.json`:
822
845
 
823
846
  ```json
824
847
  "babel": {
@@ -828,19 +851,21 @@ By default, you will find the Shakapacker preset in your `package.json`. Note, y
828
851
  },
829
852
  ```
830
853
 
831
- Optionally, you can change your Babel configuration by removing these lines in your `package.json` and adding [a Babel configuration file](https://babeljs.io/docs/en/config-files) to your project. For an example of customization based on the original, see [Customizing Babel Config](./docs/customizing_babel_config.md).
854
+ You can also change your Babel configuration by removing these lines in your `package.json` and adding [a Babel configuration file](https://babeljs.io/docs/en/config-files) to your project. For an example of customization based on the original, see [Customizing Babel Config](./docs/customizing_babel_config.md).
832
855
 
833
856
  ### SWC configuration
834
857
 
835
- You can try out experimental integration with the SWC loader. You can read more at [SWC usage docs](./docs/using_swc_loader.md).
858
+ SWC is the recommended JavaScript transpiler in Shakapacker v9+ (20x faster than Babel). New installations use SWC by default via the installation template. You can read more at [SWC usage docs](./docs/using_swc_loader.md).
859
+
860
+ **Note on defaults**: The installation template explicitly sets `javascript_transpiler: "swc"` for new projects. However, for backward compatibility, webpack's runtime default (when no explicit config exists) remains `"babel"`. Rspack always defaults to `"swc"`.
836
861
 
837
- 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.
862
+ Please note that SWC supports [React](#react) integration out of the box - no additional configuration needed.
838
863
 
839
864
  ### esbuild loader configuration
840
865
 
841
- You can try out experimental integration with the esbuild-loader. You can read more at [esbuild-loader usage docs](./docs/using_esbuild_loader.md).
866
+ You can use esbuild as an alternative JavaScript transpiler. You can read more at [esbuild-loader usage docs](./docs/using_esbuild_loader.md).
842
867
 
843
- 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.
868
+ Please note that esbuild supports [React](#react) integration out of the box - no additional configuration needed.
844
869
 
845
870
  ### Switching between transpilers
846
871
 
@@ -0,0 +1,519 @@
1
+ # Shakapacker API Reference
2
+
3
+ This document provides a comprehensive reference for Shakapacker's public Ruby API. For JavaScript/webpack configuration, see [Webpack Configuration](./webpack-configuration.md).
4
+
5
+ ## Table of Contents
6
+
7
+ - [Overview](#overview)
8
+ - [Main Module: Shakapacker](#main-module-shakapacker)
9
+ - [Configuration API](#configuration-api)
10
+ - [View Helpers](#view-helpers)
11
+ - [Manifest API](#manifest-api)
12
+ - [Dev Server API](#dev-server-api)
13
+ - [Compiler API](#compiler-api)
14
+ - [Advanced Usage](#advanced-usage)
15
+
16
+ ## Overview
17
+
18
+ Shakapacker provides a Ruby API for integrating webpack/rspack with Rails applications. The API is divided into several key areas:
19
+
20
+ - **Configuration**: Access to `config/shakapacker.yml` settings
21
+ - **View Helpers**: Rails helpers for rendering script/link tags
22
+ - **Manifest**: Asset lookup and resolution
23
+ - **Compilation**: Programmatic asset compilation
24
+ - **Dev Server**: Development server status and management
25
+
26
+ ### What's Public API?
27
+
28
+ Methods and classes marked with `@api public` in the source code are considered stable public API. Other methods may change between minor versions.
29
+
30
+ ## Main Module: Shakapacker
31
+
32
+ The `Shakapacker` module provides singleton-style access to all major functionality.
33
+
34
+ ### Configuration Access
35
+
36
+ ```ruby
37
+ # Get the configuration object
38
+ Shakapacker.config
39
+ # => #<Shakapacker::Configuration>
40
+
41
+ # Access configuration values
42
+ Shakapacker.config.source_path
43
+ # => #<Pathname:/path/to/app/javascript>
44
+
45
+ Shakapacker.config.public_output_path
46
+ # => "packs"
47
+ ```
48
+
49
+ ### Compilation
50
+
51
+ ```ruby
52
+ # Compile all packs
53
+ Shakapacker.compile
54
+ # => true
55
+
56
+ # Check if compilation is needed
57
+ Shakapacker.compiler.stale?
58
+ # => false
59
+
60
+ # Get compiler output
61
+ Shakapacker.compiler.compile
62
+ ```
63
+
64
+ ### Manifest Lookup
65
+
66
+ ```ruby
67
+ # Look up compiled asset path
68
+ Shakapacker.manifest.lookup("application.js")
69
+ # => "/packs/application-abc123.js"
70
+
71
+ # Look up with error if not found
72
+ Shakapacker.manifest.lookup!("application.js")
73
+ # => "/packs/application-abc123.js" (or raises Shakapacker::Manifest::MissingEntryError)
74
+ ```
75
+
76
+ ### Dev Server Status
77
+
78
+ ```ruby
79
+ # Check if dev server is running
80
+ Shakapacker.dev_server.running?
81
+ # => true
82
+
83
+ # Get dev server host
84
+ Shakapacker.dev_server.host
85
+ # => "localhost"
86
+
87
+ # Get dev server port
88
+ Shakapacker.dev_server.port
89
+ # => 3035
90
+ ```
91
+
92
+ ### Environment Management
93
+
94
+ ```ruby
95
+ # Get current environment
96
+ Shakapacker.env
97
+ # => #<ActiveSupport::StringInquirer "development">
98
+
99
+ # Temporarily use different NODE_ENV
100
+ Shakapacker.with_node_env("production") do
101
+ Shakapacker.compile
102
+ end
103
+ ```
104
+
105
+ ### Logging
106
+
107
+ ```ruby
108
+ # Access logger
109
+ Shakapacker.logger
110
+ # => #<Logger>
111
+
112
+ # Redirect to STDOUT temporarily
113
+ Shakapacker.ensure_log_goes_to_stdout do
114
+ Shakapacker.compile
115
+ end
116
+ ```
117
+
118
+ ## Configuration API
119
+
120
+ The `Shakapacker::Configuration` class provides access to all settings from `config/shakapacker.yml`.
121
+
122
+ ### Accessing Configuration Data
123
+
124
+ ```ruby
125
+ config = Shakapacker.config
126
+
127
+ # Get raw configuration hash (public API as of v9.1.0)
128
+ config.data
129
+ # => { "source_path" => "app/javascript", ... }
130
+
131
+ # Access specific values
132
+ config.data["source_path"]
133
+ # => "app/javascript"
134
+ ```
135
+
136
+ **See Also:** [Configuration Guide](./configuration.md) for all available options.
137
+
138
+ ### Path Configuration
139
+
140
+ ```ruby
141
+ # Source paths
142
+ config.source_path # => #<Pathname:/app/app/javascript>
143
+ config.source_entry_path # => #<Pathname:/app/app/javascript/packs>
144
+ config.additional_paths # => [#<Pathname:/app/app/assets>, ...]
145
+
146
+ # Output paths
147
+ config.public_path # => #<Pathname:/app/public>
148
+ config.public_output_path # => "packs"
149
+ config.public_manifest_path # => #<Pathname:/app/public/packs/manifest.json>
150
+ ```
151
+
152
+ ### Bundler Detection
153
+
154
+ ```ruby
155
+ # Check which bundler is configured
156
+ config.webpack? # => true
157
+ config.rspack? # => false
158
+ config.bundler # => "webpack"
159
+
160
+ # Get bundler config path
161
+ config.assets_bundler_config_path
162
+ # => #<Pathname:/app/config/webpack/webpack.config.js>
163
+ ```
164
+
165
+ ### Compilation Settings
166
+
167
+ ```ruby
168
+ config.compile? # => true (auto-compile enabled?)
169
+ config.cache_manifest? # => false
170
+ config.extract_css? # => false (use MiniCssExtractPlugin?)
171
+ config.nested_entries? # => false
172
+ ```
173
+
174
+ ### Dev Server Configuration
175
+
176
+ ```ruby
177
+ dev_server = config.dev_server
178
+ dev_server["host"] # => "localhost"
179
+ dev_server["port"] # => 3035
180
+ dev_server["hmr"] # => true
181
+ dev_server["https"] # => false
182
+ ```
183
+
184
+ ## View Helpers
185
+
186
+ Shakapacker provides Rails view helpers in the `Shakapacker::Helper` module, automatically included in ActionView.
187
+
188
+ ### JavaScript Pack Tag
189
+
190
+ ```ruby
191
+ # Basic usage
192
+ <%= javascript_pack_tag 'application' %>
193
+ # => <script src="/packs/application-abc123.js" defer></script>
194
+
195
+ # Multiple packs (handles chunk deduplication)
196
+ <%= javascript_pack_tag 'calendar', 'map' %>
197
+
198
+ # Custom attributes
199
+ <%= javascript_pack_tag 'application', 'data-turbo-track': 'reload' %>
200
+
201
+ # Async loading
202
+ <%= javascript_pack_tag 'application', async: true %>
203
+
204
+ # Disable defer
205
+ <%= javascript_pack_tag 'application', defer: false %>
206
+
207
+ # Early hints configuration
208
+ <%= javascript_pack_tag 'application', early_hints: 'preload' %>
209
+ <%= javascript_pack_tag 'application', early_hints: false %>
210
+ ```
211
+
212
+ **Important:** Call `javascript_pack_tag` only once per page to avoid duplicate chunks.
213
+
214
+ ### Stylesheet Pack Tag
215
+
216
+ ```ruby
217
+ # Basic usage
218
+ <%= stylesheet_pack_tag 'application' %>
219
+ # => <link rel="stylesheet" href="/packs/application-abc123.css">
220
+
221
+ # Multiple packs with attributes
222
+ <%= stylesheet_pack_tag 'application', 'calendar', media: 'screen' %>
223
+
224
+ # Early hints
225
+ <%= stylesheet_pack_tag 'application', early_hints: 'preload' %>
226
+ ```
227
+
228
+ ### Dynamic Pack Loading
229
+
230
+ ```ruby
231
+ # In view or partial - queue packs
232
+ <% append_javascript_pack_tag 'calendar' %>
233
+ <% append_stylesheet_pack_tag 'calendar' %>
234
+
235
+ # Prepend to queue
236
+ <% prepend_javascript_pack_tag 'critical' %>
237
+
238
+ # In layout - render all queued packs
239
+ <%= javascript_pack_tag 'application' %>
240
+ <%= stylesheet_pack_tag 'application' %>
241
+ ```
242
+
243
+ ### Asset Helpers
244
+
245
+ ```ruby
246
+ # Get pack path
247
+ <%= asset_pack_path 'logo.svg' %>
248
+ # => "/packs/logo-abc123.svg"
249
+
250
+ # Get pack URL
251
+ <%= asset_pack_url 'logo.svg' %>
252
+ # => "https://cdn.example.com/packs/logo-abc123.svg"
253
+
254
+ # Image pack tag
255
+ <%= image_pack_tag 'logo.png', size: '16x10', alt: 'Logo' %>
256
+ # => <img src="/packs/logo-abc123.png" width="16" height="10" alt="Logo">
257
+
258
+ # With srcset
259
+ <%= image_pack_tag 'photo.png', srcset: { 'photo-2x.png' => '2x' } %>
260
+
261
+ # Favicon
262
+ <%= favicon_pack_tag 'icon.png', rel: 'apple-touch-icon' %>
263
+
264
+ # Preload asset
265
+ <%= preload_pack_asset 'fonts/custom.woff2' %>
266
+ ```
267
+
268
+ ## Manifest API
269
+
270
+ The `Shakapacker::Manifest` class handles asset lookup from the compiled manifest.
271
+
272
+ ### Basic Lookup
273
+
274
+ ```ruby
275
+ manifest = Shakapacker.manifest
276
+
277
+ # Look up an asset (returns nil if not found)
278
+ manifest.lookup("application.js")
279
+ # => "/packs/application-abc123.js"
280
+
281
+ # Look up with error on missing
282
+ manifest.lookup!("application.js")
283
+ # => "/packs/application-abc123.js" (raises if missing)
284
+ ```
285
+
286
+ ### Lookup with Type
287
+
288
+ ```ruby
289
+ # Lookup stylesheets
290
+ manifest.lookup("application.css")
291
+ # => "/packs/application-abc123.css"
292
+
293
+ # Lookup images
294
+ manifest.lookup("logo.svg")
295
+ # => "/packs/static/logo-abc123.svg"
296
+ ```
297
+
298
+ ### Full Manifest Access
299
+
300
+ ```ruby
301
+ # Get all entries
302
+ manifest.data
303
+ # => { "application.js" => "/packs/application-abc123.js", ... }
304
+
305
+ # Refresh manifest from disk
306
+ manifest.refresh
307
+ ```
308
+
309
+ ## Dev Server API
310
+
311
+ The `Shakapacker::DevServer` class provides status and configuration for the development server.
312
+
313
+ ### Status Checking
314
+
315
+ ```ruby
316
+ dev_server = Shakapacker.dev_server
317
+
318
+ # Check if running
319
+ dev_server.running?
320
+ # => true
321
+
322
+ # Get full status URL
323
+ dev_server.status_url
324
+ # => "http://localhost:3035"
325
+ ```
326
+
327
+ ### Configuration
328
+
329
+ ```ruby
330
+ dev_server.host
331
+ # => "localhost"
332
+
333
+ dev_server.port
334
+ # => 3035
335
+
336
+ dev_server.https?
337
+ # => false
338
+
339
+ dev_server.hmr?
340
+ # => true
341
+ ```
342
+
343
+ ### Proxying
344
+
345
+ ```ruby
346
+ # Get asset URL (uses dev server if running, otherwise public path)
347
+ dev_server.asset_url("application.js")
348
+ # => "http://localhost:3035/packs/application.js" (or "/packs/application.js")
349
+ ```
350
+
351
+ ## Compiler API
352
+
353
+ The `Shakapacker::Compiler` class handles compilation of webpack/rspack assets.
354
+
355
+ ### Compilation
356
+
357
+ ```ruby
358
+ compiler = Shakapacker.compiler
359
+
360
+ # Compile all packs
361
+ compiler.compile
362
+ # => true
363
+
364
+ # Check if compilation needed
365
+ compiler.stale?
366
+ # => false
367
+
368
+ # Get last compilation time
369
+ compiler.last_compilation_digest
370
+ # => "abc123..."
371
+ ```
372
+
373
+ ### Configuration
374
+
375
+ ```ruby
376
+ # Get watched paths
377
+ compiler.watched_paths
378
+ # => [#<Pathname:/app/app/javascript>, ...]
379
+
380
+ # Get config files
381
+ compiler.config_files
382
+ # => [#<Pathname:/app/config/webpack/webpack.config.js>, ...]
383
+ ```
384
+
385
+ ## Advanced Usage
386
+
387
+ ### Multiple Shakapacker Instances
388
+
389
+ For advanced scenarios like Rails engines with separate webpack configs:
390
+
391
+ ```ruby
392
+ # Create custom instance
393
+ custom_instance = Shakapacker::Instance.new(
394
+ root_path: Rails.root,
395
+ config_path: Rails.root.join("config/custom_shakapacker.yml")
396
+ )
397
+
398
+ # Use in view helper
399
+ def current_shakapacker_instance
400
+ @custom_instance ||= Shakapacker::Instance.new(...)
401
+ end
402
+ ```
403
+
404
+ ### Testing
405
+
406
+ ```ruby
407
+ # In tests, you can stub the instance
408
+ RSpec.describe "my feature" do
409
+ let(:mock_manifest) { instance_double(Shakapacker::Manifest) }
410
+ let(:mock_instance) { instance_double(Shakapacker::Instance, manifest: mock_manifest) }
411
+
412
+ before do
413
+ allow(Shakapacker).to receive(:instance).and_return(mock_instance)
414
+ end
415
+ end
416
+ ```
417
+
418
+ ### Programmatic Configuration Access
419
+
420
+ ```ruby
421
+ # Access raw configuration for custom tooling
422
+ config_data = Shakapacker.config.data
423
+
424
+ # Use in custom rake task
425
+ namespace :assets do
426
+ task :analyze do
427
+ config = Shakapacker.config
428
+ puts "Source: #{config.source_path}"
429
+ puts "Output: #{config.public_output_path}"
430
+ puts "Bundler: #{config.bundler}"
431
+ end
432
+ end
433
+ ```
434
+
435
+ ### Custom Webpack Configuration
436
+
437
+ Access Shakapacker config from your webpack config:
438
+
439
+ ```javascript
440
+ // config/webpack/webpack.config.js
441
+ const { generateWebpackConfig } = require("shakapacker")
442
+
443
+ // The shakapacker.yml is automatically loaded
444
+ const config = generateWebpackConfig()
445
+
446
+ console.log(config.output.path) // Uses public_output_path from shakapacker.yml
447
+ ```
448
+
449
+ ## Environment Variables
450
+
451
+ Shakapacker respects these environment variables:
452
+
453
+ | Variable | Purpose | Example |
454
+ | ---------------------------- | ----------------------------- | ------------------------- |
455
+ | `SHAKAPACKER_CONFIG` | Custom config file path | `/custom/shakapacker.yml` |
456
+ | `SHAKAPACKER_PRECOMPILE` | Enable/disable precompilation | `false` |
457
+ | `SHAKAPACKER_ASSET_HOST` | CDN hostname | `https://cdn.example.com` |
458
+ | `SHAKAPACKER_ASSETS_BUNDLER` | Override bundler selection | `rspack` |
459
+ | `RAILS_ENV` | Rails environment | `production` |
460
+ | `NODE_ENV` | Node environment | `production` |
461
+
462
+ ## Error Handling
463
+
464
+ ```ruby
465
+ # Manifest lookup errors
466
+ begin
467
+ path = Shakapacker.manifest.lookup!("missing.js")
468
+ rescue Shakapacker::Manifest::MissingEntryError => e
469
+ Rails.logger.error "Missing pack: #{e.message}"
470
+ end
471
+
472
+ # Compilation errors
473
+ begin
474
+ Shakapacker.compiler.compile
475
+ rescue Shakapacker::Compiler::CompilationError => e
476
+ Rails.logger.error "Compilation failed: #{e.message}"
477
+ end
478
+
479
+ # Configuration errors
480
+ begin
481
+ config = Shakapacker::Configuration.new(...)
482
+ rescue Shakapacker::Configuration::InvalidConfigurationError => e
483
+ Rails.logger.error "Invalid config: #{e.message}"
484
+ end
485
+ ```
486
+
487
+ ## Deprecations
488
+
489
+ Shakapacker follows semantic versioning. Deprecated methods will:
490
+
491
+ 1. Issue warnings in the current major version
492
+ 2. Be removed in the next major version
493
+
494
+ Check the [CHANGELOG](../CHANGELOG.md) for deprecation notices.
495
+
496
+ ## See Also
497
+
498
+ - [Configuration Guide](./configuration.md) - All `shakapacker.yml` options
499
+ - [View Helpers](../README.md#view-helpers) - Detailed view helper usage
500
+ - [Webpack Configuration](../README.md#webpack-configuration) - JavaScript API
501
+ - [TypeScript](./typescript.md) - Type definitions for Shakapacker
502
+ - [Troubleshooting](./troubleshooting.md) - Common issues
503
+
504
+ ## Generating Full API Documentation
505
+
506
+ For complete API documentation with all methods and parameters:
507
+
508
+ ```bash
509
+ # Using YARD (recommended)
510
+ gem install yard
511
+ yard doc
512
+ yard server # View at http://localhost:8808
513
+
514
+ # Using RDoc
515
+ rdoc lib/
516
+ open doc/index.html
517
+ ```
518
+
519
+ The generated documentation includes all public and private methods with detailed parameter descriptions.