Integrate SWC JavaScript compiler with Laravel Mix.
We know how far Rust can be in terms of performance, this projects brings all its power for JavaScript compiling (doing all the job that Babel does but much faster!).
Check its benchmarks here for more reference.
Installing this in your Laravel project is very simple, run this command:
yarn add -D laravel-mix-swc
# or
npm i --dev laravel-mix-swc
And in your webpack.mix.js
file in the root of your project add the following:
// At the very top of your file:
require("laravel-mix-swc");
// And replace mix.ts(), mix.js() or mix.babel() with .swc():
mix.swc("resources/js/app.js", "public/js")
To configure SWC you can send options as third parameter:
mix.swc("resources/js/app.js", "public/js", {
jsc: {
parser: {
syntax: "ecmascript",
jsx: false,
}
}
})
For more info check the official documentation of swc here.
Some "presets" or lets call them like that, remember this is the default config: https://github.com/open-southeners/laravel-mix-swc/blob/e45a3f1b92a1130a1acda2de7801f1348df547b7/src/plugin.js#L6
{
"test": ".*.ts$",
"jsc": {
"parser": {
"syntax": "typescript"
}
}
}
{
"jsc": {
"parser": {
"jsx": true
}
}
}
Very important that you've the decorators enabled, this also supports TypeScript but you can modify that.
{
"test": ".*.ts$",
"jsc": {
"parser": {
"syntax": "typescript",
"jsx": false,
"decorators": true,
"dynamicImport": true,
"exportDefaultFrom": true
}
}
}
This package is open-sourced software licensed under the MIT license.