Skip to content

Commit

Permalink
package level optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Violet-Bora-Lee committed Aug 16, 2024
1 parent d0c932f commit ef2950d
Show file tree
Hide file tree
Showing 5 changed files with 552 additions and 6,618 deletions.
39 changes: 20 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.26.1",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
"chart.js": "^4.3.0",
"react": "^18.2.0",
"react-chartjs-2": "^5.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.11.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"devDependencies": {
"@babel/core": "^7.22.1",
"@babel/preset-env": "^7.22.4",
"@babel/preset-react": "^7.22.3",
"babel-loader": "^9.1.3",
"webpack": "^5.84.1",
"webpack-bundle-analyzer": "^4.9.0",
"webpack-cli": "^5.1.1",
"webpack-dev-server": "^4.15.0",
"html-webpack-plugin": "^5.5.0"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
"scripts": {
"start": "webpack serve --mode development",
"build": "webpack --mode production",
"build:analyze": "webpack --mode production --env analyze"
},
"browserslist": {
"production": [
Expand All @@ -36,4 +37,4 @@
"last 1 safari version"
]
}
}
}
35 changes: 2 additions & 33 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,11 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>Code Splitting Demo</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
</html>
55 changes: 53 additions & 2 deletions src/components/advanced/DataVisualization.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,58 @@
import React from 'react';
import React, { useState, useEffect } from 'react';

function DataVisualization() {
return <h3>Data Visualization Component</h3>;
const [ChartComponent, setChartComponent] = useState(null);

useEffect(() => {
const loadChart = async () => {
const { Chart, registerables } = await import('chart.js');
Chart.register(...registerables);
const { Bar } = await import('react-chartjs-2');
setChartComponent(() => Bar);
};

loadChart();
}, []);

const data = {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
};

const options = {
scales: {
y: {
beginAtZero: true
}
}
};

return (
<div>
<h2>Data Visualization</h2>
{ChartComponent && <ChartComponent data={data} options={options} />}
</div>
);
}

export default DataVisualization;
57 changes: 57 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

module.exports = (env, argv) => {
const config = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].[contenthash].js',
clean: true,
publicPath: '/',
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react']
}
}
}
]
},
optimization: {
splitChunks: {
chunks: 'all',
},
},
devServer: {
static: {
directory: path.join(__dirname, 'public'),
},
historyApiFallback: true,
open: true,
hot: true,
port: 3000,
},
resolve: {
extensions: ['.js', '.jsx'],
},
plugins: [
new HtmlWebpackPlugin({
template: './public/index.html',
}),
],
};

if (env.analyze) {
config.plugins.push(new BundleAnalyzerPlugin());
}

return config;
};
Loading

0 comments on commit ef2950d

Please sign in to comment.