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

Charts: Replace Rollup with Webpack #40912

Merged
merged 26 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
426 changes: 363 additions & 63 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Replace Rollup with Webpack for charts
48 changes: 27 additions & 21 deletions projects/js-packages/charts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
"test-coverage": "pnpm run test --coverage",
"storybook": "cd ../storybook && pnpm run storybook:dev",
"compile-ts": "tsc --pretty",
"build": "rollup -c",
"build:prod": "rollup -c --environment NODE_ENV:production",
"build:dev": "rollup -c --environment NODE_ENV:development",
"build:watch": "rollup -c -w",
"clean-build": "rm -rf dist/"
"clean-build": "rm -rf dist/",
"build": "pnpm run build:cjs && pnpm run build:esm && bash ./tools/fixup.sh",
"build:cjs": "webpack --config webpack-cjs.cjs --mode production",
"build:esm": "webpack --config webpack-esm.cjs --mode production",
"build:types": "tsc --emitDeclarationOnly --declaration --declarationDir dist"
},
"dependencies": {
"@babel/runtime": "7.26.0",
"@react-spring/web": "9.7.3",
"@visx/axis": "^3.12.0",
"@visx/event": "^3.8.0",
Expand All @@ -42,45 +43,50 @@
"tslib": "2.5.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "26.0.1",
"@rollup/plugin-json": "6.1.0",
"@rollup/plugin-node-resolve": "15.3.0",
"@rollup/plugin-terser": "0.4.3",
"@rollup/plugin-typescript": "12.1.0",
"@babel/core": "7.26.0",
"@babel/plugin-transform-runtime": "7.25.9",
"@babel/preset-env": "7.26.0",
"@babel/preset-react": "7.26.3",
"@babel/preset-typescript": "7.26.0",
"@storybook/blocks": "8.4.7",
"@storybook/react": "8.4.7",
"@types/react": "18.3.18",
"@types/react-dom": "18.3.5",
"babel-loader": "9.1.2",
"clean-webpack-plugin": "^4.0.0",
"css-loader": "^6.7.0",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"jest-extended": "4.0.2",
"mini-css-extract-plugin": "^2.7.0",
"postcss": "8.4.47",
"postcss-loader": "^7.0.0",
"postcss-modules": "6.0.1",
"react": "18.3.1",
"react-dom": "18.3.1",
"rollup": "3.29.5",
"rollup-plugin-dts": "6.1.1",
"rollup-plugin-peer-deps-external": "2.2.4",
"rollup-plugin-postcss": "4.0.2",
"sass": "1.64.1",
"sass-embedded": "1.83.0",
"sass-loader": "^13.0.0",
"storybook": "8.4.7",
"typescript": "5.7.2"
"ts-loader": "^9.4.0",

Check failure on line 71 in projects/js-packages/charts/package.json

View workflow job for this annotation

GitHub Actions / Project structure

For consistency we've settled on using `@babel/preset-typescript` (and `fork-ts-checker-webpack-plugin` or `tsc` for definition files) rather than `ts-loader`. Please switch to that.
"typescript": "5.7.2",
"webpack": "^5.88.0",
"webpack-cli": "^5.1.0"
},
"peerDependencies": {
"react": "^17.0.0 || ^18.0.0",
"react-dom": "^17.0.0 || ^18.0.0"
},
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"types": "./dist/index.d.ts"
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.cjs",
"types": "./dist/esm/index.d.ts"
},
"./components/*": {
"import": "./dist/components/*/index.js",
"require": "./dist/components/*/index.cjs.js",
"types": "./dist/components/*/index.d.ts"
"import": "./dist/esm/components/*/index.js",
"require": "./dist/cjs/components/*/index.cjs",
"types": "./dist/esm/components/*/index.d.ts"
},
"./style.css": "./dist/style.css"
},
Expand Down
142 changes: 0 additions & 142 deletions projects/js-packages/charts/rollup.config.mjs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { GridControl } from '../grid-control';
import { Legend } from '../legend';
import { BaseTooltip } from '../tooltip';
import styles from './bar-chart.module.scss';
import type { BaseChartProps, SeriesData } from '../shared/types';
import type { BaseChartProps, SeriesData } from '../../types';

