swc-project / swc-loader

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

feat: add Inject JSX helper before JSX and TSX files are processed by swc #34

Closed umbrella22 closed 2 years ago

umbrella22 commented 2 years ago

Add an entry that can customize the JSX helper, it is used in the same way as thevite, before the swc works, inject a custom JSX helper into all JSX/TSX files, and with the pragma and pragmaFrag can customize any desired parsing method

For example in vue3

module: {
    rules: [
        {
            test: /\.(tsx|jsx)$/,
            exclude: /(node_modules|bower_components)/,
            use: {
                loader: "swc-loader",
                options: {
                    jsc: {
                        parser: {
                            syntax: "typescript"
                        },
                        transform: {
                            react: {
                                /** Use custom rendering functions, If you use the example of vue, it is */
                                pragma: 'h',
                                pragmaFrag: 'Fragment',
                                jsxInject:`import { h, Fragment } from 'vue'`
                            }
                        },
                    }
                }
            }
        }
    ];
}

In addition to vue, in some custom jsx rendering functions, this is more convenient and understandable; For example: tsx-dom

CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.

kdy1 commented 2 years ago

This is intentionally not supported. (CLI/lodaer should not touch such option)