Lesson 5 / 30
Installing and Configuring SWC
Set up SWC as a Babel replacement with .swcrc configuration.
npm install @swc/core and @swc/cli
SWC installs similarly to Babel: core for the transpiler, cli for command-line usage.
npm install --save-dev @swc/core @swc/cli.swcrc: SWC configuration
.swcrc follows a similar structure to .babelrc but with different option names tailored to SWC.
{
"env": {
"targets": {
"chrome": "90"
}
},
"jsc": {
"parser": {
"syntax": "ecmascript"
}
}
}Running SWC from the CLI
Use npx swc to transpile files. SWC automatically picks up .swcrc in the project root.
npx swc src/index.js
npx swc src -d dist # much faster than Babel
Output:
var x = [1, 2, 3].map(function(n) {
return n * 2;
});