Giter Club home page Giter Club logo

vite-plugin-vue2-jsx's People

Contributors

amour1688 avatar anncwb avatar antfu avatar baboon-king avatar benmccann avatar bluwy avatar cawa-93 avatar ferdinando-ferreira avatar jokcy avatar jounqin avatar kaelwd avatar kakachake avatar patak-dev avatar renovate-bot avatar renovate[bot] avatar sapphi-red avatar shinigami92 avatar sodatea avatar swedish-li avatar sxzz avatar tocurd avatar troy351 avatar underfin avatar uptownhr avatar virgosoy avatar y1d7ng avatar ydcjeff avatar yyx990803 avatar zhenzhenchange avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

vite-plugin-vue2-jsx's Issues

Hope to support it in single file components (. vue)

因为插件强制匹配了去除?之后的**/.vue,导致无法在inlucde中设置正则仅匹配/**.vue,比如设置include: /.vue$/,依然会编译 /.vue?vue&type=style,导致报错

sorry, my english is pool,and hope you can understand.

h function context not same as webpack, which is right?

use render function to create customElement;

<template>
  <div :style="{ '--node-height': height + 'px' }" class="c-page">
    <VTree ref="vtree" class="constraint-tree" :render="renderNode" :nodeMinHeight="height" />
  </div>
</template>

    renderNode(node: any) {
      let compName = 'CNodeCommon'
      if (isArray) {
        compName = 'CNodeArray'
      }
      return <compName class="contraint-node" info={info} />
    },

webpack use vm.$createElement,context is this
image

vite use h function, context is the ui-lib's component
image

vite will show this error; Tried jsx in setup or methods both has same problem

 Unknown custom element: <CNodeCommon> - did you register the component correctly?

In my case, webpack is more reasonable, because I cannot controll ui lib's component
vue-tree lib: https://github.com/wsfe/vue-tree

"vite": "^5.0.11",
"@vitejs/plugin-vue2": "^2.3.1",
"@vitejs/plugin-vue2-jsx": "^1.1.1",
"vue": "^2.7.16",

vue2.7 tsx使用<> </>编译出错

import { defineComponent, toRefs, reactive } from "vue";

export default defineComponent({
    name: 'Home',
    props: {
        title: {
            type: [String, Number],
            default: '123'
        },
    },
    setup(props, context) {

        const state = reactive({
            count: 1
        })
        return {
            ...toRefs(state),
        }
    },
    render() {
        const {count} = this;
        console.log(count);
        return (
            <>
                {count}<button onClick={(e)=> this.count++}>点击</button>
            </>
        )
    }
})

image

How to enable 'decorators' support?

I'm facing this issue while building my project in vite. I'm using Vue 2.7. I have some components using the @Component syntax.

SyntaxError: unknown: Support for the experimental syntax 'decorators' isn't currently enabled

globally imported h() can only be invoked when there is an active component instance

@sodatea Hi there, sorry for bothering, I found an error recently when I migrated my project from vue2.7(webpack) to vue2.7(vite), due to the history reason, it breaks at runtime. for example:

<template>
  <button @click="testJsx">Click Me</button>
</template>

<script lang="jsx">
export default {
  methods: {
    testJsx() {
      console.log(<div>123</div>);
    },
  },
};
</script>

Click the button and the open the console, you'll find that JSX Element can not properly convert to VNode Element

image

May be this is a bug with @vitejs/plugin-vue2-jsx, because everything runs well with webpack workflow using the same version of @vue/[email protected] .

I made a minimal reproduction at stackblitz.com,looking forward to your reply, thanks!

When to support vite4

npm create vue@2 ,After creating the project, upgrade vite 4, and the project cannot run

How to use named slots with v-slot

Hi there, I'm struggling to use the unified slot syntax in Vue 2.7. Reference usage here

Child component:

  setup(props, { slots }) {
    return () => <div>{slots.header}</div>
  },

Parent component:

<Child>
{{
  header: () => {
    return <div>My header</div>
  },
}}
</Child>

or

<Child v-slots={{ header: () => 'My header' }}></Child>

Is this supported?

在.vue文件中编写jsx时出现编译错误

同样的jsx代码,在babel下正常编译运行,在vite中报错

Failed to parse source for import analysis because the content contains invalid JS syntax. Install @vitejs/plugin-vue to handle .vue files.

<script>
//App.vue
export default {
    render(){
        return <div>321</div>
   }
}
</script>

How to use v-model in vue2.7 jsx

// package.json
{
  "dependencies": {
    "vue": "~2.7.8",
  },
  "devDependencies": {
    "@babel/core": "^7.18.10",
    "@vitejs/plugin-legacy": "~2.0.0",
    "@vitejs/plugin-vue2": "^1.1.2",
    "@vitejs/plugin-vue2-jsx": "^1.0.2",
    "terser": "^5.14.2",
    "vite": "~3.0.3",
  },
  "engines": {
    "node": "^16.0.0",
    "pnpm": "^7.9.0"
  },

}
// vite.config.js
import { defineConfig } from 'vite';
import legacy from '@vitejs/plugin-legacy';
import vue2 from '@vitejs/plugin-vue2';
import vue2Jsx from '@vitejs/plugin-vue2-jsx';

export default defineConfig(({ command, mode }) => {
  return {
    plugins: [
      vue2(),
      vue2Jsx(),
      legacy({
        // When targeting IE11, you also need regenerator-runtime
        additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
      }),
    ],
  };
});
// demo.vue
<script lang="jsx">
import { defineComponent, ref } from 'vue';

let index = 0;
export default defineComponent({
  setup() {
    
    const date1 = ref(new Date());

    // Invalid prop: type check failed for prop "value". Expected Date, String, Array, got Object 
    const datePicker1 = <DatePicker  v-model={date1}></DatePicker>;

    const date2 = new Date()
    // Although there is no warning above, but this loses reactive
    const datePicker2 = <DatePicker  v-model={date2}></DatePicker>;

    const date3 = ref(new Date());
    // [plugin:vite:vue2-jsx] unknown: Cannot read properties of undefined (reading 'body')
    const datePicker3 = <DatePicker  v-model={date3.value}></DatePicker>;
    
    return () => datePicker;
  },
});
</script>

vue2.7.16中setup jsx语法中vModel无法绑定ref

example: https://stackblitz.com/edit/vitejs-vite-dnqewx?file=src%2FApp.vue

vue2.7.16中setup jsx语法中vModel无法绑定ref

error log:
[vite] Internal server error: unknown file: Property left of AssignmentExpression expected node to be of a type ["LVal","OptionalMemberExpression"] but instead got "CallExpression"
Plugin: vite:vue2-jsx
File: /home/projects/vitejs-vite-dnqewx/src/App.vue?vue&type=script&setup=true&lang.jsx
at Object.validate (file:///home/projects/vitejs-vite-dnqewx/node_modules/@babel/types/lib/definitions/utils.js:105:11)
at validateField (file:///home/projects/vitejs-vite-dnqewx/node_modules/@babel/types/lib/validators/validate.js:21:9)
at validate (file:///home/projects/vitejs-vite-dnqewx/node_modules/@babel/types/lib/validators/validate.js:15:3)
at validateNode (file:///home/projects/vitejs-vite-dnqewx/node_modules/@babel/types/lib/builders/validateNode.js:12:27)
at Object.assignmentExpression (file:///home/projects/vitejs-vite-dnqewx/node_modules/@babel/types/lib/builders/generated/index.js:269:36)
at genAssignmentCode (file:///home/projects/vitejs-vite-dnqewx/node_modules/@vue/babel-sugar-v-model/dist/plugin.js:1:2618)
at genDefaultModel (file:///home/projects/vitejs-vite-dnqewx/node_modules/@vue/babel-sugar-v-model/dist/plugin.js:1:8616)
at transformModel (file:///home/projects/vitejs-vite-dnqewx/node_modules/@vue/babel-sugar-v-model/dist/plugin.js:1:1626)
at JSXAttribute (file:///home/projects/vitejs-vite-dnqewx/node_modules/@vue/babel-sugar-v-model/dist/plugin.js:1:376)
at NodePath._call (file:///home/projects/vitejs-vite-dnqewx/node_modules/@babel/traverse/lib/path/context.js:46:20)

Why do errors occur when using JSX during installation using PNPM?

package.json

{
  "name": "business-ui",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "dayjs": "^1.8.29",
    "lodash": "^4.17.21",
    "qs": "^6.11.2",
    "vue": "^2.7.10",
    "vue-router": "^3.5.1",
    "vuex": "^3.4.0"
  },
  "devDependencies": {
    "@vitejs/plugin-vue2": "^2.3.1",
    "@vitejs/plugin-vue2-jsx": "^1.1.1",
    "sass": "^1.69.5",
    "sass-loader": "^13.3.2",
    "vite": "^5.0.10"
  }
}

vite.config.js

import { defineConfig } from 'vite'
import path from 'node:path'
import vue from '@vitejs/plugin-vue2'
import vueJsx from '@vitejs/plugin-vue2-jsx'
import devConfig from './build/dev.config'
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue(), vueJsx({
    jsx: true
    // options are passed on to @vue/babel-preset-jsx
  })],
  resolve: {
    alias: [
      {
        find: /\/@src\//,
        replacement: path.join(process.cwd(), "src/")
      },
      {
        find: /\/@packages\//,
        replacement: path.join(process.cwd(), "packages/")
      },
      {
        find: /\/@lib\//,
        replacement: path.join(process.cwd(), "lib/")
      },
      {
        find: /\/@examples\//,
        replacement: path.join(process.cwd(), "examples/")
      },
      {
        find: /\/@\//,
        replacement: path.join(process.cwd(), "examples/")
      },
    ]
  },
  ...devConfig
})

error

[vite] Internal server error: Failed to resolve import "@vue/babel-helper-vue-jsx-merge-props" from "packages/CustomConfigSearch/src/components/SearchConditionResult/components/ConfirmDialog.vue?vue&type=script&lang.jsx". Does the file exist?
  Plugin: vite:import-analysis
import _mergeJSXProps from "@vue/babel-helper-vue-jsx-merge-props";
     |                              ^
  2  |  import { h } from "vue";
  3  |  const p = () => new Promise(r => r(true));

It was installed using pnpm.But it works well when installed using npm.

  • node: v16.14.2
  • pnpm: v8.10.4
  • npm: v8.3.1

How to enable 'decorator' syntax?

I am upgrading vue from 2.5 to 2.7. Before this, I use vue-property-decorator in my project, and this error occured in the file which use vue-property-decorator and tsx.

Error detail:

[plugin:vite:vue2-jsx] unknown: Support for the experimental syntax 'decorators' isn't currently enabled (34:1):

Add @babel/plugin-proposal-decorators (https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-decorators) to the 'plugins' section of your Babel config to enable transformation.
If you want to leave it as-is, add @babel/plugin-syntax-decorators (https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-decorators) to the 'plugins' section to enable parsing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.