Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
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
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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.