Skip to content

Commit

Permalink
replace babel-loader with swc-loader (metabase#45843)
Browse files Browse the repository at this point in the history
- babel is kept to transpile fonts file as swc emotion plugin doesn't handle our case correctly. I didn't find a root cause of wrong behaviour, but the safe past is to keep using babel + emotion plugin for one file and all others can be transpiled with swc
- react fast-refresh now handled by swc
- swc-loader can't read browserslist config from package.json, so we had to manually specify supported browsers in webpack
  • Loading branch information
uladzimirdev authored Jul 22, 2024
1 parent cfc6152 commit e02589a
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 89 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,6 @@ modules/drivers/*/.lsp/*

# airgap
/resources/airgap/

# swc
.swc/
2 changes: 1 addition & 1 deletion frontend/src/metabase-lib/v1/queries/structured/Filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export default class Filter extends MBQLClause {
return this.set(setFilterOptions(this, options));
}

formattedArguments(maxDisplayValues?: number = 1) {
formattedArguments(maxDisplayValues: number = 1) {
const dimension = this.dimension();
const operator = this.operator();
const args = this.arguments();
Expand Down
1 change: 0 additions & 1 deletion frontend/src/metabase/dev.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
import "@pmmmwh/react-refresh-webpack-plugin/client/ReactRefreshEntry.js";
import "cljs/metabase.util.devtools";
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@
"@storybook/manager-webpack5": "6.5.16",
"@storybook/react": "6.5.16",
"@svgr/webpack": "^8.0.1",
"@swc/core": "^1.3.99",
"@swc/core": "^1.7.0",
"@swc/plugin-emotion": "^3.0.10",
"@testing-library/cypress": "^10.0.2",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^15.0.2",
Expand Down Expand Up @@ -280,6 +281,7 @@
"stylelint": "^16.2.1",
"stylelint-config-css-modules": "^4.4.0",
"stylelint-config-standard": "^36.0.0",
"swc-loader": "^0.2.6",
"terser-webpack-plugin": "^5.3.9",
"webpack": "^5.85.0",
"webpack-bundle-analyzer": "^4.10.1",
Expand Down
55 changes: 39 additions & 16 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,37 @@ const shouldUseEslint =
// Babel:
const BABEL_CONFIG = {
cacheDirectory: process.env.BABEL_DISABLE_CACHE ? false : ".babel_cache",
plugins: ["@emotion"],
};

const BABEL_LOADER = { loader: "babel-loader", options: BABEL_CONFIG };

const SWC_LOADER = {
loader: "swc-loader",
options: {
jsc: {
loose: true,
transform: {
react: {
runtime: "automatic",
refresh: devMode,
},
},
parser: {
syntax: "typescript",
tsx: true,
},
experimental: {
plugins: [["@swc/plugin-emotion", { sourceMap: devMode }]],
},
},

sourceMaps: true,
minify: false, // produces same bundle size, but cuts 1s locally
env: {
targets: ["defaults"],
},
},
};

const CSS_CONFIG = {
Expand Down Expand Up @@ -102,9 +133,15 @@ const config = (module.exports = {
module: {
rules: [
{
test: /\.(tsx?|jsx?)$/,
// swc breaks styles for the whole app if we proceed this file
test: /css\/core\/fonts\.styled\.ts$/,
exclude: /node_modules|cljs/,
use: [{ loader: "babel-loader", options: BABEL_CONFIG }],
use: [BABEL_LOADER],
},
{
test: /\.(tsx?|jsx?)$/,
exclude: /node_modules|cljs|css\/core\/fonts\.styled\.ts/,
use: [SWC_LOADER],
},
...(shouldUseEslint
? [
Expand Down Expand Up @@ -308,20 +345,6 @@ if (WEBPACK_BUNDLE === "hot") {
config.output.publicPath =
"http://localhost:8080/" + config.output.publicPath;

config.module.rules.unshift({
test: /\.(tsx?|jsx?)$/,
exclude: /node_modules|cljs/,
use: [
{
loader: "babel-loader",
options: {
...BABEL_CONFIG,
plugins: ["@emotion", "react-refresh/babel"],
},
},
],
});

config.devServer = {
hot: true,
client: {
Expand Down
162 changes: 92 additions & 70 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5091,78 +5091,93 @@
"@svgr/plugin-jsx" "8.0.1"
"@svgr/plugin-svgo" "8.0.1"

"@swc/[email protected]":
version "1.3.99"
resolved "https://registry.yarnpkg.com/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.99.tgz#def204349ac645b8de21a800fa784907642a6c91"
integrity sha512-Qj7Jct68q3ZKeuJrjPx7k8SxzWN6PqLh+VFxzA+KwLDpQDPzOlKRZwkIMzuFjLhITO4RHgSnXoDk/Syz0ZeN+Q==

"@swc/[email protected]":
version "1.3.99"
resolved "https://registry.yarnpkg.com/@swc/core-darwin-x64/-/core-darwin-x64-1.3.99.tgz#2633f1ac1668ec569f34f86eb5250d56fcacd952"
integrity sha512-wR7m9QVJjgiBu1PSOHy7s66uJPa45Kf9bZExXUL+JAa9OQxt5y+XVzr+n+F045VXQOwdGWplgPnWjgbUUHEVyw==

"@swc/[email protected]":
version "1.3.99"
resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.99.tgz#871c2f049a3a5d88bcc7317ac004230517a08ba4"
integrity sha512-gcGv1l5t0DScEONmw5OhdVmEI/o49HCe9Ik38zzH0NtDkc+PDYaCcXU5rvfZP2qJFaAAr8cua8iJcOunOSLmnA==

"@swc/[email protected]":
version "1.3.99"
resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.99.tgz#28ed1622e92bc13aab4b650f2af695af8695289b"
integrity sha512-XL1/eUsTO8BiKsWq9i3iWh7H99iPO61+9HYiWVKhSavknfj4Plbn+XyajDpxsauln5o8t+BRGitymtnAWJM4UQ==

"@swc/[email protected]":
version "1.3.99"
resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.99.tgz#8e07add9cc8b76d542959e3240340effa6c6e446"
integrity sha512-fGrXYE6DbTfGNIGQmBefYxSk3rp/1lgbD0nVg4rl4mfFRQPi7CgGhrrqSuqZ/ezXInUIgoCyvYGWFSwjLXt/Qg==

"@swc/[email protected]":
version "1.3.99"
resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.99.tgz#677eb82d6862605cb0a81ec5b732bef2a9861b16"
integrity sha512-kvgZp/mqf3IJ806gUOL6gN6VU15+DfzM1Zv4Udn8GqgXiUAvbQehrtruid4Snn5pZTLj4PEpSCBbxgxK1jbssA==

"@swc/[email protected]":
version "1.3.99"
resolved "https://registry.yarnpkg.com/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.99.tgz#6c9bf96dd4cb81b5960884906766dc47a49efb0d"
integrity sha512-yt8RtZ4W/QgFF+JUemOUQAkVW58cCST7mbfKFZ1v16w3pl3NcWd9OrtppFIXpbjU1rrUX2zp2R7HZZzZ2Zk/aQ==

"@swc/[email protected]":
version "1.3.99"
resolved "https://registry.yarnpkg.com/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.99.tgz#6940a602b65137eee30f09ced7cd9fcb6e162b88"
integrity sha512-62p5fWnOJR/rlbmbUIpQEVRconICy5KDScWVuJg1v3GPLBrmacjphyHiJC1mp6dYvvoEWCk/77c/jcQwlXrDXw==

"@swc/[email protected]":
version "1.3.99"
resolved "https://registry.yarnpkg.com/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.99.tgz#7fcdfe6577f015604f7e69f71dda99822e946385"
integrity sha512-PdppWhkoS45VGdMBxvClVgF1hVjqamtvYd82Gab1i4IV45OSym2KinoDCKE1b6j3LwBLOn2J9fvChGSgGfDCHQ==

"@swc/core@^1.3.99":
version "1.3.99"
resolved "https://registry.yarnpkg.com/@swc/core/-/core-1.3.99.tgz#24a2ff0aaa1096b31046c8099b043936db0c4ca6"
integrity sha512-8O996RfuPC4ieb4zbYMfbyCU9k4gSOpyCNnr7qBQ+o7IEmh8JCV6B8wwu+fT/Om/6Lp34KJe1IpJ/24axKS6TQ==
dependencies:
"@swc/counter" "^0.1.1"
"@swc/types" "^0.1.5"
"@swc/[email protected]":
version "1.7.0"
resolved "https://registry.yarnpkg.com/@swc/core-darwin-arm64/-/core-darwin-arm64-1.7.0.tgz#fdc694dd6e8543f3efea0619a6fba9ce82939205"
integrity sha512-2ylhM7f0HwUwLrFYZAe/dse8PCbPsYcJS3Dt7Q8NT3PUn7vy6QOMxNcOPPuDrnmaXqQQO3oxdmRapguTxaat9g==

"@swc/[email protected]":
version "1.7.0"
resolved "https://registry.yarnpkg.com/@swc/core-darwin-x64/-/core-darwin-x64-1.7.0.tgz#a9a78ace5c7e43c8cb68d11c53d33a0bf966ca8e"
integrity sha512-SgVnN4gT1Rb9YfTkp4FCUITqSs7Yj0uB2SUciu5CV3HuGvS5YXCUzh+KrwpLFtx8NIgivISKcNnb41mJi98X8Q==

"@swc/[email protected]":
version "1.7.0"
resolved "https://registry.yarnpkg.com/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.7.0.tgz#6861ac82fda01b68b44970d3b9aaa955d7311d98"
integrity sha512-+Z9Dayart1iKJQEJJ9N/KS4z5EdXJE3WPFikY0jonKTo4Dd8RuyVz5yLvqcIMeVdz/SwximATaL6iJXw7hZS9A==

"@swc/[email protected]":
version "1.7.0"
resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.7.0.tgz#aa0e3dac17807c73d501f52526115666d60ea7a6"
integrity sha512-UnLrCiZ1EI4shznJn0xP6DLgsXUSwtfsdgHhGYCrvbgVBBve3S9iFgVFEB3SPl7Q/TdowNbrN4zHU0oChfiNfw==

"@swc/[email protected]":
version "1.7.0"
resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.7.0.tgz#4bb226a4e9eabac4e1a3b3ffd7ea5955629c84ed"
integrity sha512-H724UANA+ptsfwKRr9mnaDa9cb5fw0oFysiGKTgb3DMYcgk3Od0jMTnXVPFSVpo7FlmyxeC9K8ueUPBOoOK6XA==

"@swc/[email protected]":
version "1.7.0"
resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.7.0.tgz#ee65d1362214e91de89414f41b3310ba5302c2c5"
integrity sha512-SY3HA0K0Dpqt1HIfMLGpwL4hd4UaL2xHP5oZXPlRQPhUDZrbb4PbI3ZJnh66c63eL4ZR8EJ+HRFI0Alx5p69Zw==

"@swc/[email protected]":
version "1.7.0"
resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.7.0.tgz#0868518771004753acb07d9871cf5b143b51dc30"
integrity sha512-cEJ2ebtV1v/5Ilb55E05J6F5SrHKQWzUttIhR5Mkayyo+yvPslcpByuFC3D+J7X1ebziTOBpWuMpUdjLfh3SMQ==

"@swc/[email protected]":
version "1.7.0"
resolved "https://registry.yarnpkg.com/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.7.0.tgz#43048d67f871e798566c3883c991bed521ef3b9e"
integrity sha512-ecQOOmzEssz+m0pR4xDYCGuvn3E/l0nQ3tk5jp1NA1lsAy4bMV0YbYCHjptYvWL/UjhIerIp3IlCJ8x5DodSog==

"@swc/[email protected]":
version "1.7.0"
resolved "https://registry.yarnpkg.com/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.7.0.tgz#6e98f413e6469cfd00dcc7c106cb69f2c709e581"
integrity sha512-gz81seZkRn3zMnVOc7L5k6F4vQC82gIxmHiL+GedK+A37XI/X26AASU3zxvORnqQbwQYXQ+AEVckxBmFlz3v2g==

"@swc/[email protected]":
version "1.7.0"
resolved "https://registry.yarnpkg.com/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.7.0.tgz#79dfce878552f0a066a40c9cef524f4a8f872674"
integrity sha512-b5Fd1xEOw9uqBpj2lqsaR4Iq9UhiL84hNDcEsi6DQA7Y1l85waQAslTbS0E4/pJ1PISAs0jW0zIGLco1eaWBOg==

"@swc/core@^1.7.0":
version "1.7.0"
resolved "https://registry.yarnpkg.com/@swc/core/-/core-1.7.0.tgz#81f4e7dadf03e1d7f9a5e48a87f5d857e8fc1468"
integrity sha512-d4vMzH6ICllDwlPuhset2h8gu/USHdbyfJim+2hQEdxC0UONtfpmu38XBgNqRjStrji1Q5M10jfeUZL3cu1i8g==
dependencies:
"@swc/counter" "^0.1.3"
"@swc/types" "^0.1.9"
optionalDependencies:
"@swc/core-darwin-arm64" "1.3.99"
"@swc/core-darwin-x64" "1.3.99"
"@swc/core-linux-arm64-gnu" "1.3.99"
"@swc/core-linux-arm64-musl" "1.3.99"
"@swc/core-linux-x64-gnu" "1.3.99"
"@swc/core-linux-x64-musl" "1.3.99"
"@swc/core-win32-arm64-msvc" "1.3.99"
"@swc/core-win32-ia32-msvc" "1.3.99"
"@swc/core-win32-x64-msvc" "1.3.99"

"@swc/counter@^0.1.1":
version "0.1.2"
resolved "https://registry.yarnpkg.com/@swc/counter/-/counter-0.1.2.tgz#bf06d0770e47c6f1102270b744e17b934586985e"
integrity sha512-9F4ys4C74eSTEUNndnER3VJ15oru2NumfQxS8geE+f3eB5xvfxpWyqE5XlVnxb/R14uoXi6SLbBwwiDSkv+XEw==
"@swc/core-darwin-arm64" "1.7.0"
"@swc/core-darwin-x64" "1.7.0"
"@swc/core-linux-arm-gnueabihf" "1.7.0"
"@swc/core-linux-arm64-gnu" "1.7.0"
"@swc/core-linux-arm64-musl" "1.7.0"
"@swc/core-linux-x64-gnu" "1.7.0"
"@swc/core-linux-x64-musl" "1.7.0"
"@swc/core-win32-arm64-msvc" "1.7.0"
"@swc/core-win32-ia32-msvc" "1.7.0"
"@swc/core-win32-x64-msvc" "1.7.0"

"@swc/counter@^0.1.3":
version "0.1.3"
resolved "https://registry.yarnpkg.com/@swc/counter/-/counter-0.1.3.tgz#cc7463bd02949611c6329596fccd2b0ec782b0e9"
integrity sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==

"@swc/types@^0.1.5":
version "0.1.5"
resolved "https://registry.yarnpkg.com/@swc/types/-/types-0.1.5.tgz#043b731d4f56a79b4897a3de1af35e75d56bc63a"
integrity sha512-myfUej5naTBWnqOCc/MdVOLVjXUXtIA+NpDrDBKJtLLg2shUjBu3cZmB/85RyitKc55+lUUyl7oRfLOvkr2hsw==
"@swc/plugin-emotion@^3.0.10":
version "3.0.10"
resolved "https://registry.yarnpkg.com/@swc/plugin-emotion/-/plugin-emotion-3.0.10.tgz#f8e409448e2d5ce231533cefedec87c7752f1f79"
integrity sha512-IIYGws4w7tUPISuzLjSykaY6JGoADh3Z350PZMvOGLEC+Yuxa8c6LERT+ljFl5BBs8kE/fZeS2msNK/KduxI9w==
dependencies:
"@swc/counter" "^0.1.3"

"@swc/types@^0.1.9":
version "0.1.9"
resolved "https://registry.yarnpkg.com/@swc/types/-/types-0.1.9.tgz#e67cdcc2e4dd74a3cef4474b465eb398e7ae83e2"
integrity sha512-qKnCno++jzcJ4lM4NTfYifm1EFSCeIfKiAHAfkENZAV5Kl9PjJIyd2yeeVv6c/2CckuLyv2NmRC5pv6pm2WQBg==
dependencies:
"@swc/counter" "^0.1.3"

"@szmarczak/http-timer@^1.1.2":
version "1.1.2"
Expand Down Expand Up @@ -22914,6 +22929,13 @@ svgo@^3.0.2:
csso "^5.0.5"
picocolors "^1.0.0"

swc-loader@^0.2.6:
version "0.2.6"
resolved "https://registry.yarnpkg.com/swc-loader/-/swc-loader-0.2.6.tgz#bf0cba8eeff34bb19620ead81d1277fefaec6bc8"
integrity sha512-9Zi9UP2YmDpgmQVbyOPJClY0dwf58JDyDMQ7uRc4krmc72twNI2fvlBWHLqVekBpPc7h5NJkGVT1zNDxFrqhvg==
dependencies:
"@swc/counter" "^0.1.3"

symbol-observable@^1.0.3:
version "1.2.0"
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804"
Expand Down

0 comments on commit e02589a

Please sign in to comment.