shakapacker 9.1.0 → 9.3.0.beta.0
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.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +6 -9
- data/.github/ISSUE_TEMPLATE/feature_request.md +6 -8
- data/.github/workflows/claude-code-review.yml +4 -5
- data/.github/workflows/claude.yml +1 -2
- data/.github/workflows/dummy.yml +4 -4
- data/.github/workflows/generator.yml +9 -9
- data/.github/workflows/node.yml +11 -2
- data/.github/workflows/ruby.yml +16 -16
- data/.github/workflows/test-bundlers.yml +9 -9
- data/.gitignore +7 -0
- data/CHANGELOG.md +50 -4
- data/CLAUDE.md +6 -1
- data/CONTRIBUTING.md +0 -1
- data/Gemfile.lock +1 -1
- data/README.md +35 -14
- data/TODO.md +10 -2
- data/TODO_v9.md +13 -3
- data/bin/export-bundler-config +11 -0
- data/conductor-setup.sh +1 -1
- data/conductor.json +1 -1
- data/docs/cdn_setup.md +13 -8
- data/docs/common-upgrades.md +2 -1
- data/docs/configuration.md +630 -0
- data/docs/css-modules-export-mode.md +120 -100
- data/docs/customizing_babel_config.md +16 -16
- data/docs/deployment.md +68 -6
- data/docs/developing_shakapacker.md +6 -0
- data/docs/optional-peer-dependencies.md +9 -4
- data/docs/peer-dependencies.md +17 -6
- data/docs/precompile_hook.md +342 -0
- data/docs/react.md +57 -47
- data/docs/releasing.md +195 -0
- data/docs/rspack.md +25 -21
- data/docs/rspack_migration_guide.md +363 -8
- data/docs/sprockets.md +1 -0
- data/docs/style_loader_vs_mini_css.md +12 -12
- data/docs/subresource_integrity.md +13 -7
- data/docs/transpiler-performance.md +40 -19
- data/docs/troubleshooting.md +122 -23
- data/docs/typescript-migration.md +48 -39
- data/docs/typescript.md +12 -8
- data/docs/using_esbuild_loader.md +10 -10
- data/docs/v6_upgrade.md +33 -20
- data/docs/v7_upgrade.md +8 -6
- data/docs/v8_upgrade.md +13 -12
- data/docs/v9_upgrade.md +2 -1
- data/eslint.config.fast.js +134 -0
- data/eslint.config.js +140 -0
- data/knip.ts +54 -0
- data/lib/install/bin/export-bundler-config +11 -0
- data/lib/install/bin/shakapacker +1 -1
- data/lib/install/bin/shakapacker-dev-server +1 -1
- data/lib/install/config/shakapacker.yml +16 -5
- data/lib/shakapacker/bundler_switcher.rb +7 -0
- data/lib/shakapacker/compiler.rb +80 -0
- data/lib/shakapacker/configuration.rb +56 -2
- data/lib/shakapacker/dev_server_runner.rb +140 -1
- data/lib/shakapacker/doctor.rb +302 -57
- data/lib/shakapacker/instance.rb +8 -3
- data/lib/shakapacker/rspack_runner.rb +1 -1
- data/lib/shakapacker/runner.rb +245 -9
- data/lib/shakapacker/version.rb +1 -1
- data/lib/shakapacker/webpack_runner.rb +1 -1
- data/lib/shakapacker.rb +10 -0
- data/lib/tasks/shakapacker/doctor.rake +42 -2
- data/lib/tasks/shakapacker/export_bundler_config.rake +72 -0
- data/package/babel/preset.ts +7 -4
- data/package/config.ts +42 -30
- data/package/configExporter/cli.ts +1274 -0
- data/package/configExporter/configDocs.ts +102 -0
- data/package/configExporter/configFile.ts +520 -0
- data/package/configExporter/fileWriter.ts +96 -0
- data/package/configExporter/index.ts +13 -0
- data/package/configExporter/types.ts +70 -0
- data/package/configExporter/yamlSerializer.ts +280 -0
- data/package/dev_server.ts +1 -1
- data/package/environments/__type-tests__/rspack-plugin-compatibility.ts +11 -5
- data/package/environments/base.ts +18 -13
- data/package/environments/development.ts +1 -1
- data/package/environments/production.ts +4 -1
- data/package/index.d.ts +50 -3
- data/package/index.d.ts.template +50 -0
- data/package/index.ts +7 -7
- data/package/loaders.d.ts +2 -2
- data/package/optimization/rspack.ts +1 -1
- data/package/plugins/rspack.ts +15 -4
- data/package/plugins/webpack.ts +7 -3
- data/package/rspack/index.ts +10 -2
- data/package/rules/raw.ts +3 -2
- data/package/rules/sass.ts +1 -1
- data/package/types/README.md +15 -13
- data/package/types/index.ts +5 -5
- data/package/types.ts +0 -1
- data/package/utils/defaultConfigPath.ts +4 -1
- data/package/utils/errorCodes.ts +129 -100
- data/package/utils/errorHelpers.ts +34 -29
- data/package/utils/getStyleRule.ts +5 -2
- data/package/utils/helpers.ts +21 -11
- data/package/utils/pathValidation.ts +43 -35
- data/package/utils/requireOrError.ts +1 -1
- data/package/utils/snakeToCamelCase.ts +1 -1
- data/package/utils/typeGuards.ts +132 -83
- data/package/utils/validateDependencies.ts +1 -1
- data/package/webpack-types.d.ts +3 -3
- data/package/webpackDevServerConfig.ts +22 -10
- data/package-lock.json +2 -2
- data/package.json +37 -28
- data/scripts/type-check-no-emit.js +1 -1
- data/test/configExporter/configFile.test.js +392 -0
- data/test/configExporter/integration.test.js +275 -0
- data/test/helpers.js +1 -1
- data/test/package/configExporter.test.js +154 -0
- data/test/package/helpers.test.js +2 -2
- data/test/package/rules/sass-version-parsing.test.js +71 -0
- data/test/package/rules/sass.test.js +2 -4
- data/test/package/rules/sass1.test.js +1 -3
- data/test/package/rules/sass16.test.js +23 -0
- data/tools/README.md +15 -5
- data/tsconfig.eslint.json +2 -9
- data/yarn.lock +1635 -1442
- metadata +29 -3
- data/.eslintignore +0 -5
|
@@ -4,15 +4,16 @@ This document provides performance benchmarks comparing different JavaScript tra
|
|
|
4
4
|
|
|
5
5
|
## Executive Summary
|
|
6
6
|
|
|
7
|
-
| Transpiler
|
|
8
|
-
|
|
9
|
-
| **SWC**
|
|
10
|
-
| **esbuild** | **15x faster** | Minimal config
|
|
11
|
-
| **Babel**
|
|
7
|
+
| Transpiler | Relative Speed | Configuration | Best For |
|
|
8
|
+
| ----------- | -------------- | ---------------- | ---------------------------------------------- |
|
|
9
|
+
| **SWC** | **20x faster** | Zero config | Production builds, large codebases |
|
|
10
|
+
| **esbuild** | **15x faster** | Minimal config | Modern browsers, simple transformations |
|
|
11
|
+
| **Babel** | **Baseline** | Extensive config | Legacy browser support, custom transformations |
|
|
12
12
|
|
|
13
13
|
## Detailed Benchmarks
|
|
14
14
|
|
|
15
15
|
### Test Environment
|
|
16
|
+
|
|
16
17
|
- **Hardware**: MacBook Pro M1, 16GB RAM
|
|
17
18
|
- **Node Version**: 20.x
|
|
18
19
|
- **Project Size Categories**:
|
|
@@ -23,6 +24,7 @@ This document provides performance benchmarks comparing different JavaScript tra
|
|
|
23
24
|
### Build Time Comparison
|
|
24
25
|
|
|
25
26
|
#### Small Project (<100 files, ~50KB total)
|
|
27
|
+
|
|
26
28
|
```text
|
|
27
29
|
SWC: 0.3s (20x faster)
|
|
28
30
|
esbuild: 0.4s (15x faster)
|
|
@@ -30,6 +32,7 @@ Babel: 6.0s (baseline)
|
|
|
30
32
|
```
|
|
31
33
|
|
|
32
34
|
#### Medium Project (500 files, ~2MB total)
|
|
35
|
+
|
|
33
36
|
```text
|
|
34
37
|
SWC: 1.2s (25x faster)
|
|
35
38
|
esbuild: 1.8s (17x faster)
|
|
@@ -37,6 +40,7 @@ Babel: 30s (baseline)
|
|
|
37
40
|
```
|
|
38
41
|
|
|
39
42
|
#### Large Project (2000 files, ~10MB total)
|
|
43
|
+
|
|
40
44
|
```text
|
|
41
45
|
SWC: 4.5s (22x faster)
|
|
42
46
|
esbuild: 6.2s (16x faster)
|
|
@@ -45,25 +49,26 @@ Babel: 100s (baseline)
|
|
|
45
49
|
|
|
46
50
|
### Memory Usage
|
|
47
51
|
|
|
48
|
-
| Transpiler
|
|
49
|
-
|
|
50
|
-
| **SWC**
|
|
51
|
-
| **esbuild** | 180MB
|
|
52
|
-
| **Babel**
|
|
52
|
+
| Transpiler | Peak Memory (Small) | Peak Memory (Medium) | Peak Memory (Large) |
|
|
53
|
+
| ----------- | ------------------- | -------------------- | ------------------- |
|
|
54
|
+
| **SWC** | 150MB | 250MB | 450MB |
|
|
55
|
+
| **esbuild** | 180MB | 300MB | 500MB |
|
|
56
|
+
| **Babel** | 350MB | 600MB | 1200MB |
|
|
53
57
|
|
|
54
58
|
## Incremental Build Performance
|
|
55
59
|
|
|
56
60
|
For development with watch mode enabled:
|
|
57
61
|
|
|
58
|
-
| Transpiler
|
|
59
|
-
|
|
60
|
-
| **SWC**
|
|
61
|
-
| **esbuild** | 1.8s
|
|
62
|
-
| **Babel**
|
|
62
|
+
| Transpiler | Initial Build | Incremental Build | HMR Update |
|
|
63
|
+
| ----------- | ------------- | ----------------- | ---------- |
|
|
64
|
+
| **SWC** | 1.2s | 0.1s | <50ms |
|
|
65
|
+
| **esbuild** | 1.8s | 0.15s | <70ms |
|
|
66
|
+
| **Babel** | 30s | 2-5s | 200-500ms |
|
|
63
67
|
|
|
64
68
|
## Feature Comparison
|
|
65
69
|
|
|
66
70
|
### SWC
|
|
71
|
+
|
|
67
72
|
- ✅ TypeScript support built-in
|
|
68
73
|
- ✅ JSX/TSX transformation
|
|
69
74
|
- ✅ Minification built-in
|
|
@@ -73,6 +78,7 @@ For development with watch mode enabled:
|
|
|
73
78
|
- ⚠️ Newer, less battle-tested
|
|
74
79
|
|
|
75
80
|
### esbuild
|
|
81
|
+
|
|
76
82
|
- ✅ TypeScript support built-in
|
|
77
83
|
- ✅ JSX transformation
|
|
78
84
|
- ✅ Extremely fast bundling
|
|
@@ -81,6 +87,7 @@ For development with watch mode enabled:
|
|
|
81
87
|
- ❌ No plugin system for custom transforms
|
|
82
88
|
|
|
83
89
|
### Babel
|
|
90
|
+
|
|
84
91
|
- ✅ Most comprehensive browser support
|
|
85
92
|
- ✅ Extensive plugin ecosystem
|
|
86
93
|
- ✅ Custom transformation support
|
|
@@ -91,6 +98,7 @@ For development with watch mode enabled:
|
|
|
91
98
|
## Recommendations by Use Case
|
|
92
99
|
|
|
93
100
|
### Choose SWC when:
|
|
101
|
+
|
|
94
102
|
- Performance is critical
|
|
95
103
|
- Using modern JavaScript/TypeScript
|
|
96
104
|
- Building large applications
|
|
@@ -98,12 +106,14 @@ For development with watch mode enabled:
|
|
|
98
106
|
- Default choice for new projects
|
|
99
107
|
|
|
100
108
|
### Choose esbuild when:
|
|
109
|
+
|
|
101
110
|
- Need the absolute fastest builds
|
|
102
111
|
- Targeting modern browsers only
|
|
103
112
|
- Simple transformation requirements
|
|
104
113
|
- Minimal configuration preferred
|
|
105
114
|
|
|
106
115
|
### Choose Babel when:
|
|
116
|
+
|
|
107
117
|
- Need extensive browser compatibility (IE11, etc.)
|
|
108
118
|
- Using experimental JavaScript features
|
|
109
119
|
- Require specific Babel plugins
|
|
@@ -112,6 +122,7 @@ For development with watch mode enabled:
|
|
|
112
122
|
## Migration Impact
|
|
113
123
|
|
|
114
124
|
### From Babel to SWC
|
|
125
|
+
|
|
115
126
|
- **Build time reduction**: 90-95%
|
|
116
127
|
- **Memory usage reduction**: 50-70%
|
|
117
128
|
- **Configuration simplification**: 80% less config
|
|
@@ -120,16 +131,19 @@ For development with watch mode enabled:
|
|
|
120
131
|
### Real-world Examples
|
|
121
132
|
|
|
122
133
|
#### E-commerce Platform (1500 components)
|
|
134
|
+
|
|
123
135
|
- **Before (Babel)**: 120s production build
|
|
124
136
|
- **After (SWC)**: 5.5s production build
|
|
125
137
|
- **Improvement**: 95.4% faster
|
|
126
138
|
|
|
127
139
|
#### SaaS Dashboard (800 files)
|
|
140
|
+
|
|
128
141
|
- **Before (Babel)**: 45s development build
|
|
129
142
|
- **After (SWC)**: 2.1s development build
|
|
130
143
|
- **Improvement**: 95.3% faster
|
|
131
144
|
|
|
132
145
|
#### Blog Platform (200 files)
|
|
146
|
+
|
|
133
147
|
- **Before (Babel)**: 15s build time
|
|
134
148
|
- **After (SWC)**: 0.8s build time
|
|
135
149
|
- **Improvement**: 94.7% faster
|
|
@@ -137,28 +151,34 @@ For development with watch mode enabled:
|
|
|
137
151
|
## How to Switch Transpilers
|
|
138
152
|
|
|
139
153
|
### To SWC (Recommended)
|
|
154
|
+
|
|
140
155
|
```yaml
|
|
141
156
|
# config/shakapacker.yml
|
|
142
|
-
javascript_transpiler:
|
|
157
|
+
javascript_transpiler: "swc"
|
|
143
158
|
```
|
|
159
|
+
|
|
144
160
|
```bash
|
|
145
161
|
npm install @swc/core swc-loader
|
|
146
162
|
```
|
|
147
163
|
|
|
148
164
|
### To esbuild
|
|
165
|
+
|
|
149
166
|
```yaml
|
|
150
167
|
# config/shakapacker.yml
|
|
151
|
-
javascript_transpiler:
|
|
168
|
+
javascript_transpiler: "esbuild"
|
|
152
169
|
```
|
|
170
|
+
|
|
153
171
|
```bash
|
|
154
172
|
npm install esbuild esbuild-loader
|
|
155
173
|
```
|
|
156
174
|
|
|
157
175
|
### To Babel
|
|
176
|
+
|
|
158
177
|
```yaml
|
|
159
178
|
# config/shakapacker.yml
|
|
160
|
-
javascript_transpiler:
|
|
179
|
+
javascript_transpiler: "babel"
|
|
161
180
|
```
|
|
181
|
+
|
|
162
182
|
```bash
|
|
163
183
|
npm install babel-loader @babel/core @babel/preset-env
|
|
164
184
|
```
|
|
@@ -166,6 +186,7 @@ npm install babel-loader @babel/core @babel/preset-env
|
|
|
166
186
|
## Testing Methodology
|
|
167
187
|
|
|
168
188
|
Benchmarks were conducted using:
|
|
189
|
+
|
|
169
190
|
1. Clean builds (no cache)
|
|
170
191
|
2. Average of 10 runs
|
|
171
192
|
3. Same source code for all transpilers
|
|
@@ -176,4 +197,4 @@ Benchmarks were conducted using:
|
|
|
176
197
|
|
|
177
198
|
For most projects, **SWC provides the best balance** of performance, features, and ease of use. It offers a 20x performance improvement over Babel with minimal configuration required.
|
|
178
199
|
|
|
179
|
-
Consider your specific requirements around browser support, plugin needs, and existing infrastructure when choosing a transpiler. The performance gains from switching to SWC or esbuild can significantly improve developer productivity and CI/CD pipeline efficiency.
|
|
200
|
+
Consider your specific requirements around browser support, plugin needs, and existing infrastructure when choosing a transpiler. The performance gains from switching to SWC or esbuild can significantly improve developer productivity and CI/CD pipeline efficiency.
|
data/docs/troubleshooting.md
CHANGED
|
@@ -17,12 +17,70 @@
|
|
|
17
17
|
|
|
18
18
|
4. You can also pass additional options to the command to run the webpack-dev-server and start the webpack-dev-server with the option `--debug-shakapacker`
|
|
19
19
|
|
|
20
|
-
5.
|
|
20
|
+
5. **Export your full webpack/rspack configuration for analysis**: Use the `bin/export-bundler-config` utility to export your complete resolved configuration. This is especially helpful for:
|
|
21
|
+
- **Migrations**: Comparing configurations before and after migrating between webpack and rspack, or between different Shakapacker versions
|
|
22
|
+
- **Debugging**: Inspecting the exact configuration webpack/rspack is using, including all merged settings
|
|
23
|
+
- **AI Analysis**: Uploading the exported config to ChatGPT or other AI tools for troubleshooting
|
|
24
|
+
|
|
25
|
+
**Installation**: The utility is installed when you run `rake shakapacker:binstubs` or can be used directly via `rake shakapacker:export_bundler_config`.
|
|
26
|
+
|
|
27
|
+
**RECOMMENDED - Quick troubleshooting:**
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Install the binstub (one-time setup)
|
|
31
|
+
rake shakapacker:binstubs
|
|
32
|
+
|
|
33
|
+
# Export EVERYTHING for troubleshooting (dev + prod, annotated YAML)
|
|
34
|
+
bin/export-bundler-config --doctor
|
|
35
|
+
# Creates: webpack-development-client.yaml, webpack-development-server.yaml,
|
|
36
|
+
# webpack-production-client.yaml, webpack-production-server.yaml
|
|
21
37
|
```
|
|
38
|
+
|
|
39
|
+
**Other usage examples:**
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# Save current environment configs with auto-generated names
|
|
43
|
+
bin/export-bundler-config --save
|
|
44
|
+
# Creates: webpack-development-client.yaml, webpack-development-server.yaml
|
|
45
|
+
|
|
46
|
+
# Save to specific directory
|
|
47
|
+
bin/export-bundler-config --save --save-dir=./debug-configs
|
|
48
|
+
|
|
49
|
+
# Export only client config for production
|
|
50
|
+
bin/export-bundler-config --save --env=production --client-only
|
|
51
|
+
# Creates: webpack-production-client.yaml
|
|
52
|
+
|
|
53
|
+
# Compare development vs production configs
|
|
54
|
+
bin/export-bundler-config --save --save-dir=./configs
|
|
55
|
+
diff configs/webpack-development-client.yaml configs/webpack-production-client.yaml
|
|
56
|
+
|
|
57
|
+
# View config in terminal (no files created)
|
|
58
|
+
bin/export-bundler-config
|
|
59
|
+
|
|
60
|
+
# Export without inline documentation annotations
|
|
61
|
+
bin/export-bundler-config --save --no-annotate
|
|
62
|
+
|
|
63
|
+
# Export in JSON format for programmatic analysis
|
|
64
|
+
bin/export-bundler-config --save --format=json
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Config files are automatically named:** `{bundler}-{env}-{type}.{ext}`
|
|
68
|
+
- Examples: `webpack-development-client.yaml`, `rspack-production-server.yaml`
|
|
69
|
+
- YAML format includes inline documentation explaining each config key
|
|
70
|
+
- Separate files for client and server bundles (cleaner than combined)
|
|
71
|
+
|
|
72
|
+
See `bin/export-bundler-config --help` for all available options.
|
|
73
|
+
|
|
74
|
+
6. Generate webpack stats for build analysis (useful for bundle size optimization):
|
|
75
|
+
|
|
76
|
+
```bash
|
|
22
77
|
NODE_ENV=development bin/shakapacker --profile --json > /tmp/webpack-stats.json
|
|
23
78
|
```
|
|
24
79
|
|
|
80
|
+
ChatGPT and other AI tools can consume this output file. Change the NODE_ENV per your needs.
|
|
81
|
+
|
|
25
82
|
## Incorrect peer dependencies
|
|
83
|
+
|
|
26
84
|
Shakapacker uses peer dependencies to make it easier to manage what versions are being used for your app, which is especially
|
|
27
85
|
useful for patching security vulnerabilities. However, not all package managers will actually enforce these versions - notably,
|
|
28
86
|
Yarn will omit a warning rather than erroring if you forget to update a peer dependency:
|
|
@@ -32,6 +90,7 @@ warning " > shakapacker@6.1.1" has incorrect peer dependency "compression-webpac
|
|
|
32
90
|
```
|
|
33
91
|
|
|
34
92
|
This omission resulted in an error in the browser:
|
|
93
|
+
|
|
35
94
|
```
|
|
36
95
|
Failed to load resource: net::ERR_CONTENT_DECODING_FAILED
|
|
37
96
|
```
|
|
@@ -40,6 +99,40 @@ The error was caused by an old version of the peer dependency `webpack-compressi
|
|
|
40
99
|
|
|
41
100
|
So, be sure to investigate warnings from `yarn install`!
|
|
42
101
|
|
|
102
|
+
## NoMethodError: undefined method 'deep_symbolize_keys' for nil:NilClass
|
|
103
|
+
|
|
104
|
+
If you see this error during deployment (especially on Heroku with a staging environment):
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
NoMethodError: undefined method 'deep_symbolize_keys' for nil:NilClass
|
|
108
|
+
from shakapacker/configuration.rb:XXX:in 'load'
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
This happens when deploying to a custom Rails environment (like `staging`) that isn't explicitly defined in your `config/shakapacker.yml` file.
|
|
112
|
+
|
|
113
|
+
**Solution:** This was fixed in Shakapacker v9.1.1+. Upgrade to the latest version:
|
|
114
|
+
|
|
115
|
+
```ruby
|
|
116
|
+
# Gemfile
|
|
117
|
+
gem 'shakapacker', '~> 9.1'
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
After upgrading, Shakapacker will automatically fall back to sensible defaults when your environment isn't defined:
|
|
121
|
+
|
|
122
|
+
1. First tries your environment (e.g., `staging`)
|
|
123
|
+
2. Falls back to `production` configuration
|
|
124
|
+
|
|
125
|
+
**Alternative:** If you can't upgrade immediately, explicitly add your environment to `config/shakapacker.yml`:
|
|
126
|
+
|
|
127
|
+
```yaml
|
|
128
|
+
staging:
|
|
129
|
+
<<: *default
|
|
130
|
+
compile: false
|
|
131
|
+
cache_manifest: true
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
See the [deployment guide](./deployment.md#custom-rails-environments-eg-staging) for more details.
|
|
135
|
+
|
|
43
136
|
## ENOENT: no such file or directory - node-sass
|
|
44
137
|
|
|
45
138
|
If you get the error `ENOENT: no such file or directory - node-sass` on deploy with
|
|
@@ -54,7 +147,7 @@ thing, like Heroku.
|
|
|
54
147
|
|
|
55
148
|
However, if you get this on local development, or not during a deploy then you
|
|
56
149
|
may need to rebuild `node-sass`. It's a bit of a weird error; basically, it
|
|
57
|
-
can't find the `node-sass` binary.
|
|
150
|
+
can't find the `node-sass` binary. An easy solution is to create a postinstall
|
|
58
151
|
hook to ensure `node-sass` is rebuilt whenever new modules are installed.
|
|
59
152
|
|
|
60
153
|
In `package.json`:
|
|
@@ -67,19 +160,18 @@ In `package.json`:
|
|
|
67
160
|
|
|
68
161
|
## Can't find hello_react.js in manifest.json
|
|
69
162
|
|
|
70
|
-
|
|
71
|
-
when loading a view in the browser it's because webpack is still compiling packs.
|
|
72
|
-
Shakapacker uses a `manifest.json` file to keep track of packs in all environments,
|
|
73
|
-
however since this file is generated after packs are compiled by webpack. So,
|
|
74
|
-
if you load a view in browser whilst webpack is compiling you will get this error.
|
|
75
|
-
Therefore, make sure webpack
|
|
76
|
-
(i.e `./bin/shakapacker-dev-server`) is running and has
|
|
77
|
-
completed the compilation successfully before loading a view.
|
|
78
|
-
|
|
163
|
+
- If you get this error `Can't find hello_react.js in manifest.json`
|
|
164
|
+
when loading a view in the browser it's because webpack is still compiling packs.
|
|
165
|
+
Shakapacker uses a `manifest.json` file to keep track of packs in all environments,
|
|
166
|
+
however since this file is generated after packs are compiled by webpack. So,
|
|
167
|
+
if you load a view in browser whilst webpack is compiling you will get this error.
|
|
168
|
+
Therefore, make sure webpack
|
|
169
|
+
(i.e `./bin/shakapacker-dev-server`) is running and has
|
|
170
|
+
completed the compilation successfully before loading a view.
|
|
79
171
|
|
|
80
172
|
## throw er; // Unhandled 'error' event
|
|
81
173
|
|
|
82
|
-
|
|
174
|
+
- If you get this error while trying to use Elm, try rebuilding Elm. You can do
|
|
83
175
|
so with a postinstall hook in your `package.json`:
|
|
84
176
|
|
|
85
177
|
```json
|
|
@@ -90,9 +182,9 @@ completed the compilation successfully before loading a view.
|
|
|
90
182
|
|
|
91
183
|
## webpack or webpack-dev-server not found
|
|
92
184
|
|
|
93
|
-
|
|
185
|
+
- This could happen if `shakapacker:install` step is skipped. Please run `bundle exec rails shakapacker:install` to fix the issue.
|
|
94
186
|
|
|
95
|
-
|
|
187
|
+
- If you encounter the above error on heroku after upgrading from Rails 4.x to 5.1.x, then the problem might be related to missing `yarn` binstub. Please run following commands to update/add binstubs:
|
|
96
188
|
|
|
97
189
|
```bash
|
|
98
190
|
bundle config --delete bin
|
|
@@ -137,6 +229,7 @@ chmod +x $HOME/your_rails_app/node_modules/.bin/elm-make
|
|
|
137
229
|
```
|
|
138
230
|
|
|
139
231
|
## Rake assets:precompile fails. ExecJS::RuntimeError
|
|
232
|
+
|
|
140
233
|
This error occurs because you are trying to minify by `terser` a pack that's already been minified by Shakapacker. To avoid this conflict and prevent appearing of `ExecJS::RuntimeError` error, you will need to disable uglifier from Rails config:
|
|
141
234
|
|
|
142
235
|
```ruby
|
|
@@ -152,10 +245,11 @@ Rails.application.config.assets.js_compressor = Uglifier.new(harmony: true)
|
|
|
152
245
|
### Angular: WARNING in ./node_modules/@angular/core/esm5/core.js, Critical dependency: the request of a dependency is an expression
|
|
153
246
|
|
|
154
247
|
To silent these warnings, please update `config/webpack/webpack.config.js`:
|
|
248
|
+
|
|
155
249
|
```js
|
|
156
|
-
const webpack = require(
|
|
157
|
-
const { resolve } = require(
|
|
158
|
-
const { generateWebpackConfig } = require(
|
|
250
|
+
const webpack = require("webpack")
|
|
251
|
+
const { resolve } = require("path")
|
|
252
|
+
const { generateWebpackConfig } = require("shakapacker")
|
|
159
253
|
|
|
160
254
|
module.exports = generateWebpackConfig({
|
|
161
255
|
plugins: [
|
|
@@ -192,6 +286,7 @@ Thus ProvidePlugin manages build-time dependencies to global symbols whereas the
|
|
|
192
286
|
**You don't need to assign dependencies on `window`.**
|
|
193
287
|
|
|
194
288
|
For instance, with [jQuery](https://jquery.com/):
|
|
289
|
+
|
|
195
290
|
```diff
|
|
196
291
|
// app/javascript/entrypoints/application.js
|
|
197
292
|
|
|
@@ -200,19 +295,20 @@ For instance, with [jQuery](https://jquery.com/):
|
|
|
200
295
|
```
|
|
201
296
|
|
|
202
297
|
Instead do:
|
|
298
|
+
|
|
203
299
|
```js
|
|
204
300
|
// config/webpack/webpack.config.js
|
|
205
301
|
|
|
206
|
-
const webpack = require(
|
|
207
|
-
const { generateWebpackConfig } = require(
|
|
302
|
+
const webpack = require("webpack")
|
|
303
|
+
const { generateWebpackConfig } = require("shakapacker")
|
|
208
304
|
|
|
209
305
|
module.exports = generateWebpackConfig({
|
|
210
306
|
plugins: [
|
|
211
307
|
new webpack.ProvidePlugin({
|
|
212
|
-
$:
|
|
213
|
-
jQuery:
|
|
308
|
+
$: "jquery",
|
|
309
|
+
jQuery: "jquery"
|
|
214
310
|
})
|
|
215
|
-
]
|
|
311
|
+
]
|
|
216
312
|
})
|
|
217
313
|
```
|
|
218
314
|
|
|
@@ -225,7 +321,7 @@ application is using your staging `config.asset_host` host when using
|
|
|
225
321
|
|
|
226
322
|
This can be fixed by setting the environment variable `SHAKAPACKER_ASSET_HOST` to
|
|
227
323
|
an empty string where your assets are compiled. On Heroku this is done under
|
|
228
|
-
|
|
324
|
+
_Settings_ -> _Config Vars_.
|
|
229
325
|
|
|
230
326
|
This way shakapacker won't hard-code the CDN host into the manifest file used by
|
|
231
327
|
`javascript_pack_tag`, but instead fetch the CDN host at runtime, resolving the
|
|
@@ -243,6 +339,7 @@ In order to generate the storage path, we rely on the filename that's [provided
|
|
|
243
339
|
This usually works out of the box. There's a potential problem however, if you use the [context setting](https://webpack.js.org/configuration/entry-context/#context) in your webpack config. By default this is set to current Node working directory/project root.
|
|
244
340
|
|
|
245
341
|
If you were to override it like:
|
|
342
|
+
|
|
246
343
|
```
|
|
247
344
|
{
|
|
248
345
|
context: path.resolve(__dirname, '../../app/javascript')
|
|
@@ -252,12 +349,14 @@ If you were to override it like:
|
|
|
252
349
|
Then the filename available in the rule generator will be relative to that directory.
|
|
253
350
|
|
|
254
351
|
This means for example:
|
|
352
|
+
|
|
255
353
|
- a static asset from `node_modules` folder could end up being referenced with path of `../../node_modules/some_module/static_file.jpg` rather than simply `node_modules/some_module/static_file.jpg`.
|
|
256
354
|
- a static asset in one of the `additional_paths`, example `app/assets/images/image.jpg`, would end up being referenced with path of `../assets/images/image.jpg`.
|
|
257
355
|
|
|
258
356
|
Those paths are later passed to [output path generation in the rule](https://github.com/shakacode/shakapacker/blob/e52b335dbabfb934fe7d3076a8322b97d5ef3470/package/rules/file.js#L25-L26), where we would end up with a path like `static/../../node_modules/some_module/static_file.jpg`, resulting in the file being output in a location two directories above the desired path.
|
|
259
357
|
|
|
260
358
|
You can avoid this by:
|
|
359
|
+
|
|
261
360
|
- not using overridden `context` in your webpack config, if there's no good reason for it.
|
|
262
361
|
- using custom Webpack config to modify the static file rule, following a similar process as outlined in the [Webpack Configuration](https://github.com/shakacode/shakapacker/blob/main/README.md#webpack-configuration) section of the readme.
|
|
263
362
|
|