Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demonstrate usage of SWC loader (Updated) #56

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ bin/dev-static
overmind start -f Procfile.dev-static
```


## Running with SWC

This project uses [SWC](https://swc.rs) instead of Babel.
For more information about this feature,
introduced in Shakapacker 6.1.1,
please check out
[Shakapacker - Using SWC Loader](https://github.com/shakacode/shakapacker/blob/master/docs/using_swc_loader.md)
documentation.

## Testing Functionality of SSR and HMR

1. Start app using either `bin/dev` or `bin/dev-static` (or run `Procfile.dev` or `Procfile.dev-static` with your favorit process manager like overmind or foreman).
Expand Down Expand Up @@ -79,7 +89,7 @@ overmind start -f Procfile.dev-static

1. Uncomment the debugger line at the end of file `config/webpack/webpack.config.js`
1. Set your preferred environment values and run
`NODE_ENV=production RAILS_ENV=production bin/webpacker --debug-webpacker`
`NODE_ENV=production RAILS_ENV=production bin/shakapacker --debug-shakapacker`

## Descriptive Commits

Expand All @@ -106,7 +116,6 @@ _Note, this repo started with rails/webpacker v5 and an older version of React o
2. Change config/initializers/react_on_rails.rb to have the correct server bundle name
3. Follow the flow from config/webpack/development.js to webpackConfig.js and consider
uncommenting the debug line to see what happens when you run bin/webpacker --debug

1. [Upgrade to rails/webpacker v6](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/commit/04b3c7f9996bca469b9f5bd5fb27d20c016bfa8c)

# Client only rendering versus Server-Side Rendering
Expand Down
2 changes: 2 additions & 0 deletions config/shakapacker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ default: &default
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false

webpack_loader: swc

development:
<<: *default
# This is false since we're running `bin/shakapacker -w` in Procfile.dev-setic
Expand Down
17 changes: 17 additions & 0 deletions config/swc.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { env } = require('shakapacker')

const customConfig = {
options: {
jsc: {
transform: {
react: {
useBuiltins: true,
development: env.isDevelopment,
refresh: env.isDevelopment && env.runningWebpackDevServer
}
}
}
}
}

module.exports = customConfig
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"@mdx-js/loader": "^2.3.0",
"@types/react": "^18.2.6",
"@types/react-dom": "^18.2.4",
"babel-loader": "^9.1.2",
"babel-plugin-macros": "^3.1.0",
"compression-webpack-plugin": "^10.0.0",
"css-loader": "^6.7.3",
Expand All @@ -35,8 +34,10 @@
},
"devDependencies": {
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
"@swc/core": "^1.2.133",
"fork-ts-checker-webpack-plugin": "^8.0.0",
"react-refresh": "^0.14.0",
"swc-loader": "^0.1.15",
"webpack-dev-server": "^4.15.0"
},
"packageManager": "[email protected]"
Expand Down
171 changes: 128 additions & 43 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1806,6 +1806,120 @@ __metadata:
languageName: node
linkType: hard

"@swc/core-darwin-arm64@npm:1.3.64":
version: 1.3.64
resolution: "@swc/core-darwin-arm64@npm:1.3.64"
conditions: os=darwin & cpu=arm64
languageName: node
linkType: hard

"@swc/core-darwin-x64@npm:1.3.64":
version: 1.3.64
resolution: "@swc/core-darwin-x64@npm:1.3.64"
conditions: os=darwin & cpu=x64
languageName: node
linkType: hard

"@swc/core-linux-arm-gnueabihf@npm:1.3.64":
version: 1.3.64
resolution: "@swc/core-linux-arm-gnueabihf@npm:1.3.64"
conditions: os=linux & cpu=arm
languageName: node
linkType: hard

"@swc/core-linux-arm64-gnu@npm:1.3.64":
version: 1.3.64
resolution: "@swc/core-linux-arm64-gnu@npm:1.3.64"
conditions: os=linux & cpu=arm64 & libc=glibc
languageName: node
linkType: hard

"@swc/core-linux-arm64-musl@npm:1.3.64":
version: 1.3.64
resolution: "@swc/core-linux-arm64-musl@npm:1.3.64"
conditions: os=linux & cpu=arm64 & libc=musl
languageName: node
linkType: hard

"@swc/core-linux-x64-gnu@npm:1.3.64":
version: 1.3.64
resolution: "@swc/core-linux-x64-gnu@npm:1.3.64"
conditions: os=linux & cpu=x64 & libc=glibc
languageName: node
linkType: hard

"@swc/core-linux-x64-musl@npm:1.3.64":
version: 1.3.64
resolution: "@swc/core-linux-x64-musl@npm:1.3.64"
conditions: os=linux & cpu=x64 & libc=musl
languageName: node
linkType: hard

"@swc/core-win32-arm64-msvc@npm:1.3.64":
version: 1.3.64
resolution: "@swc/core-win32-arm64-msvc@npm:1.3.64"
conditions: os=win32 & cpu=arm64
languageName: node
linkType: hard

"@swc/core-win32-ia32-msvc@npm:1.3.64":
version: 1.3.64
resolution: "@swc/core-win32-ia32-msvc@npm:1.3.64"
conditions: os=win32 & cpu=ia32
languageName: node
linkType: hard

"@swc/core-win32-x64-msvc@npm:1.3.64":
version: 1.3.64
resolution: "@swc/core-win32-x64-msvc@npm:1.3.64"
conditions: os=win32 & cpu=x64
languageName: node
linkType: hard

"@swc/core@npm:^1.2.133":
version: 1.3.64
resolution: "@swc/core@npm:1.3.64"
dependencies:
"@swc/core-darwin-arm64": 1.3.64
"@swc/core-darwin-x64": 1.3.64
"@swc/core-linux-arm-gnueabihf": 1.3.64
"@swc/core-linux-arm64-gnu": 1.3.64
"@swc/core-linux-arm64-musl": 1.3.64
"@swc/core-linux-x64-gnu": 1.3.64
"@swc/core-linux-x64-musl": 1.3.64
"@swc/core-win32-arm64-msvc": 1.3.64
"@swc/core-win32-ia32-msvc": 1.3.64
"@swc/core-win32-x64-msvc": 1.3.64
peerDependencies:
"@swc/helpers": ^0.5.0
dependenciesMeta:
"@swc/core-darwin-arm64":
optional: true
"@swc/core-darwin-x64":
optional: true
"@swc/core-linux-arm-gnueabihf":
optional: true
"@swc/core-linux-arm64-gnu":
optional: true
"@swc/core-linux-arm64-musl":
optional: true
"@swc/core-linux-x64-gnu":
optional: true
"@swc/core-linux-x64-musl":
optional: true
"@swc/core-win32-arm64-msvc":
optional: true
"@swc/core-win32-ia32-msvc":
optional: true
"@swc/core-win32-x64-msvc":
optional: true
peerDependenciesMeta:
"@swc/helpers":
optional: true
checksum: ea77168089a34dcec088ab81aef99301eba003b5ed3dca4039803050ba9344e754687f7d4fb4b3e40d22509658bdbdbac2f94f99c6f94051970566c857774371
languageName: node
linkType: hard

"@tootallnate/once@npm:2":
version: 2.0.0
resolution: "@tootallnate/once@npm:2.0.0"
Expand Down Expand Up @@ -2619,19 +2733,6 @@ __metadata:
languageName: node
linkType: hard

"babel-loader@npm:^9.1.2":
version: 9.1.2
resolution: "babel-loader@npm:9.1.2"
dependencies:
find-cache-dir: ^3.3.2
schema-utils: ^4.0.0
peerDependencies:
"@babel/core": ^7.12.0
webpack: ">=5"
checksum: f0edb8e157f9806b810ba3f2c8ca8fa489d377ae5c2b7b00c2ace900a6925641ce4ec520b9c12f70e37b94aa5366e7003e0f6271b26821643e109966ce741cb7
languageName: node
linkType: hard

"babel-plugin-macros@npm:^3.1.0":
version: 3.1.0
resolution: "babel-plugin-macros@npm:3.1.0"
Expand Down Expand Up @@ -3160,13 +3261,6 @@ __metadata:
languageName: node
linkType: hard

"commondir@npm:^1.0.1":
version: 1.0.1
resolution: "commondir@npm:1.0.1"
checksum: 59715f2fc456a73f68826285718503340b9f0dd89bfffc42749906c5cf3d4277ef11ef1cca0350d0e79204f00f1f6d83851ececc9095dc88512a697ac0b9bdcb
languageName: node
linkType: hard

"compressible@npm:~2.0.16":
version: 2.0.18
resolution: "compressible@npm:2.0.18"
Expand Down Expand Up @@ -4097,17 +4191,6 @@ __metadata:
languageName: node
linkType: hard

"find-cache-dir@npm:^3.3.2":
version: 3.3.2
resolution: "find-cache-dir@npm:3.3.2"
dependencies:
commondir: ^1.0.1
make-dir: ^3.0.2
pkg-dir: ^4.1.0
checksum: 1e61c2e64f5c0b1c535bd85939ae73b0e5773142713273818cc0b393ee3555fb0fd44e1a5b161b8b6c3e03e98c2fcc9c227d784850a13a90a8ab576869576817
languageName: node
linkType: hard

"find-up@npm:^3.0.0":
version: 3.0.0
resolution: "find-up@npm:3.0.0"
Expand Down Expand Up @@ -5239,15 +5322,6 @@ __metadata:
languageName: node
linkType: hard

"make-dir@npm:^3.0.2":
version: 3.1.0
resolution: "make-dir@npm:3.1.0"
dependencies:
semver: ^6.0.0
checksum: 484200020ab5a1fdf12f393fe5f385fc8e4378824c940fba1729dcd198ae4ff24867bc7a5646331e50cead8abff5d9270c456314386e629acec6dff4b8016b78
languageName: node
linkType: hard

"make-fetch-happen@npm:^10.0.3":
version: 10.1.7
resolution: "make-fetch-happen@npm:10.1.7"
Expand Down Expand Up @@ -6481,7 +6555,7 @@ __metadata:
languageName: node
linkType: hard

"pkg-dir@npm:^4.1.0, pkg-dir@npm:^4.2.0":
"pkg-dir@npm:^4.2.0":
version: 4.2.0
resolution: "pkg-dir@npm:4.2.0"
dependencies:
Expand Down Expand Up @@ -7372,9 +7446,9 @@ __metadata:
"@babel/runtime": ^7.21.5
"@mdx-js/loader": ^2.3.0
"@pmmmwh/react-refresh-webpack-plugin": ^0.5.10
"@swc/core": ^1.2.133
"@types/react": ^18.2.6
"@types/react-dom": ^18.2.4
babel-loader: ^9.1.2
babel-plugin-macros: ^3.1.0
compression-webpack-plugin: ^10.0.0
css-loader: ^6.7.3
Expand All @@ -7388,6 +7462,7 @@ __metadata:
react-refresh: ^0.14.0
shakapacker: 7.0.0
style-loader: ^3.3.2
swc-loader: ^0.1.15
terser-webpack-plugin: ^5.3.8
typescript: ^5.0.4
webpack: ^5.82.0
Expand Down Expand Up @@ -7506,7 +7581,7 @@ __metadata:
languageName: node
linkType: hard

"semver@npm:^6.0.0, semver@npm:^6.1.1, semver@npm:^6.1.2, semver@npm:^6.3.0":
"semver@npm:^6.1.1, semver@npm:^6.1.2, semver@npm:^6.3.0":
version: 6.3.0
resolution: "semver@npm:6.3.0"
bin:
Expand Down Expand Up @@ -8058,6 +8133,16 @@ __metadata:
languageName: node
linkType: hard

"swc-loader@npm:^0.1.15":
version: 0.1.16
resolution: "swc-loader@npm:0.1.16"
peerDependencies:
"@swc/core": ^1.2.147
webpack: ">=2"
checksum: 168ddd62105a74884f8bc1dbecc913d8c542a55baeb484c22590dfe5f89f081dbdd4012ad8d04fb3b0c230729babee25b82a71208e573874b4156a074ab7d3d2
languageName: node
linkType: hard

"tapable@npm:^2.0, tapable@npm:^2.1.1, tapable@npm:^2.2.0, tapable@npm:^2.2.1":
version: 2.2.1
resolution: "tapable@npm:2.2.1"
Expand Down
Loading