将相同的导入到一个柏树文件上

发布于 2025-02-06 21:04:16 字数 419 浏览 1 评论 0原文

我们使用的是柏树v10和我们的 .cy.js 文件始终使用以下相同的导入:

import Customers from "../imports/Customer"
import Search from "../imports/Search"
import PostComment from "../imports/PostComment"
import Feedback from "../imports/Feedback"
import Login from "../imports/Login"

有更好的方法可以将所有这些导入包含在一到两行中,并且不会手动称其为?我尝试创建一个complete.js包含复制粘贴代码的文件,然后尝试导入完整的js,但似乎不起作用。我不确定我是否缺少任何东西。

We are using Cypress v10 and our .cy.js files always use these same imports:

import Customers from "../imports/Customer"
import Search from "../imports/Search"
import PostComment from "../imports/PostComment"
import Feedback from "../imports/Feedback"
import Login from "../imports/Login"

Is there a better way that I can include all these imports in a single or two lines and not call them manually like this? I tried creating a complete.js file that contains copy pasted code as above then try to import that complete.js but it does not seem to work. I'm not sure if I'm missing anything.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

℉服软 2025-02-13 21:04:16

您可以使用索引文件重新出口并简化导入。

// imports/index.js
export { Customers } from 'Customer'
export { Search } from 'Search'
export { PostComment } from 'PostComment'
export { Feedback } from 'Feedback'
export { Login } from 'Login'

// test.cy.js
import { Customers, Search, PostComment, Feedback, Login } from '../imports'

You can use an index file to re-export and simplify the import.

// imports/index.js
export { Customers } from 'Customer'
export { Search } from 'Search'
export { PostComment } from 'PostComment'
export { Feedback } from 'Feedback'
export { Login } from 'Login'

// test.cy.js
import { Customers, Search, PostComment, Feedback, Login } from '../imports'
不一样的天空 2025-02-13 21:04:16

将单个文件中的默认转换为命名在枪管索引中的导出

export { * as Customers } from 'Customer'
export { * as Search } from 'Search'
export { * as PostComment } from 'PostComment'
export { * as Feedback } from 'Feedback'
export { * as Login } from 'Login'

To convert default exports in the individual files to named exports in the barrel index

export { * as Customers } from 'Customer'
export { * as Search } from 'Search'
export { * as PostComment } from 'PostComment'
export { * as Feedback } from 'Feedback'
export { * as Login } from 'Login'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文