Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defineOptions中的name可以支持变量吗 #37

Closed
Miofly opened this issue Jul 13, 2022 · 11 comments
Closed

defineOptions中的name可以支持变量吗 #37

Miofly opened this issue Jul 13, 2022 · 11 comments
Labels

Comments

@Miofly
Copy link

Miofly commented Jul 13, 2022

比如

  const myName = 'popup'
  defineOptions({
    name: myName
  });
@sxzz
Copy link
Member

sxzz commented Jul 13, 2022

Not supported yet. But I created a PR to vue. vuejs/core#5752

@Miofly
Copy link
Author

Miofly commented Jul 14, 2022

Not supported yet. But I create a PR to vue. vuejs/core#5752

thanks

@sxzz sxzz closed this as completed in 16041de Aug 11, 2022
@sxzz
Copy link
Member

sxzz commented Aug 11, 2022

Now you can. Please use plugin unplugin-vue-macros and upgrade it to the latest version. hoistStatic feature is enabled by default.

@Miofly
Copy link
Author

Miofly commented Aug 26, 2022

  const _test = 'wfly';
  const name = `${_test}-app-provider`;

  defineOptions({
    name
  });

这种写法是不是不支持

@sxzz
Copy link
Member

sxzz commented Aug 26, 2022

Try

const _test = 'wfly'
const name = /*hoist-static*/ `${_test}-app-provider`

@Miofly
Copy link
Author

Miofly commented Aug 26, 2022

Try

const _test = 'wfly'
const name = /*hoist-static*/ `${_test}-app-provider`

可以了实现了我想要的功能,谢谢大佬
const [name, bem] = /* hoist-static*/ createNamespace('config-provider');

@Miofly
Copy link
Author

Miofly commented Aug 29, 2022

如图所示代码, rootMenuEmitter.on 中的 name 是参数,但是这样写会和 /* hoist-static*/ 中的 name 冲突导致崩溃,我现在将函数中的 name 参数重命名为(_name)去解决这个问题,但这个问题是否可以从插件层面去解决呢
image

@sxzz sxzz reopened this Aug 29, 2022
@sxzz sxzz removed the upstream label Aug 30, 2022
@sxzz
Copy link
Member

sxzz commented Aug 30, 2022

Can't reproduce, please provide a minimum reproduction repo.

@Miofly
Copy link
Author

Miofly commented Aug 30, 2022

Can't reproduce, please provide a minimum reproduction repo.

https://github.com/Miofly/vite-dev-tree-shaking
image

<script lang="ts" setup>
const [name] = /* hoist-static*/ ['VarCompName'];

defineOptions({
  name
});

const test = (name: string) => name
</script>

<template>
	<div>
    1
  </div>
</template>

@sxzz sxzz closed this as completed in c14ddaa Aug 30, 2022
@sxzz
Copy link
Member

sxzz commented Aug 30, 2022

try v0.11.1

@Miofly
Copy link
Author

Miofly commented Aug 30, 2022

try v0.11.1

it`s correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants