Open hogarthww-labs opened 3 years ago
@hogarthww-labs For the time being you can import swcrc config to your webpack config and do the extension test
in the webpack config itself. This will help you to migrate your code, without waiting for this fix to happen.
import swcJSConfig from "./.swcrc.mjs";
import swcTSConfig from "./.swcrc.ts.mjs";
...
rules: [
{
test: /\.m?jsx?$/,
exclude: /node_modules/,
use: [
{
loader: "swc-loader",
options: swcJSConfig,
}
]
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader: "swc-loader",
options: swcTSConfig,
}
]
},
]
...
Hope this helps, as it helped me resolve the issue on my end.
Since TypeScript is a superset of JavaScript (i.e. all JavaScript is valid TypeScript), you may also be able to just use your TypeScript config.
As per: https://swc.rs/docs/configuring-swc/#multiple-entries
We've been trying to use the following swc configuration options:
We've tried adding this to a
.swrc
file in the app folder for the app being build and in the root of our Nx monorepo (same folder as ourwebpack.config.js
). Not sure if it is picked up correctly. Then when we tried setting these options directly in the webpack rule with the loader:We get the following error:
Complaining that options must be an object or string. What should we do?
The Webpack rule for
swc-loader
when we print it:We need SWC to transpile ts and tsx files as typescript files and js and jsx files as ecmascript files. We are currently transitioning from Javascript to Typescript and have a mix.