LZS911 / vite-plugin-conditional-compile

4 stars 0 forks source link

`vite:react-swc` plugin conflict with `vite-plugin-conditional-compile` #8

Open f4-miyata opened 2 months ago

f4-miyata commented 2 months ago

Description:

When using vite-plugin-conditional-compile in a Vite project with the vite:react-swc plugin, an error occurs during the build process. The vite:react-swc plugin throws a syntax error.

Environment:

Steps to Reproduce:

  1. Install vite-plugin-conditional-compile and vite-plugin-react-swc. 2.Use conditional compilation in a React component
import React from 'react';
import { Route } from 'react-router-dom';
import { Page } from '@debug/pages/Page';

const AppRoutes = () => {
  return (
    <>
      {/* #if [DEV] */}
      <Route path="/Page" element={<Page />} />
      {/* #endif */}

      <Route path="/Error" element={<ErrorPage />} />
    </>
  );
};

export default AppRoutes;
  1. Run the Vite development server or build the project.

  2. The following syntax error occurs during the build process:

    
    Plugin: vite:react-swc
    File: /path/to/project/src/app/AppRoutes.tsx:12:1

SyntaxError: Unexpected token (15:0) 13 | 14 |

15 | } | ^ 16 | 17 | 18 | <Route path="/Error" element={} />

f4-miyata commented 2 months ago

@LZS911 I tried the following code, then it works as expected:

{
  // #if [DEV]
  <Route path="/Page" element={<Page />} />
  // #endif
}