Skip to content
This repository was archived by the owner on Jul 14, 2023. It is now read-only.

swc-project/swc-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Jun 9, 2022
4697faf · Jun 9, 2022

History

71 Commits
Jan 17, 2020
Apr 12, 2022
Apr 12, 2022
Apr 12, 2022
Apr 12, 2022
Jun 9, 2022
Jan 19, 2019
Apr 12, 2022
Apr 16, 2021
Jul 27, 2021
Jul 15, 2021
Jun 9, 2022
Apr 12, 2022

Repository files navigation

swc-loader

This package allows transpiling JavaScript files using swc and webpack.

Installation

npm i --save-dev @swc/core swc-loader webpack

Usage

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"
                        }
                    }
                }
            }
        }
    ];
}

Configuration Reference

Refer https://swc.rs/docs/configuring-swc