swc-project / swc-loader

Moved to https://github.com/swc-project/pkgs
MIT License
394 stars 29 forks source link

Will swc-loader add appendTsSuffixTo option #63

Open BppleMan opened 2 years ago

BppleMan commented 2 years ago

Compiling ts with swc is blazingly fast, and its advantage over esbuild is that it supports decorate metadata, which is great.

I hope that swc-loader can support appendTsSuffixTo in the future, just like ts-loader appendTsSuffixTo, so that swc-loader can better support the compilation of .vue files

This is what I do now and it works fine so far. But I'm not sure if there are other problems with this。

// webpack.config.ts
// ...... other rules
{
    test: /\.ts$/i,
    exclude: ["/node_modules/"],
    use: [
        'swc-loader',
        resolve(__dirname, 'custom-loader')
    ],
},
// ...... other rules
// custom-loader.js
module.exports = function (content, sourceMap, meta) {
    if (sourceMap && this.resourcePath && this.resourcePath.endsWith(".vue")) {
        this.resourcePath += ".ts"
    }
    return content
}

This is what I do now and it works fine so far. But I'm not sure if there are other problems with this. If anyone can tell me how to add an option to swc-loader to do something similar, maybe I can submit a pull request