Skip to content

Commit

Permalink
Update Rollup config to reduce build time and exclude deps
Browse files Browse the repository at this point in the history
  • Loading branch information
pkosiec committed Feb 11, 2022
1 parent df68cd2 commit 8e6bd0f
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 57 deletions.
7 changes: 4 additions & 3 deletions dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"dependencies": {
"@ant-design/icons": "^4.7.0",
"@capactio/react-components": "^0.1.0",
"@rjsf/antd": "^3.2.1",
"@rjsf/core": "^3.2.1",
"@testing-library/jest-dom": "^5.15.1",
"@testing-library/react": "^12.1.2",
"@testing-library/user-event": "^13.5.0",
Expand All @@ -22,8 +20,11 @@
"react-scripts": "5.0.0",
"styled-components": "^5.3.3",
"typescript": "^4.5.5",
"web-vitals": "^2.1.2",
"@rjsf/antd": "^3.2.1",
"@rjsf/core": "^3.2.1",
"unique-names-generator": "^4.6.0",
"web-vitals": "^2.1.2"
"react-query": "^3.33.7"
},
"scripts": {
"start": "react-scripts --max_old_space_size=4096 start",
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
QuestionCircleOutlined,
UserOutlined,
} from "@ant-design/icons";
import SubMenu from "antd/lib/menu/SubMenu";
import { Link } from "react-router-dom";

const { SubMenu } = Menu;
const { Header: AntHeader } = Layout;