interface BarChartProps extends BaseChartProps< SeriesData[] > {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GridRows, GridColumns } from '@visx/grid';
import React from 'react';
import styles from './grid-control.module.scss';
import type { GridProps } from '../shared/types';
import type { GridProps } from '../../types';

const GridControl: React.FC< GridProps > = ( {
width,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { FC } from 'react';
import { useChartTheme } from '../../providers/theme/theme-provider';
import { Legend } from '../legend';
import styles from './line-chart.module.scss';
import type { BaseChartProps, DataPointDate, SeriesData } from '../shared/types';
import type { BaseChartProps, DataPointDate, SeriesData } from '../../types';

// TODO: revisit grid and axis options - accept as props for frid lines, axis, values: x, y, all, none

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SeriesData } from '../../shared/types';
import type { SeriesData } from '../../types';

// Sample data
const temperatureData: SeriesData[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useChartTheme, defaultTheme } from '../../providers/theme';
import { Legend } from '../legend';
import { BaseTooltip } from '../tooltip';
import styles from './pie-chart.module.scss';
import type { BaseChartProps, DataPointPercentage } from '../shared/types';
import type { BaseChartProps, DataPointPercentage } from '../../types';
import type { PieArcDatum } from '@visx/shape/lib/shapes/Pie';

// TODO: add animation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useChartTheme } from '../../providers/theme/theme-provider';
import { Legend } from '../legend';
import { BaseTooltip } from '../tooltip';
import styles from './pie-semi-circle-chart.module.scss';
import type { BaseChartProps, DataPointPercentage } from '../shared/types';
import type { BaseChartProps, DataPointPercentage } from '../../types';

interface PieSemiCircleChartProps extends BaseChartProps< DataPointPercentage[] > {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,5 @@ export type GridProps = {
*/
top?: number;
};

declare module '*.module.scss';
11 changes: 11 additions & 0 deletions projects/js-packages/charts/tools/fixup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cat >dist/cjs/package.json <<!EOF
{
"type": "commonjs"
}
!EOF

cat >dist/esm/package.json <<!EOF
{
"type": "module"
}
!EOF
83 changes: 83 additions & 0 deletions projects/js-packages/charts/tools/webpack.common.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
const { CleanWebpackPlugin } = require( 'clean-webpack-plugin' );
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );

// List of components to build individually
const components = [
'components/bar-chart',
'components/line-chart',
'components/pie-chart',
'components/pie-semi-circle-chart',
'components/tooltip',
'components/legend',
'components/grid-control',
'providers/theme',
];

// Common configuration for both ESM and CommonJS builds
const getCommonConfig = isESM => ( {
module: {
rules: [
{
test: /\.(ts|tsx)$/,
use: [
{
loader: 'babel-loader',
options: {
presets: [ '@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript' ],
plugins: [ [ '@babel/plugin-transform-runtime', { useESModules: isESM } ] ],
},
},
],
exclude: /node_modules/,
},
{
test: /\.(scss|css)$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: {
localIdentName: '[name]__[local]__[hash:base64:5]',
kangzj marked this conversation as resolved.
Show resolved Hide resolved
},
importLoaders: 2,
},
},
'postcss-loader',
'sass-loader',
],
},
],
},
resolve: {
extensions: [ '.tsx', '.ts', '.js', '.jsx' ],
},
externals: [ 'react', 'react-dom', /^@visx\/.*/, '@react-spring/web', 'clsx', 'tslib' ],
plugins: [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin( {
filename: pathData => {
const name = pathData.chunk.name;
if ( name === 'index' ) {
return 'style.css';
}
return `${ name }/style.css`;
},
} ),
],
} );

// Generate entry points for components
const getComponentEntries = () => {
const entries = {
index: './src/index.ts',
};

components.forEach( component => {
entries[ component ] = `./src/${ component }/index`;
} );

return entries;
};

module.exports = { getCommonConfig, getComponentEntries };
2 changes: 1 addition & 1 deletion projects/js-packages/charts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"typeRoots": [ "./node_modules/@types/", "src/*" ]
},
"include": [ "src" ],
"exclude": [ "node_modules", "dist" ]
"exclude": [ "node_modules", "dist", "**/stories/*" ]
}
Loading
Loading