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
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
This guide helps you adopt TypeScript types in your Shakapacker configuration files for better type safety and IDE support.
|
|
4
4
|
|
|
5
5
|
## Table of Contents
|
|
6
|
+
|
|
6
7
|
- [Benefits](#benefits)
|
|
7
8
|
- [Quick Start](#quick-start)
|
|
8
9
|
- [Migration Steps](#migration-steps)
|
|
@@ -12,6 +13,7 @@ This guide helps you adopt TypeScript types in your Shakapacker configuration fi
|
|
|
12
13
|
## Benefits
|
|
13
14
|
|
|
14
15
|
Using TypeScript with Shakapacker provides:
|
|
16
|
+
|
|
15
17
|
- **Type Safety**: Catch configuration errors at compile time
|
|
16
18
|
- **IDE Support**: Get autocompletion and inline documentation
|
|
17
19
|
- **Better Refactoring**: Safely rename and restructure configurations
|
|
@@ -56,13 +58,13 @@ Rename `config/webpack/webpack.config.js` to `config/webpack/webpack.config.ts`:
|
|
|
56
58
|
|
|
57
59
|
```typescript
|
|
58
60
|
// config/webpack/webpack.config.ts
|
|
59
|
-
import { generateWebpackConfig, merge } from
|
|
60
|
-
import type { WebpackConfigWithDevServer } from
|
|
61
|
-
import type { Configuration } from
|
|
61
|
+
import { generateWebpackConfig, merge } from "shakapacker"
|
|
62
|
+
import type { WebpackConfigWithDevServer } from "shakapacker/types"
|
|
63
|
+
import type { Configuration } from "webpack"
|
|
62
64
|
|
|
63
65
|
const customConfig: Configuration = {
|
|
64
66
|
resolve: {
|
|
65
|
-
extensions: [
|
|
67
|
+
extensions: [".css", ".ts", ".tsx"]
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
|
|
@@ -83,7 +85,7 @@ import type {
|
|
|
83
85
|
WebpackConfigWithDevServer,
|
|
84
86
|
RspackConfigWithDevServer,
|
|
85
87
|
CompressionPluginOptions
|
|
86
|
-
} from
|
|
88
|
+
} from "shakapacker/types"
|
|
87
89
|
```
|
|
88
90
|
|
|
89
91
|
### Step 2: Type Your Configuration Objects
|
|
@@ -94,16 +96,16 @@ Add type annotations to your configuration objects:
|
|
|
94
96
|
// Before (JavaScript)
|
|
95
97
|
const customConfig = {
|
|
96
98
|
resolve: {
|
|
97
|
-
extensions: [
|
|
99
|
+
extensions: [".css", ".ts", ".tsx"]
|
|
98
100
|
}
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
// After (TypeScript)
|
|
102
|
-
import type { Configuration } from
|
|
104
|
+
import type { Configuration } from "webpack"
|
|
103
105
|
|
|
104
106
|
const customConfig: Configuration = {
|
|
105
107
|
resolve: {
|
|
106
|
-
extensions: [
|
|
108
|
+
extensions: [".css", ".ts", ".tsx"]
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
111
|
```
|
|
@@ -120,8 +122,8 @@ function modifyConfig(config) {
|
|
|
120
122
|
}
|
|
121
123
|
|
|
122
124
|
// After (TypeScript)
|
|
123
|
-
import type { Configuration } from
|
|
124
|
-
import type { WebpackPluginInstance } from
|
|
125
|
+
import type { Configuration } from "webpack"
|
|
126
|
+
import type { WebpackPluginInstance } from "shakapacker/types"
|
|
125
127
|
|
|
126
128
|
function modifyConfig(config: Configuration): Configuration {
|
|
127
129
|
const plugins = config.plugins as WebpackPluginInstance[]
|
|
@@ -134,11 +136,11 @@ function modifyConfig(config: Configuration): Configuration {
|
|
|
134
136
|
|
|
135
137
|
```typescript
|
|
136
138
|
// config/webpack/development.ts
|
|
137
|
-
import { generateWebpackConfig } from
|
|
138
|
-
import type { WebpackConfigWithDevServer } from
|
|
139
|
+
import { generateWebpackConfig } from "shakapacker"
|
|
140
|
+
import type { WebpackConfigWithDevServer } from "shakapacker/types"
|
|
139
141
|
|
|
140
142
|
const developmentConfig: WebpackConfigWithDevServer = generateWebpackConfig({
|
|
141
|
-
devtool:
|
|
143
|
+
devtool: "eval-cheap-module-source-map",
|
|
142
144
|
devServer: {
|
|
143
145
|
hot: true,
|
|
144
146
|
port: 3035
|
|
@@ -153,11 +155,11 @@ export default developmentConfig
|
|
|
153
155
|
### Pattern 1: Custom Loaders
|
|
154
156
|
|
|
155
157
|
```typescript
|
|
156
|
-
import type { RuleSetRule } from
|
|
158
|
+
import type { RuleSetRule } from "webpack"
|
|
157
159
|
|
|
158
160
|
const customLoader: RuleSetRule = {
|
|
159
161
|
test: /\.svg$/,
|
|
160
|
-
use: [
|
|
162
|
+
use: ["@svgr/webpack"]
|
|
161
163
|
}
|
|
162
164
|
|
|
163
165
|
const config: Configuration = generateWebpackConfig({
|
|
@@ -170,12 +172,12 @@ const config: Configuration = generateWebpackConfig({
|
|
|
170
172
|
### Pattern 2: Plugin Configuration
|
|
171
173
|
|
|
172
174
|
```typescript
|
|
173
|
-
import CompressionPlugin from
|
|
174
|
-
import type { CompressionPluginOptions } from
|
|
175
|
+
import CompressionPlugin from "compression-webpack-plugin"
|
|
176
|
+
import type { CompressionPluginOptions } from "shakapacker/types"
|
|
175
177
|
|
|
176
178
|
const compressionOptions: CompressionPluginOptions = {
|
|
177
|
-
filename:
|
|
178
|
-
algorithm:
|
|
179
|
+
filename: "[path][base].gz",
|
|
180
|
+
algorithm: "gzip",
|
|
179
181
|
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf)$/
|
|
180
182
|
}
|
|
181
183
|
|
|
@@ -187,8 +189,8 @@ const config: Configuration = generateWebpackConfig({
|
|
|
187
189
|
### Pattern 3: Conditional Configuration
|
|
188
190
|
|
|
189
191
|
```typescript
|
|
190
|
-
import type { Configuration } from
|
|
191
|
-
import { env } from
|
|
192
|
+
import type { Configuration } from "webpack"
|
|
193
|
+
import { env } from "shakapacker"
|
|
192
194
|
|
|
193
195
|
const config: Configuration = generateWebpackConfig()
|
|
194
196
|
|
|
@@ -208,11 +210,11 @@ export default config
|
|
|
208
210
|
|
|
209
211
|
```typescript
|
|
210
212
|
// config/rspack/rspack.config.ts
|
|
211
|
-
import type { RspackConfigWithDevServer } from
|
|
212
|
-
import { generateWebpackConfig } from
|
|
213
|
+
import type { RspackConfigWithDevServer } from "shakapacker/types"
|
|
214
|
+
import { generateWebpackConfig } from "shakapacker"
|
|
213
215
|
|
|
214
216
|
const rspackConfig: RspackConfigWithDevServer = generateWebpackConfig({
|
|
215
|
-
mode:
|
|
217
|
+
mode: "development",
|
|
216
218
|
devServer: {
|
|
217
219
|
hot: true,
|
|
218
220
|
port: 3036
|
|
@@ -246,11 +248,13 @@ npm run type-check
|
|
|
246
248
|
## Available Types Reference
|
|
247
249
|
|
|
248
250
|
### Core Types
|
|
251
|
+
|
|
249
252
|
- `Config` - Shakapacker configuration from shakapacker.yml
|
|
250
253
|
- `Env` - Environment variables and helpers
|
|
251
254
|
- `DevServerConfig` - Development server configuration
|
|
252
255
|
|
|
253
256
|
### Webpack/Rspack Types
|
|
257
|
+
|
|
254
258
|
- `WebpackConfigWithDevServer` - Webpack configuration with dev server
|
|
255
259
|
- `RspackConfigWithDevServer` - Rspack configuration with dev server
|
|
256
260
|
- `WebpackPluginInstance` - Webpack plugin instance type
|
|
@@ -258,6 +262,7 @@ npm run type-check
|
|
|
258
262
|
- `RspackPlugin` - **⚠️ Deprecated:** Use `RspackPluginInstance` instead
|
|
259
263
|
|
|
260
264
|
### Helper Types
|
|
265
|
+
|
|
261
266
|
- `CompressionPluginOptions` - Compression plugin configuration
|
|
262
267
|
- `ReactRefreshWebpackPlugin` - React refresh for Webpack
|
|
263
268
|
- `ReactRefreshRspackPlugin` - React refresh for Rspack
|
|
@@ -287,7 +292,7 @@ plugins.push(new MyPlugin())
|
|
|
287
292
|
|
|
288
293
|
```typescript
|
|
289
294
|
// If types aren't available, declare them
|
|
290
|
-
declare module
|
|
295
|
+
declare module "my-custom-loader" {
|
|
291
296
|
const loader: any
|
|
292
297
|
export default loader
|
|
293
298
|
}
|
|
@@ -316,27 +321,31 @@ Here's a complete example of a typed webpack configuration:
|
|
|
316
321
|
|
|
317
322
|
```typescript
|
|
318
323
|
// config/webpack/webpack.config.ts
|
|
319
|
-
import {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
+
import {
|
|
325
|
+
generateWebpackConfig,
|
|
326
|
+
merge,
|
|
327
|
+
config as shakapackerConfig
|
|
328
|
+
} from "shakapacker"
|
|
329
|
+
import type { Configuration } from "webpack"
|
|
330
|
+
import type { WebpackConfigWithDevServer } from "shakapacker/types"
|
|
331
|
+
import CompressionPlugin from "compression-webpack-plugin"
|
|
332
|
+
import { resolve } from "path"
|
|
324
333
|
|
|
325
334
|
// Type-safe custom configuration
|
|
326
335
|
const customConfig: Configuration = {
|
|
327
336
|
resolve: {
|
|
328
|
-
extensions: [
|
|
337
|
+
extensions: [".css", ".ts", ".tsx"],
|
|
329
338
|
alias: {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
339
|
+
"@": resolve(__dirname, "../../app/javascript"),
|
|
340
|
+
components: resolve(__dirname, "../../app/javascript/components"),
|
|
341
|
+
utils: resolve(__dirname, "../../app/javascript/utils")
|
|
333
342
|
}
|
|
334
343
|
},
|
|
335
344
|
module: {
|
|
336
345
|
rules: [
|
|
337
346
|
{
|
|
338
347
|
test: /\.svg$/,
|
|
339
|
-
use: [
|
|
348
|
+
use: ["@svgr/webpack"],
|
|
340
349
|
issuer: /\.(tsx?|jsx?)$/
|
|
341
350
|
}
|
|
342
351
|
]
|
|
@@ -347,13 +356,13 @@ const customConfig: Configuration = {
|
|
|
347
356
|
const webpackConfig: Configuration = generateWebpackConfig(customConfig)
|
|
348
357
|
|
|
349
358
|
// Type-safe modifications based on environment
|
|
350
|
-
if (shakapackerConfig.env ===
|
|
359
|
+
if (shakapackerConfig.env === "production") {
|
|
351
360
|
const plugins = (webpackConfig.plugins || []) as WebpackPluginInstance[]
|
|
352
361
|
|
|
353
362
|
plugins.push(
|
|
354
363
|
new CompressionPlugin({
|
|
355
|
-
filename:
|
|
356
|
-
algorithm:
|
|
364
|
+
filename: "[path][base].br",
|
|
365
|
+
algorithm: "brotliCompress",
|
|
357
366
|
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf)$/
|
|
358
367
|
})
|
|
359
368
|
)
|
|
@@ -376,4 +385,4 @@ After migrating to TypeScript:
|
|
|
376
385
|
- [TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/intro.html)
|
|
377
386
|
- [Webpack TypeScript Configuration](https://webpack.js.org/configuration/configuration-languages/#typescript)
|
|
378
387
|
- [Shakapacker Types Documentation](./types/README.md)
|
|
379
|
-
- [Migration Examples](https://github.com/shakacode/shakapacker/tree/main/examples/typescript-config)
|
|
388
|
+
- [Migration Examples](https://github.com/shakacode/shakapacker/tree/main/examples/typescript-config)
|
data/docs/typescript.md
CHANGED
|
@@ -8,8 +8,8 @@ Shakapacker v9 includes TypeScript support, providing type safety and better IDE
|
|
|
8
8
|
|
|
9
9
|
```typescript
|
|
10
10
|
// webpack.config.ts
|
|
11
|
-
import { generateWebpackConfig } from
|
|
12
|
-
import type { Configuration } from
|
|
11
|
+
import { generateWebpackConfig } from "shakapacker"
|
|
12
|
+
import type { Configuration } from "webpack"
|
|
13
13
|
|
|
14
14
|
const config: Configuration = generateWebpackConfig({
|
|
15
15
|
// Your config with full type safety
|
|
@@ -22,7 +22,7 @@ export default config
|
|
|
22
22
|
|
|
23
23
|
```javascript
|
|
24
24
|
// webpack.config.js
|
|
25
|
-
const { generateWebpackConfig } = require(
|
|
25
|
+
const { generateWebpackConfig } = require("shakapacker")
|
|
26
26
|
|
|
27
27
|
/** @type {import('webpack').Configuration} */
|
|
28
28
|
const config = {
|
|
@@ -48,10 +48,12 @@ module.exports = generateWebpackConfig(config)
|
|
|
48
48
|
## IDE Setup
|
|
49
49
|
|
|
50
50
|
### VS Code
|
|
51
|
+
|
|
51
52
|
- Install TypeScript extension (built-in)
|
|
52
53
|
- Set `"typescript.tsdk": "node_modules/typescript/lib"` in settings
|
|
53
54
|
|
|
54
55
|
### WebStorm/IntelliJ
|
|
56
|
+
|
|
55
57
|
- Enable TypeScript service in Settings → Languages & Frameworks → TypeScript
|
|
56
58
|
|
|
57
59
|
## Common Patterns
|
|
@@ -59,7 +61,7 @@ module.exports = generateWebpackConfig(config)
|
|
|
59
61
|
### Environment-Specific Config
|
|
60
62
|
|
|
61
63
|
```typescript
|
|
62
|
-
import { generateWebpackConfig, env } from
|
|
64
|
+
import { generateWebpackConfig, env } from "shakapacker"
|
|
63
65
|
|
|
64
66
|
const config = generateWebpackConfig({
|
|
65
67
|
optimization: {
|
|
@@ -71,8 +73,8 @@ const config = generateWebpackConfig({
|
|
|
71
73
|
### Rspack Config
|
|
72
74
|
|
|
73
75
|
```typescript
|
|
74
|
-
import { generateRspackConfig } from
|
|
75
|
-
import type { RspackOptions } from
|
|
76
|
+
import { generateRspackConfig } from "shakapacker/rspack"
|
|
77
|
+
import type { RspackOptions } from "@rspack/core"
|
|
76
78
|
|
|
77
79
|
const config: RspackOptions = {
|
|
78
80
|
// Rspack-specific config
|
|
@@ -84,16 +86,18 @@ export default generateRspackConfig(config)
|
|
|
84
86
|
## Troubleshooting
|
|
85
87
|
|
|
86
88
|
**Cannot find module 'shakapacker'**
|
|
89
|
+
|
|
87
90
|
```typescript
|
|
88
91
|
/// <reference types="shakapacker" />
|
|
89
92
|
```
|
|
90
93
|
|
|
91
94
|
**Type errors with custom loaders**
|
|
95
|
+
|
|
92
96
|
```typescript
|
|
93
|
-
use: [require.resolve(
|
|
97
|
+
use: [require.resolve("custom-loader") as any]
|
|
94
98
|
```
|
|
95
99
|
|
|
96
100
|
## Further Reading
|
|
97
101
|
|
|
98
102
|
- [Webpack TypeScript Documentation](https://webpack.js.org/configuration/configuration-languages/#typescript)
|
|
99
|
-
- [TypeScript Handbook](https://www.typescriptlang.org/docs/)
|
|
103
|
+
- [TypeScript Handbook](https://www.typescriptlang.org/docs/)
|
|
@@ -11,6 +11,7 @@ If you face any issues, please report them at https://github.com/shakacode/shaka
|
|
|
11
11
|
While esbuild is a complete bundler, through the usage of [esbuild-loader](https://github.com/privatenumber/esbuild-loader), you can still leverage esbuild's speedy transpilation and minification in your Webpack-based configs.
|
|
12
12
|
|
|
13
13
|
Please note, that unlike Babel or SWC loader, esbuild-loader has got no support for things like:
|
|
14
|
+
|
|
14
15
|
- React Hot Module reload
|
|
15
16
|
- ES5 as a compilation target
|
|
16
17
|
- Automatic polyfills for missing browser features
|
|
@@ -28,7 +29,7 @@ npm install esbuild esbuild-loader
|
|
|
28
29
|
```
|
|
29
30
|
|
|
30
31
|
2. Add or change `javascript_transpiler` value in your default `shakapacker.yml` config to `esbuild`
|
|
31
|
-
The default configuration of babel is done by using `package.json` to use the file within the `shakapacker` package.
|
|
32
|
+
The default configuration of babel is done by using `package.json` to use the file within the `shakapacker` package.
|
|
32
33
|
|
|
33
34
|
```yml
|
|
34
35
|
default: &default
|
|
@@ -47,7 +48,7 @@ default: &default
|
|
|
47
48
|
cache_manifest: false
|
|
48
49
|
|
|
49
50
|
# Select JavaScript transpiler to use, available options are 'babel' (default), 'swc' or 'esbuild'
|
|
50
|
-
javascript_transpiler:
|
|
51
|
+
javascript_transpiler: "esbuild"
|
|
51
52
|
```
|
|
52
53
|
|
|
53
54
|
### (Optional) Replace minification with esbuild
|
|
@@ -59,14 +60,14 @@ o do so, you need to modify your webpack configuration and use `ESBuildMinifyPlu
|
|
|
59
60
|
Example:
|
|
60
61
|
|
|
61
62
|
```js
|
|
62
|
-
const { generateWebpackConfig } = require(
|
|
63
|
-
const { ESBuildMinifyPlugin } = require(
|
|
63
|
+
const { generateWebpackConfig } = require("shakapacker")
|
|
64
|
+
const { ESBuildMinifyPlugin } = require("esbuild-loader")
|
|
64
65
|
|
|
65
66
|
const options = {
|
|
66
67
|
optimization: {
|
|
67
68
|
minimizer: [
|
|
68
69
|
new ESBuildMinifyPlugin({
|
|
69
|
-
target:
|
|
70
|
+
target: "es2015"
|
|
70
71
|
})
|
|
71
72
|
]
|
|
72
73
|
}
|
|
@@ -101,11 +102,10 @@ See some examples below of potential `config/babel.config.js`.
|
|
|
101
102
|
|
|
102
103
|
### Example: Specifying esnext target environment
|
|
103
104
|
|
|
104
|
-
|
|
105
105
|
```js
|
|
106
106
|
const customConfig = {
|
|
107
107
|
options: {
|
|
108
|
-
target:
|
|
108
|
+
target: "esnext"
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
|
|
@@ -115,12 +115,12 @@ module.exports = customConfig
|
|
|
115
115
|
### Example: Using custom jsxFragment and jsxFactory
|
|
116
116
|
|
|
117
117
|
```js
|
|
118
|
-
const { env } = require(
|
|
118
|
+
const { env } = require("shakapacker")
|
|
119
119
|
|
|
120
120
|
const customConfig = {
|
|
121
121
|
options: {
|
|
122
|
-
jsxFragment:
|
|
123
|
-
jsxFactory:
|
|
122
|
+
jsxFragment: "Fragment",
|
|
123
|
+
jsxFactory: "h"
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
|
data/docs/v6_upgrade.md
CHANGED
|
@@ -13,41 +13,47 @@ Webpacker used to configure Webpack indirectly, which lead to a [complicated sec
|
|
|
13
13
|
While you have to configure integration with frameworks yourself, [`webpack-merge`](https://github.com/survivejs/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).
|
|
14
14
|
|
|
15
15
|
## webpacker v6.0.0.rc.6 to shakapacker v6.0.0
|
|
16
|
+
|
|
16
17
|
See an example migration here: [PR 27](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/pull/27).
|
|
17
18
|
|
|
18
19
|
### Update to v6.5.2
|
|
20
|
+
|
|
19
21
|
1. Remove setting the NODE_ENV in your `bin/webpacker` and `bin/webpacker-dev-server` bin stubs as these are not set in the webpack runner file.
|
|
20
22
|
|
|
21
23
|
### Update Steps to v6.0.0 from v6.0.0.rc.6
|
|
24
|
+
|
|
22
25
|
_If you're on webpacker v5, follow [how to upgrade to webpacker v6.0.0.rc.6 from v5](#how-to-upgrade-to-webpacker-v600rc6-from-v5) to get to v6.0.0.rc.6 first._
|
|
23
26
|
|
|
24
27
|
1. Change the gem name from `webpacker` to `shakapacker` and the NPM package from `@rails/webpacker` to `shakapacker`.
|
|
25
28
|
1. Install the 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`. You may have old versions of libraries. Run `yarn install` and check for warnings like `warning " > shakapacker@6.1.1" has incorrect peer dependency "compression-webpack-plugin@^9.0.0"` and `file-loader@1.1.11" has incorrect peer dependency "webpack@^2.0.0 || ^3.0.0 || ^4.0.0"`. In other words, warnings like these are **serious** and will cause considerable confusion if not respected.
|
|
26
29
|
1. Update any scripts that called `bin/webpack` or `bin/webpack-dev-server` to `bin/webpacker` or `bin/webpacker-dev-server`
|
|
27
30
|
1. Update your webpack config for a single config file, `config/webpack/webpack.config.js`. If you want to use the prior style of having a separate file for each NODE_ENV, you can use this shim for `config/webpack/webpack.config.js`. WARNING, previously, if you did not set `NODE_ENV`, `NODE_ENV` defaulted to `development`. Thus, you might expect `config/webpack/development.js` to run, but you'll instead be using the the configuration file that corresponds to your `RAILS_ENV`. If your `RAILS_ENV` is `test`, you'd be running `config/webpack/test.js`.
|
|
31
|
+
|
|
28
32
|
```js
|
|
29
33
|
// name this file config/webpack/webpack.config.js
|
|
30
|
-
const { env, webpackConfig } = require(
|
|
31
|
-
const { existsSync } = require(
|
|
32
|
-
const { resolve } = require(
|
|
34
|
+
const { env, webpackConfig } = require("shakapacker")
|
|
35
|
+
const { existsSync } = require("fs")
|
|
36
|
+
const { resolve } = require("path")
|
|
33
37
|
|
|
34
38
|
const envSpecificConfig = () => {
|
|
35
39
|
const path = resolve(__dirname, `${env.nodeEnv}.js`)
|
|
36
40
|
if (existsSync(path)) {
|
|
37
41
|
console.log(`Loading ENV specific webpack configuration file ${path}`)
|
|
38
42
|
return require(path)
|
|
39
|
-
} else {
|
|
43
|
+
} else {
|
|
40
44
|
// Probably an error if the file for the NODE_ENV does not exist
|
|
41
|
-
throw new Error(`Got Error with NODE_ENV = ${env.nodeEnv}`)
|
|
45
|
+
throw new Error(`Got Error with NODE_ENV = ${env.nodeEnv}`)
|
|
42
46
|
}
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
module.exports = envSpecificConfig()
|
|
46
50
|
```
|
|
51
|
+
|
|
47
52
|
1. Update `babel.config.js` if you need JSX support. See [Customizing Babel Config](./customizing_babel_config.md)
|
|
48
53
|
1. If you are using the view helper called `asset_pack_path`, change "media/" in path to "static/" or consider using the `image_pack_path`.
|
|
49
54
|
|
|
50
55
|
## How to upgrade to Webpacker v6.0.0.rc.6 from v5
|
|
56
|
+
|
|
51
57
|
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.
|
|
52
58
|
|
|
53
59
|
1. **Ensure no nested directories in your `source_entry_path`.** Check if you had any entry point files in child directories of your `source_entry_path`. Files for entry points in child directories are not supported by shakacode/shakapacker v6. Move those files to the top level, adjusting any imports in those files.
|
|
@@ -80,67 +86,73 @@ _If you're on webpacker v5, follow [how to upgrade to webpacker v6.0.0.rc.6 from
|
|
|
80
86
|
Overwrite all files and check what changed.
|
|
81
87
|
|
|
82
88
|
Note, the webpacker:install will install the peer dependencies:
|
|
89
|
+
|
|
83
90
|
```bash
|
|
84
91
|
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
|
|
85
92
|
```
|
|
86
93
|
|
|
87
94
|
1. Review the new default's changes to `webpacker.yml`. Consider each suggested change carefully, especially the change to have your `source_entry_path` be at the top level of your `source_path`.
|
|
88
95
|
The v5 default used `packs` for `source_entry_path`:
|
|
96
|
+
|
|
89
97
|
```yml
|
|
90
98
|
source_path: app/javascript
|
|
91
99
|
source_entry_path: packs
|
|
92
100
|
```
|
|
101
|
+
|
|
93
102
|
The v6 default uses the top level directory.
|
|
103
|
+
|
|
94
104
|
```yml
|
|
95
105
|
source_path: app/javascript
|
|
96
106
|
source_entry_path: /
|
|
97
107
|
```
|
|
108
|
+
|
|
98
109
|
If you prefer this configuration, then you will move your `app/javascript/packs/*` (including `application.js`) to `app/javascript/` and update the configuration file.
|
|
99
110
|
|
|
100
111
|
Note, moving your files is optional, as you can still keep your entries in a separate directory, called something like `packs`, or `entries`. This directory is defined with the `source_path`.
|
|
101
112
|
|
|
102
113
|
1. Update `webpack-dev-server` to the current version, greater than 4.2, updating `package.json`.
|
|
103
114
|
|
|
104
|
-
**Important:** If you encounter the error `[webpack-cli] Invalid options object. Dev Server has been initialized using an options object that does not match the API schema` with an unknown property `_assetEmittingPreviousFiles`, this indicates your webpack-dev-server configuration contains deprecated options.
|
|
105
|
-
|
|
115
|
+
**Important:** If you encounter the error `[webpack-cli] Invalid options object. Dev Server has been initialized using an options object that does not match the API schema` with an unknown property `_assetEmittingPreviousFiles`, this indicates your webpack-dev-server configuration contains deprecated options.
|
|
116
|
+
|
|
106
117
|
To resolve this issue:
|
|
107
118
|
- Ensure you're using webpack-cli >= 4.7.0 with webpack-dev-server 5.x (webpack-cli 4.7+ is compatible with webpack-dev-server v5)
|
|
108
119
|
- Check your current versions: `npm list webpack-cli webpack-dev-server`
|
|
109
120
|
- Remove any legacy options like `_assetEmittingPreviousFiles` from your dev-server configuration
|
|
110
121
|
- Review the [webpack-dev-server migration guide](https://github.com/webpack/webpack-dev-server/blob/master/migration-v5.md) for proper v4 to v5 migration steps
|
|
111
|
-
|
|
122
|
+
|
|
112
123
|
See [issue #526](https://github.com/shakacode/shakapacker/issues/526) for more details.
|
|
113
124
|
|
|
114
|
-
1. Update API usage of the view helpers by changing `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` to `javascript_pack_tag` and `stylesheet_pack_tag`. Ensure that your layouts and views will only have **at most one call** to `javascript_pack_tag` and **at most one call** to `stylesheet_pack_tag`. You can now pass multiple bundles to these view helper methods. If you fail to changes this, you may experience performance issues, and other bugs related to multiple copies of React, like [issue 2932](https://github.com/rails/webpacker/issues/2932).
|
|
125
|
+
1. Update API usage of the view helpers by changing `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` to `javascript_pack_tag` and `stylesheet_pack_tag`. Ensure that your layouts and views will only have **at most one call** to `javascript_pack_tag` and **at most one call** to `stylesheet_pack_tag`. You can now pass multiple bundles to these view helper methods. If you fail to changes this, you may experience performance issues, and other bugs related to multiple copies of React, like [issue 2932](https://github.com/rails/webpacker/issues/2932). If you expose jquery globally with `expose-loader` by using `import $ from "expose-loader?exposes=$,jQuery!jquery"` in your `app/javascript/application.js`, pass the option `defer: false` to your `javascript_pack_tag`.
|
|
115
126
|
|
|
116
127
|
1. If you are using any integrations like `css`, `postcss`, `React` or `TypeScript`. Please see https://github.com/shakacode/shakapacker#integrations section on how they work in v6.
|
|
117
128
|
|
|
118
129
|
1. `config/webpack/environment.js` was changed to `config/webpack/base.js` and exports a native webpack config so no need to call `toWebpackConfig`.
|
|
119
130
|
Use `merge` to make changes:
|
|
120
|
-
|
|
131
|
+
|
|
121
132
|
```js
|
|
122
133
|
// config/webpack/base.js
|
|
123
|
-
const { webpackConfig, merge } = require(
|
|
134
|
+
const { webpackConfig, merge } = require("@rails/webpacker")
|
|
124
135
|
const customConfig = {
|
|
125
136
|
module: {
|
|
126
137
|
rules: [
|
|
127
138
|
{
|
|
128
|
-
test: require.resolve(
|
|
129
|
-
loader:
|
|
139
|
+
test: require.resolve("jquery"),
|
|
140
|
+
loader: "expose-loader",
|
|
130
141
|
options: {
|
|
131
|
-
exposes: [
|
|
142
|
+
exposes: ["$", "jQuery"]
|
|
132
143
|
}
|
|
133
144
|
}
|
|
134
145
|
]
|
|
135
146
|
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
module.exports = merge(webpackConfig, customConfig)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
module.exports = merge(webpackConfig, customConfig)
|
|
139
150
|
```
|
|
140
|
-
|
|
151
|
+
|
|
141
152
|
1. Copy over custom browserlist config from `.browserslistrc` if it exists into the `"browserslist"` key in `package.json` and remove `.browserslistrc`.
|
|
142
153
|
|
|
143
154
|
1. Remove `babel.config.js` if you never changed it. Configure your `package.json` to use the default:
|
|
155
|
+
|
|
144
156
|
```json
|
|
145
157
|
"babel": {
|
|
146
158
|
"presets": [
|
|
@@ -148,6 +160,7 @@ _If you're on webpacker v5, follow [how to upgrade to webpacker v6.0.0.rc.6 from
|
|
|
148
160
|
]
|
|
149
161
|
}
|
|
150
162
|
```
|
|
163
|
+
|
|
151
164
|
See customization example the [Customizing Babel Config](./customizing_babel_config.md) for React configuration.
|
|
152
165
|
|
|
153
166
|
1. `extensions` was removed from the `webpacker.yml` file. Move custom extensions to your configuration by merging an object like this. For more details, see docs for [Webpack Configuration](https://github.com/shakacode/shakapacker/blob/main/README.md#webpack-configuration)
|
|
@@ -155,10 +168,11 @@ _If you're on webpacker v5, follow [how to upgrade to webpacker v6.0.0.rc.6 from
|
|
|
155
168
|
```js
|
|
156
169
|
{
|
|
157
170
|
resolve: {
|
|
158
|
-
extensions: [
|
|
171
|
+
extensions: [".ts", ".tsx", ".vue", ".css"]
|
|
159
172
|
}
|
|
160
173
|
}
|
|
161
174
|
```
|
|
175
|
+
|
|
162
176
|
1. In `webpacker.yml`, check if you had `watched_paths`. That is now `additional_paths`.
|
|
163
177
|
|
|
164
178
|
1. Some dependencies were removed in [PR 3056](https://github.com/rails/webpacker/pull/3056). If you see the error: `Error: Cannot find module 'babel-plugin-macros'`, or similar, then you need to `yarn add <dependency>` where <dependency> might include: `babel-plugin-macros`, `case-sensitive-paths-webpack-plugin`, `core-js`, `regenerator-runtime`. Or you might want to remove your dependency on those.
|
|
@@ -175,7 +189,6 @@ _If you're on webpacker v5, follow [how to upgrade to webpacker v6.0.0.rc.6 from
|
|
|
175
189
|
|
|
176
190
|
1. Now, follow the steps above to get to shakapacker v6 from webpacker v6.0.0.rc.6
|
|
177
191
|
|
|
178
|
-
|
|
179
192
|
## Examples of v5 to v6
|
|
180
193
|
|
|
181
194
|
1. [React on Rails Project with HMR and SSR](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/compare/webpacker-5.x...61e897f2c604085f45b9ab5e23642501e430fb28)
|
data/docs/v7_upgrade.md
CHANGED
|
@@ -14,7 +14,7 @@ Just so you know, Shakapacker v8 will remove any backward compatibility for spel
|
|
|
14
14
|
|
|
15
15
|
**Note:** At each step of changing the version, ensure that you update both gem and npm versions to the same "exact" version (like `x.y.z` and not `^x.y.z` or `>= x.y.z`).
|
|
16
16
|
|
|
17
|
-
1. Upgrade Shakapacker to the latest 6.x version and make sure there are no issues running your application.
|
|
17
|
+
1. Upgrade Shakapacker to the latest 6.x version and make sure there are no issues running your application.
|
|
18
18
|
2. Upgrade Shakapacker to version 7.
|
|
19
19
|
3. Run `rake shakapacker:binstubs` to get the new files in place. Then delete the `bin/webpacker` and `bin/webpacker-dev-server` ones.
|
|
20
20
|
4. Change spelling from Webpacker to Shakapacker in the code
|
|
@@ -23,8 +23,8 @@ Just so you know, Shakapacker v8 will remove any backward compatibility for spel
|
|
|
23
23
|
- Rename`Shakapacker.config.webpacker_precompile?` method, replace it with `Shakapacker.config.shakapacker_precompile?`
|
|
24
24
|
- `--debug-webpacker` is now `--debug-shakapacker` for your shakapacker binstubs.
|
|
25
25
|
5. Rename files
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
- Rename `config/webpacker.yml` to `config/shakapacker.yml`.
|
|
27
|
+
- Rename environment variables from `WEBPACKER_XYZ` to `SHAKAPACKER_XYZ`.
|
|
28
28
|
6. Where you have used webpackConfig, you must create a new instance with `generateWebpackConfig`. Alternatively, you can rename the import to globalMutableWebpackConfig, which retains the v6 behavior of a global, mutable object.
|
|
29
29
|
7. You may need to upgrade dependencies in package.json. You should use `yarn upgrade-interactive`.
|
|
30
30
|
|
|
@@ -35,25 +35,27 @@ When generating file paths for static assets, a top-level directory will no long
|
|
|
35
35
|
## The `webpackConfig` property is changed
|
|
36
36
|
|
|
37
37
|
The `webpackConfig` property in the `shakapacker` module has been changed. The shakapacker module has two options:
|
|
38
|
+
|
|
38
39
|
1. `generateWebpackConfig`: a function that returns a new webpack configuration object, which ensures that any modifications made to it will not affect any other usage of the webpack configuration.
|
|
39
40
|
2. `globalMutableWebpackConfig`: if a project still desires the old mutable object. You can rename your imports of `webpackConfig` with `globalMutableWebpackConfig`.
|
|
40
41
|
|
|
41
42
|
## Example Upgrade
|
|
43
|
+
|
|
42
44
|
If you started with:
|
|
43
45
|
|
|
44
46
|
```js
|
|
45
|
-
const { webpackConfig } = require(
|
|
47
|
+
const { webpackConfig } = require("shakapacker")
|
|
46
48
|
```
|
|
47
49
|
|
|
48
50
|
Switch to:
|
|
49
51
|
|
|
50
52
|
```js
|
|
51
|
-
const { generateWebpackConfig } = require(
|
|
53
|
+
const { generateWebpackConfig } = require("shakapacker")
|
|
52
54
|
const webpackConfig = generateWebpackConfig()
|
|
53
55
|
```
|
|
54
56
|
|
|
55
57
|
or use `globalMutableWebpackConfig` if the project desires to use a globally mutable object.
|
|
56
58
|
|
|
57
59
|
```js
|
|
58
|
-
const { globalMutableWebpackConfig: webpackConfig } = require(
|
|
60
|
+
const { globalMutableWebpackConfig: webpackConfig } = require("shakapacker")
|
|
59
61
|
```
|