Skip to content

Commit 713d127

Browse files
authored
fix: nextjs lodash esm (#2666)
1 parent 83aee0d commit 713d127

File tree

18 files changed

+116
-25
lines changed

18 files changed

+116
-25
lines changed

config/jest.js

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const BaseJestConfig = {
88
'\\.(less|css)$': 'jest-less-loader',
99
},
1010
moduleNameMapper: {
11-
'^lodash-es$': 'lodash',
1211
'^.+\\.(css|less)$': 'identity-obj-proxy',
1312
},
1413
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],

config/webpack.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const getWebpackConfig = (name, library) => {
4040
commonjs: 'react-dom',
4141
amd: 'react-dom',
4242
},
43-
'lodash-es': {
43+
lodash: {
4444
root: '_',
4545
commonjs2: 'lodash',
4646
commonjs: 'lodash',

packages/charts/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 2.2.1
2+
3+
`2024-08-26`
4+
5+
- 🐞 [🧐[问题]ESM packages (lodash-es) need to be imported. ](https://github.com/ant-design/ant-design-charts/issues/2489)
6+
17
## 2.1.2
28

39
`2024-07-24`

packages/charts/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": false,
33
"name": "@ant-design/charts",
4-
"version": "2.1.2",
4+
"version": "2.2.1",
55
"description": "AntV upper level visual component library",
66
"bugs": {
77
"url": "https://github.com/ant-design/ant-design-charts/issues"
@@ -30,10 +30,10 @@
3030
"lib:es": "tsc -p tsconfig.json --target ES5 --module ESNext --outDir es"
3131
},
3232
"dependencies": {
33-
"@ant-design/plots": "^2.1.3"
33+
"@ant-design/plots": "^2.1.3",
34+
"lodash": "^4.17.21"
3435
},
3536
"peerDependencies": {
36-
"lodash-es": "^4.17.21",
3737
"react": ">=16.8.4",
3838
"react-dom": ">=16.8.4"
3939
},

packages/plots/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 2.3.1
2+
3+
`2024-08-26`
4+
5+
- 🐞 [🧐[问题]ESM packages (lodash-es) need to be imported. ](https://github.com/ant-design/ant-design-charts/issues/2489)
6+
17
## 2.2.8
28
## 2.2.7
39
`2024-08-05`

packages/plots/jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = {
44
...(process.env.DEBUG_MODE === '1' ? OnlineConfig : {}),
55
moduleNameMapper: {
66
'^d3-((?!linear)\\S*)': `<rootDir>/../../node_modules/d3-$1/dist/d3-$1.min.js`,
7-
'^lodash-es$': 'lodash',
7+
'^lodash$': 'lodash',
88
'^@ant-design/charts-util': `<rootDir>/../../packages/util/src`,
99
},
1010
};

packages/plots/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ant-design/plots",
3-
"version": "2.2.8",
3+
"version": "2.3.1",
44
"description": "G2Plot Statistical chart",
55
"bugs": {
66
"url": "https://github.com/ant-design/ant-design-charts/issues"
@@ -40,10 +40,10 @@
4040
"@antv/event-emitter": "^0.1.3",
4141
"@antv/g": "^6.0.0",
4242
"@antv/g2": "^5.1.18",
43-
"@antv/g2-extension-plot": "^0.2.0"
43+
"@antv/g2-extension-plot": "^0.2.0",
44+
"lodash": "^4.17.21"
4445
},
4546
"peerDependencies": {
46-
"lodash-es": "^4.17.21",
4747
"react": ">=16.8.4",
4848
"react-dom": ">=16.8.4"
4949
},

packages/plots/src/core/utils/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export {
2828
memoize,
2929
values,
3030
isUndefined,
31-
} from 'lodash-es';
31+
} from 'lodash';
3232
export { isCompositePlot } from './is-composite-plot';
3333
export { transformOptions } from './transform';
3434
export { deleteExcessKeys } from './delete-excess-keys';

packages/plots/src/util/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export { isEqual, get, isString, isNumber, isFunction, isElement, cloneDeep, isArray, isObject } from 'lodash-es';
1+
export { isEqual, get, isString, isNumber, isFunction, isElement, cloneDeep, isArray, isObject } from 'lodash';
22
export { createNode, uuid } from '@ant-design/charts-util';
33
export { isValidElement } from './is-valid-element';

scripts/ast3.0/core/constants.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { uniqBy, concat, filter, get } = require('lodash-es');
1+
const { uniqBy, concat, filter, get } = require('lodash');
22

33
/**
44
* 函数标识

scripts/ast3.0/core/parser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const fs = require('fs');
22
const babel = require('@babel/core');
33
const chalk = require('chalk');
4-
const { get, pick } = require('lodash-es');
4+
const { get, pick } = require('lodash');
55
const { PIPELINE } = require('./constants');
66
const { SETGLOBAL, RESETGLOBAL, INGLOBALRANGE } = require('./global');
77
const {

scripts/ast3.0/core/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { get } = require('lodash-es');
1+
const { get } = require('lodash');
22
const { SHAPES, SIGN } = require('./constants');
33
const { SETGLOBAL } = require('./global');
44

site/.dumi/global.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ if (window) {
44
(window as any).react = require('react');
55
(window as any).reactDom = require('react-dom');
66
(window as any).fecha = require('fecha');
7-
(window as any).lodashEs = require('lodash-es');
7+
(window as any).lodashEs = require('lodash');
88
/** 不要使用 link, react-dom 冲突 */
99
(window as any).plots = require('@ant-design/plots');
1010
(window as any).d3Interpolate = require('d3-interpolate');

site/docs/manual/getting-started.zh.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { Line } from '@ant-design/charts';
2020

2121
```ts
2222
"peerDependencies": {
23-
"lodash-es": "^4.17.20",
2423
"react": ">=16.8.4",
2524
"react-dom": ">=16.8.4"
2625
}
@@ -42,19 +41,17 @@ npm install @ant-design/plots --save
4241
<script type="text/javascript" src="https://unpkg.com/@ant-design/plots@latest/dist/plots.min.js"></script>
4342
```
4443

45-
由于 @ant-design/charts 里面 externals 了 `react``react-dom``lodash-es`,使用时需要通过 CDN 的方式在 `charts.min.js` 之前引入对应包的 CDN 地址。
44+
由于 @ant-design/charts 里面 externals 了 `react``react-dom`,使用时需要通过 CDN 的方式在 `charts.min.js` 之前引入对应包的 CDN 地址。
4645

4746
```ts
4847
// webpack.config.js
4948
externals: {
5049
react: 'React',
5150
'react-dom': 'ReactDOM',
52-
'lodash-es': 'lodash'
5351
}
5452
// public/index.html
5553
<script crossorigin src="https://unpkg.com/react@latest/umd/react.production.min.js"></script>
5654
<script crossorigin src="https://unpkg.com/react-dom@latest/umd/react-dom.production.min.js"></script>
57-
<script crossorigin src="https://unpkg.com/[email protected]/lodash.min.js"></script>
5855

5956
// 按需引入
6057
<script type="text/javascript" src="https://unpkg.com/@ant-design/plots@latest/dist/plots.min.js"></script>

site/examples/statistics/column/demo/annotation-label.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Column } from '@ant-design/plots';
22
import React, { useEffect, useState } from 'react';
33
import ReactDOM from 'react-dom';
4-
import { forEach, groupBy } from 'lodash-es';
4+
import { forEach, groupBy } from 'lodash';
55

66
const DemoColumn = () => {
77
const [data, setData] = useState([]);

site/examples/statistics/sankey/demo/basic.js

+85-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,78 @@ import ReactDOM from 'react-dom';
55
const DemoSankey = () => {
66
const config = {
77
data: {
8-
type: 'fetch',
9-
value: 'https://assets.antv.antgroup.com/g2/energy.json',
8+
value: {
9+
links: [
10+
{ source: "Agricultural 'waste'", target: 'Bio-conversion', value: 124.729 },
11+
{ source: 'Bio-conversion', target: 'Liquid', value: 0.597 },
12+
{ source: 'Bio-conversion', target: 'Losses', value: 26.862 },
13+
{ source: 'Bio-conversion', target: 'Solid', value: 280.322 },
14+
{ source: 'Bio-conversion', target: 'Gas', value: 81.144 },
15+
{ source: 'Biofuel imports', target: 'Liquid', value: 35 },
16+
{ source: 'Biomass imports', target: 'Solid', value: 35 },
17+
{ source: 'Coal imports', target: 'Coal', value: 11.606 },
18+
{ source: 'Coal reserves', target: 'Coal', value: 63.965 },
19+
{ source: 'Coal', target: 'Solid', value: 75.571 },
20+
{ source: 'District heating', target: 'Industry', value: 10.639 },
21+
{ source: 'District heating', target: 'Heating and cooling - commercial', value: 22.505 },
22+
{ source: 'District heating', target: 'Heating and cooling - homes', value: 46.184 },
23+
{ source: 'Electricity grid', target: 'Over generation / exports', value: 104.453 },
24+
{ source: 'Electricity grid', target: 'Heating and cooling - homes', value: 113.726 },
25+
{ source: 'Electricity grid', target: 'H2 conversion', value: 27.14 },
26+
{ source: 'Electricity grid', target: 'Industry', value: 342.165 },
27+
{ source: 'Electricity grid', target: 'Road transport', value: 37.797 },
28+
{ source: 'Electricity grid', target: 'Agriculture', value: 4.412 },
29+
{ source: 'Electricity grid', target: 'Heating and cooling - commercial', value: 40.858 },
30+
{ source: 'Electricity grid', target: 'Losses', value: 56.691 },
31+
{ source: 'Electricity grid', target: 'Rail transport', value: 7.863 },
32+
{ source: 'Electricity grid', target: 'Lighting & appliances - commercial', value: 90.008 },
33+
{ source: 'Electricity grid', target: 'Lighting & appliances - homes', value: 93.494 },
34+
{ source: 'Gas imports', target: 'Ngas', value: 40.719 },
35+
{ source: 'Gas reserves', target: 'Ngas', value: 82.233 },
36+
{ source: 'Gas', target: 'Heating and cooling - commercial', value: 0.129 },
37+
{ source: 'Gas', target: 'Losses', value: 1.401 },
38+
{ source: 'Gas', target: 'Thermal generation', value: 151.891 },
39+
{ source: 'Gas', target: 'Agriculture', value: 2.096 },
40+
{ source: 'Gas', target: 'Industry', value: 48.58 },
41+
{ source: 'Geothermal', target: 'Electricity grid', value: 7.013 },
42+
{ source: 'H2 conversion', target: 'H2', value: 20.897 },
43+
{ source: 'H2 conversion', target: 'Losses', value: 6.242 },
44+
{ source: 'H2', target: 'Road transport', value: 20.897 },
45+
{ source: 'Hydro', target: 'Electricity grid', value: 6.995 },
46+
{ source: 'Liquid', target: 'Industry', value: 121.066 },
47+
{ source: 'Liquid', target: 'International shipping', value: 128.69 },
48+
{ source: 'Liquid', target: 'Road transport', value: 135.835 },
49+
{ source: 'Liquid', target: 'Domestic aviation', value: 14.458 },
50+
{ source: 'Liquid', target: 'International aviation', value: 206.267 },
51+
{ source: 'Liquid', target: 'Agriculture', value: 3.64 },
52+
{ source: 'Liquid', target: 'National navigation', value: 33.218 },
53+
{ source: 'Liquid', target: 'Rail transport', value: 4.413 },
54+
{ source: 'Marine algae', target: 'Bio-conversion', value: 4.375 },
55+
{ source: 'Ngas', target: 'Gas', value: 122.952 },
56+
{ source: 'Nuclear', target: 'Thermal generation', value: 839.978 },
57+
{ source: 'Oil imports', target: 'Oil', value: 504.287 },
58+
{ source: 'Oil reserves', target: 'Oil', value: 107.703 },
59+
{ source: 'Oil', target: 'Liquid', value: 611.99 },
60+
{ source: 'Other waste', target: 'Solid', value: 56.587 },
61+
{ source: 'Other waste', target: 'Bio-conversion', value: 77.81 },
62+
{ source: 'Pumped heat', target: 'Heating and cooling - homes', value: 193.026 },
63+
{ source: 'Pumped heat', target: 'Heating and cooling - commercial', value: 70.672 },
64+
{ source: 'Solar PV', target: 'Electricity grid', value: 59.901 },
65+
{ source: 'Solar Thermal', target: 'Heating and cooling - homes', value: 19.263 },
66+
{ source: 'Solar', target: 'Solar Thermal', value: 19.263 },
67+
{ source: 'Solar', target: 'Solar PV', value: 59.901 },
68+
{ source: 'Solid', target: 'Agriculture', value: 0.882 },
69+
{ source: 'Solid', target: 'Thermal generation', value: 400.12 },
70+
{ source: 'Solid', target: 'Industry', value: 46.477 },
71+
{ source: 'Thermal generation', target: 'Electricity grid', value: 525.531 },
72+
{ source: 'Thermal generation', target: 'Losses', value: 787.129 },
73+
{ source: 'Thermal generation', target: 'District heating', value: 79.329 },
74+
{ source: 'Tidal', target: 'Electricity grid', value: 9.452 },
75+
{ source: 'UK land based bioenergy', target: 'Bio-conversion', value: 182.01 },
76+
{ source: 'Wave', target: 'Electricity grid', value: 19.013 },
77+
{ source: 'Wind', target: 'Electricity grid', value: 289.366 },
78+
],
79+
},
1080
},
1181
scale: {
1282
color: {
@@ -31,6 +101,19 @@ const DemoSankey = () => {
31101
nodeStrokeWidth: 1.2,
32102
linkFillOpacity: 0.4,
33103
},
104+
interaction: {
105+
tooltip: {
106+
render: (e, { title, items }) => {
107+
console.log(title, items);
108+
// const div = document.createElement('div');
109+
// const h3 = document.createElement('h3');
110+
// h3.innerHTML = title;
111+
// div.appendChild(h3);
112+
// div.innerHTML = `${source} → ${target}: ${value}`;
113+
return <div>123</div>;
114+
},
115+
},
116+
},
34117
};
35118
return <Sankey {...config} />;
36119
};

site/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"@ant-design/plots": "workspace:*",
4646
"antd": "^4.16.13",
4747
"insert-css": "^2.0.0",
48-
"lodash-es": "^4.17.21",
48+
"lodash": "^4.17.21",
4949
"rc-util": "^5.39.1",
5050
"react": "^16.14.0",
5151
"react-dom": "^16.14.0"

template/doc/demo.ejs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import React, { useState, useEffect }from 'react';
22
import ReactDOM from 'react-dom';
33
import { <%= plotName %> } from '@ant-design/<%= lib %>';
44
<% if (utilName) { %>
5-
import { <%= utilName %> } from 'lodash-es';
5+
import { <%= utilName %> } from 'lodash';
66
<% } %>
77

88
const Demo<%= chartName %> = () => {
99
<%- chartContent.toString() %>
1010
return <<%= chartName %> {...config} />;
1111
};
1212

13-
ReactDOM.render(<Demo<%= chartName %> />, document.getElementById('container'));
13+
ReactDOM.render(<Demo<%= chartName %> />, document.getElementById('container'));

0 commit comments

Comments
 (0)