Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
swc-loader
Advanced tools
The swc-loader package is a webpack loader for the SWC compiler, which allows for super-fast transpilation of JavaScript and TypeScript code. It leverages the speed of SWC to offer quick build times for development and production environments. This loader integrates seamlessly with webpack, enabling developers to use SWC's powerful features directly within their webpack configuration.
Transpilation of JavaScript/TypeScript
This code sample demonstrates how to configure swc-loader in a webpack configuration file to transpile JavaScript files. It specifies the use of the SWC compiler with certain options, such as parsing JSX syntax and targeting ES2015 for the output.
module.exports = {
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'swc-loader',
options: {
jsc: {
parser: {
syntax: 'ecmascript',
jsx: true
},
target: 'es2015'
}
}
}
}
]
}
};
Source Maps
This configuration enables source map generation for debugging purposes. When set to true, the 'sourceMaps' option tells swc-loader to produce source maps alongside the transpiled code, making it easier to debug in development environments.
module.exports = {
module: {
rules: [
{
test: /\.m?js$/,
use: {
loader: 'swc-loader',
options: {
sourceMaps: true
}
}
}
]
}
};
babel-loader is a webpack plugin that uses Babel to transpile JavaScript. It is similar to swc-loader in functionality but tends to be slower because Babel performs transformations in JavaScript, whereas SWC is written in Rust, offering faster build times.
ts-loader is a TypeScript loader for webpack. It is designed specifically for TypeScript, similar to how swc-loader can handle TypeScript files. However, swc-loader might offer faster compilation times due to its efficient Rust-based compilation engine.
esbuild-loader integrates esbuild into webpack, offering extremely fast bundling and transpilation. Like swc-loader, it focuses on speed and efficiency, leveraging the performance of Go (in the case of esbuild) versus Rust (for SWC), making them both strong alternatives to traditional JavaScript-based tools.
This package allows transpiling JavaScript files using swc and webpack.
npm i --save-dev @swc/core swc-loader webpack
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
// Use `.swcrc` to configure swc
loader: "swc-loader"
}
}
];
}
You can pass options to the loader by using the option property.
module: {
rules: [
{
test: /\.ts$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: "swc-loader",
options: {
jsc: {
parser: {
syntax: "typescript"
}
}
}
}
}
];
}
If you get an error while using swc-loader
, you can pass sync: true
to get correct error message.
module: {
rules: [
{
test: /\.ts$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: "swc-loader",
options: {
// This makes swc-loader invoke swc synchronously.
sync: true,
jsc: {
parser: {
syntax: "typescript"
}
}
}
}
}
];
}
FAQs
Webpack plugin for swc
The npm package swc-loader receives a total of 1,681,059 weekly downloads. As such, swc-loader popularity was classified as popular.
We found that swc-loader demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.