A plugin for vitejs to use transform
of @babel/core
npm install vite-plugin-babel-core-transform
Read the details of babel's
TransformOptions
in https://babel.dev/docs/en/options
// vite.config.js
import { defineConfig } from 'vite';
import babelCoreTransformPlugin from 'vite-plugin-babel-core-transform';
export default defineConfig({
plugins: [
babelCoreTransformPlugin((id) => {
if (/\.(ts|tsx)$/.test(id)) {
return {
babelrc: false,
parserOpts: { plugins: ['jsx', 'typescript'] },
plugins: [
[
'babel-plugin-react-css-modules',
{
autoResolveMultipleImports: true,
generateScopedName,
exclude: "node_modules",
filetypes: {
'.scss': {
syntax: 'postcss-scss',
},
},
},
...
]
],
...
}
}
})
]
});