function Header() {
Expand Down
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions react-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@
],
"types": "dist/index.d.ts",
"scripts": {
"start": "npm run build -- --watch",
"build": "NODE_OPTIONS=--max_old_space_size=4096 rollup -c",
"start": "NODE_OPTIONS=--max_old_space_size=4096 rollup -c --watch",
"build": "NODE_ENV=production NODE_OPTIONS=--max_old_space_size=4096 rollup -c",
"test": "jest",
"test:watch": "jest --watch",
"storybook": "start-storybook -p 6006",
"storybook:build": "build-storybook",
"generate-graphql-hooks": "set -o allexport;. .env; set +o allexport; graphql-codegen --config codegen.yml; prettier --write 'src/generated/**/*.{js,jsx,ts,tsx,json,css,scss,md,graphql}' 'graphql.schema.json'"
},
"peerDependencies": {
"@ant-design/icons": "^4.7.0",
"antd": "^4.18.5",
"react": "^17.0.2",
"styled-components": "^5.3.3"
"styled-components": "^5.3.3",
"@rjsf/antd": "^3.2.1",
"@rjsf/core": "^3.2.1",
"unique-names-generator": "^4.6.0",
"react-query": "^3.33.7"
},
"devDependencies": {
"@babel/core": "^7.17.0",
Expand Down Expand Up @@ -53,9 +58,9 @@
"graphql": "^16.2.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^27.5.1",
"react-query": "^3.33.7",
"rollup": "^2.67.0",
"rollup-plugin-dts": "^4.1.0",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-terser": "^7.0.2",
"rollup-watch": "^4.3.1",
Expand Down
73 changes: 41 additions & 32 deletions react-components/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,54 @@
import { defineConfig } from "rollup";
import resolve from "@rollup/plugin-node-resolve";
import replace from '@rollup/plugin-replace';
import replace from "@rollup/plugin-replace";
import commonJS from "@rollup/plugin-commonjs";
import postcss from "rollup-plugin-postcss";
import typescript from "@rollup/plugin-typescript";
import dts from "rollup-plugin-dts";
import { terser } from "rollup-plugin-terser";
import json from "@rollup/plugin-json";
import peerDepsExternal from "rollup-plugin-peer-deps-external";

// eslint-disable-next-line @typescript-eslint/no-var-requires
const packageJSON = require("./package.json");

const external = [
...Object.keys(packageJSON.dependencies || {}),
...Object.keys(packageJSON.peerDependencies || {}),
const isDevMode = process.env.NODE_ENV !== "production";
const plugins = [
peerDepsExternal({ includeDependencies: false }),
resolve({
browser: true,
moduleDirectories: ["node_modules", "../node_modules"],
}),
replace({
preventAssignment: true,
"process.env.NODE_ENV": JSON.stringify(
process.env.NODE_ENV || "development"
),
}),
commonJS(),
typescript({
tsconfig: "./tsconfig.json",
exclude: [
"**/*.test.ts",
"**/*.test.tsx",
"**/*.stories.mdx",
"**/*.stories.ts",
],
}),
postcss(),
json(),
];

if (!isDevMode) {
plugins.push(...[terser()]);
}

const config = [
{
defineConfig({
input: "src/index.ts",
treeshake: {
moduleSideEffects: true,
},
output: [
{
file: packageJSON.main,
Expand All @@ -30,36 +61,14 @@ const config = [
sourcemap: true,
},
],
plugins: [
resolve({
browser: true,
}),
replace({
preventAssignment: true,
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}),
commonJS(),
typescript({
tsconfig: "./tsconfig.json",
exclude: [
"**/*.test.ts",
"**/*.test.tsx",
"**/*.stories.mdx",
"**/*.stories.ts",
],
}),
postcss(),
json(),
terser(),
],
external,
},
{
plugins,
}),
defineConfig({
input: "dist/esm/types/index.d.ts",
output: [{ file: "dist/index.d.ts", format: "esm" }],
plugins: [dts()],
external: [/\.css$/, ...external],
},
external: [/\.css$/],
}),
];

export default config;
1 change: 0 additions & 1 deletion react-components/src/actions/ActionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export interface ActionListProps {
onActionClick: (name: string) => void;
}


export function ActionList({ data, isLoading, error, onActionClick }: ActionListProps) {
if (error) {
return <ErrorAlert error={error} />;
Expand Down
6 changes: 1 addition & 5 deletions react-components/src/hub/Interfaces.container.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import React from "react";
import {
InterfaceRevision,
useListInterfacesFromInterfaceGroupQuery,
} from "../generated/graphql";
import { InterfacesCard } from "./InterfacesCard";
import { ResourceReference } from "../wizard/ResourceRef";
import { InterfacesList } from "./InterfacesList";
import { Result } from "antd";
import { InterfaceRevisionWithKey } from ".";

export enum InterfacesView {
Card,
List,
}

export interface InterfaceRevisionWithKey extends InterfaceRevision {
key: string;
}

export interface InterfacesContainerProps {
path: string;
view: InterfacesView;
Expand Down
6 changes: 2 additions & 4 deletions react-components/src/hub/InterfacesCard.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Card, Col, Row, Statistic } from "antd";
import React from "react";
import { renderInterfaceActionsButtons } from ".";
import { renderInterfaceActionsButtons } from "./render-interface-action-buttons";
import { InterfaceRevisionWithKey } from "./interface-revision";
import { CenteredSpinner, ErrorAlert } from "../layout";
import {
InterfaceRevisionWithKey,
} from "./Interfaces.container";
import "./InterfacesCard.css";

export interface InterfacesCardProps {
Expand Down
6 changes: 2 additions & 4 deletions react-components/src/hub/InterfacesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import "./InterfacesList.css";
import React, { useState } from "react";
import { CenteredSpinner, ErrorAlert } from "../layout";
import { SearchOutlined } from "@ant-design/icons";
import {
InterfaceRevisionWithKey,
} from "./Interfaces.container";
import { TypeReference } from "../generated/graphql";
import { renderInterfaceActionsButtons } from ".";
import { renderInterfaceActionsButtons } from "./render-interface-action-buttons";
import { InterfaceRevisionWithKey } from "./interface-revision";

const { Item } = List;

Expand Down
1 change: 1 addition & 0 deletions react-components/src/hub/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './InterfaceGroupCards.container';
export * from './Interfaces.container';
export * from './InterfacesCard';
export * from './InterfacesList';
export * from './interface-revision';
5 changes: 5 additions & 0 deletions react-components/src/hub/interface-revision.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { InterfaceRevision } from "..";

export interface InterfaceRevisionWithKey extends InterfaceRevision {
key: string;
}
3 changes: 1 addition & 2 deletions react-components/src/typeinstances/TypeInstanceDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import { Button, Descriptions, List, Modal, Typography } from "antd";
import { ErrorAlert } from "../layout";
import { CenteredSpinner } from "../layout/CenteredSpinner";
import { TypeInstanceQuery } from "../generated/graphql";
import Paragraph from "antd/lib/typography/Paragraph";

import "./TypeInstanceDetails.css";

const { Text } = Typography;
const { Text, Paragraph } = Typography;

export interface TypeInstanceDetailsProps {
visible: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { Button, Modal, Space } from "antd";
import { CheckCircleOutlined } from "@ant-design/icons";
import { AdditionalInputSchema } from "./SelectImplAdditionalInput.container";
import { ErrorAlert, Form, CenteredSpinner } from "../../layout";
import Title from "antd/lib/typography/Title";

import { Typography } from "antd";

const { Title } = Typography;

export interface ImplAdditionalInputSectionProps {
additionalInputSchema: AdditionalInputSchema;
Expand Down

0 comments on commit 8e6bd0f

Please sign in to comment.