underfin / vite-plugin-vue2

Vue2 plugin for Vite
621 stars 84 forks source link

vue2+vite2+jsx get some errors #114

Open NorthSeacoder opened 3 years ago

NorthSeacoder commented 3 years ago

vite.config.js

import { defineConfig } from "vite";
import path from 'path';
const { createVuePlugin } = require("vite-plugin-vue2");

const config = defineConfig({
  resolve: {
    alias: [{find: '@', replacement: path.resolve(__dirname, './src')}],
  },
  plugins: [createVuePlugin({ jsx: true })],
  build: {
    outDir: 'admin',
},
});

export default config;

.vue

<script lang="jsx">

errors

[vite] Internal server error: Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.
  Plugin: vite:import-analysis

  167|                                          vOn:click_stop={() => this.changeVisible({key, visible: !visible})}
  168|                                      />
  169|                                  </div>
     |                                        ^
  170|                              );
  171|                          }
      at formatError (/Users/yqg/personal/blog/projects/admin/node_modules/vite/dist/node/chunks/dep-e0f09032.js:45829:46)
      at TransformContext.error (/Users/yqg/personal/blog/projects/admin/node_modules/vite/dist/node/chunks/dep-e0f09032.js:45825:19)
      at TransformContext.transform (/Users/yqg/personal/blog/projects/admin/node_modules/vite/dist/node/chunks/dep-e0f09032.js:47292:22)
      at processTicksAndRejections (node:internal/process/task_queues:94:5)
      at async Object.transform (/Users/yqg/personal/blog/projects/admin/node_modules/vite/dist/node/chunks/dep-e0f09032.js:46027:30)
      at async transformRequest (/Users/yqg/personal/blog/projects/admin/node_modules/vite/dist/node/chunks/dep-e0f09032.js:61631:29)
      at async /Users/yqg/personal/blog/projects/admin/node_modules/vite/dist/node/chunks/dep-e0f09032.js:61739:32
chengkai2022 commented 3 years ago

vite.config.js配置

import { createVuePlugin } from "vite-plugin-vue2";
.....
plugins: [
      createVuePlugin({
        jsx: true,
      }),
      legacyPlugin({
        targets: [
          "Android > 39",
          "Chrome >= 60",
          "Safari >= 10.1",
          "iOS >= 10.3",
          "Firefox >= 54",
          "Edge >= 15"
        ]
      }),
      viteMockServe({
        mockPath: "mock",
        localEnabled: command === "serve"
      }),
      viteExternalsPlugin({
        jquery: "jQuery"
      }),
      svgLoader()
    ],

运行后的vite错误

> src/base/app.js:28:8: error: Unexpected "<"
    28 │         <div class="frame-app">
       ╵         ^

 > src/common/cet-scroller/index.js:73:6: error: Unexpected "<"
    73 │       <div
       ╵       ^

error when starting dev server:
Error: Build failed with 2 errors:
src/base/app.js:28:8: error: Unexpected "<"
src/common/cet-scroller/index.js:73:6: error: Unexpected "<"
    at failureErrorWithLog (C:\Users\dell\Desktop\test\CliV3.0\node_modules\esbuild\lib\main.js:1493:15)
    at C:\Users\dell\Desktop\test\CliV3.0\node_modules\esbuild\lib\main.js:1151:28
    at runOnEndCallbacks (C:\Users\dell\Desktop\test\CliV3.0\node_modules\esbuild\lib\main.js:941:63)
    at buildResponseToResult (C:\Users\dell\Desktop\test\CliV3.0\node_modules\esbuild\lib\main.js:1149:7)
    at C:\Users\dell\Desktop\test\CliV3.0\node_modules\esbuild\lib\main.js:1258:14
    at C:\Users\dell\Desktop\test\CliV3.0\node_modules\esbuild\lib\main.js:629:9
    at handleIncomingPacket (C:\Users\dell\Desktop\test\CliV3.0\node_modules\esbuild\lib\main.js:726:9)
    at Socket.readFromStdout (C:\Users\dell\Desktop\test\CliV3.0\node_modules\esbuild\lib\main.js:596:7)
    at Socket.emit (events.js:400:28)
    at addChunk (internal/streams/readable.js:290:12)
    at readableAddChunk (internal/streams/readable.js:265:9)
    at Socket.Readable.push (internal/streams/readable.js:204:10)
    at Pipe.onStreamRead (internal/stream_base_commons.js:188:23)

app.js内容

...
render() {
      return (
        <div class="frame-app">
          <FrameContainer />
          <FramePopup popup={this.popup} />
        </div>
      );
    },
...

配置jsx还是运行了会显示这个错误