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

lib 包中依赖的 lodash-es 换成 lodash/xxx #2871

Closed
tolerance-go opened this issue Nov 12, 2022 · 10 comments
Closed

lib 包中依赖的 lodash-es 换成 lodash/xxx #2871

tolerance-go opened this issue Nov 12, 2022 · 10 comments
Labels
type: discussion 讨论 Usage questions, guidance, and other discussions

Comments

@tolerance-go
Copy link

tolerance-go commented Nov 12, 2022

问题描述

哈喽,我发现 lib 中依赖的 lodash-es 不是 cjs 规范,我需要额外配置转换,比如使用 jest 的时候,而不是 webpack 打包,希望改为 lodash 统一模块规范,同时我注意到 #101 这个 PR 为了解决全量引入问题,在使用 lodash 下,按需引入建议用 babel-plugin-import 统一处理,减少改动

重现链接

重现步骤

预期行为

平台

  • X6 版本: 1.34.2

屏幕截图或视频(可选)

No response

补充说明(可选)

No response

@x6-bot
Copy link
Contributor

x6-bot bot commented Nov 12, 2022

👋 @tolerance-go

Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it.

To help make it easier for us to investigate your issue, please follow the contributing guidelines.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

@damnright
Copy link
Contributor

es是为了tree-shaking吧

@alienzhangyw
Copy link

es是为了tree-shaking吧

import XXX from 'lodash/xxx'的方式自动就是了,只导入了用到的函数,其实就不存在tree-shaking的说法了。

@damnright
Copy link
Contributor

damnright commented Nov 17, 2022

es是为了tree-shaking吧

import XXX from 'lodash/xxx'的方式自动就是了,只导入了用到的函数,其实就不存在tree-shaking的说法了。

tree-shaking 依赖于 es module
https://webpack.js.org/guides/tree-shaking/
同时引入多个时 esm更方便:
import {chunk, join, sortBy} from 'lodash-es';
cjs就要每个都单独一行引用,太麻烦

@alienzhangyw
Copy link

es是为了tree-shaking吧

import XXX from 'lodash/xxx'的方式自动就是了,只导入了用到的函数,其实就不存在tree-shaking的说法了。

tree-shaking 依赖于 es module https://webpack.js.org/guides/tree-shaking/ 同时引入多个时 esm更方便: import {chunk, join, sortBy} from 'lodash-es'; cjs就要每个都单独一行引用,太麻烦

难道你们写代码的时候import语句都是手动写的吗🤣?我都是用到的时候tab一下vscode自动导入了

@lijing666
Copy link
Contributor

es是为了tree-shaking吧

import XXX from 'lodash/xxx'的方式自动就是了,只导入了用到的函数,其实就不存在tree-shaking的说法了。

tree-shaking 依赖于 es module https://webpack.js.org/guides/tree-shaking/ 同时引入多个时 esm更方便: import {chunk, join, sortBy} from 'lodash-es'; cjs就要每个都单独一行引用,太麻烦

难道你们写代码的时候import语句都是手动写的吗🤣?我都是用到的时候tab一下vscode自动导入了

其实他用lodash-es有个好处就是我框架自带了lodash完整版,这样我可以配置alias,lodash-es为lodash即可,但是如果用lodash/xx的方式就会没那么好处理

@NewByVector NewByVector added the type: discussion 讨论 Usage questions, guidance, and other discussions label Jan 28, 2023
@NewByVector
Copy link
Contributor

NewByVector commented Feb 1, 2023

确实,lodash-es 配合 webpack 才能发挥优势,其他场景下好像没有多大必要。这里有相关 benchmark

@Oscar-ren
Copy link

目前lib目录里是require('lodash-es'),导致无法按需加载,nextjs最新版本会报错;可以的话换成 lodash/xxx 的形式比较好

@NewByVector
Copy link
Contributor

@Oscar-ren 欢迎提 PR。

@x6-bot
Copy link
Contributor

x6-bot bot commented Sep 7, 2024

This thread has been automatically locked because it has not had recent activity.

Please open a new issue for related bugs and link to relevant comments in this thread.

@x6-bot x6-bot bot locked as resolved and limited conversation to collaborators Sep 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: discussion 讨论 Usage questions, guidance, and other discussions
Projects
None yet
Development

No branches or pull requests

6 participants