Skip to content
Snippets Groups Projects
Commit a5262441 authored by Andy Summers's avatar Andy Summers
Browse files

Configure Rollup to ignore external dependencies

Rollup is now configured to not bundle external dependencies. This
allows Material-UI to be used in the project while not inflating
bundle sizes or causing duplicated instances of `@material-ui/styles`
from being included in an app.

All of this was to support using the default theme's box shadow for
Contained-disabled buttons.
parent 8abb8456
No related branches found
No related tags found
1 merge request!4Configure Rollup to ignore external dependencies
...@@ -26,16 +26,13 @@ $ npm install --save @uw-ui-development/uw-material-ui-react ...@@ -26,16 +26,13 @@ $ npm install --save @uw-ui-development/uw-material-ui-react
```jsx ```jsx
import React from "react"; import React from "react";
import ReactDOM from "react-dom"; import ReactDOM from "react-dom";
import { createMuiTheme } from "@material-ui/core/styles";
import { ThemeProvider } from "@material-ui/styles"; import { ThemeProvider } from "@material-ui/styles";
import Button from "@material-ui/core/Button"; import Button from "@material-ui/core/Button";
import { theme } from "@uw-ui-development/uw-material-ui-react"; import { theme } from "@uw-ui-development/uw-material-ui-react";
const uwMadison = createMuiTheme(theme);
function App(props) { function App(props) {
return ( return (
<ThemeProvider theme={uwMadison}> <ThemeProvider theme={theme}>
<Button>{props.text}</Button> <Button>{props.text}</Button>
</ThemeProvider> </ThemeProvider>
); );
......
{ {
"name": "@uw-ui-development/uw-material-ui-react", "name": "@uw-ui-development/uw-material-ui-react",
"version": "0.0.11", "version": "0.1.0",
"description": "Preconfigured UW-Madison styles for Material-UI projects", "description": "Preconfigured UW-Madison styles for Material-UI projects",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
"build": "npx rollup ./src/index.js --format cjs --file ./dist/index.js && cp src/index.d.ts dist/", "build": "npx rollup -c && cp src/index.d.ts dist/",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"keywords": [], "keywords": [],
...@@ -14,16 +14,17 @@ ...@@ -14,16 +14,17 @@
"dist" "dist"
], ],
"peerDependencies": { "peerDependencies": {
"@material-ui/core": "^4.5.0" "@material-ui/core": "^4.5.2"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.6.4", "@babel/core": "^7.6.4",
"@babel/preset-env": "^7.6.3", "@babel/preset-env": "^7.6.3",
"@material-ui/core": "^4.5.0",
"eslint": "^6.4.0", "eslint": "^6.4.0",
"prettier": "^1.18.2", "prettier": "^1.18.2",
"rollup": "^1.26.0", "rollup": "^1.26.0",
"rollup-plugin-babel": "^4.3.3" "rollup-plugin-babel": "^4.3.3",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-uglify": "^6.0.3"
}, },
"prettier": { "prettier": {
"trailingComma": "es5" "trailingComma": "es5"
......
import babel from "rollup-plugin-babel";
import resolve from "rollup-plugin-node-resolve";
import { uglify } from "rollup-plugin-uglify";
export default {
input: "src/index.js",
output: {
file: "dist/index.js",
format: "cjs",
},
plugins: [
resolve({
customResolveOptions: {
moduleDirectory: "node_modules",
},
}),
babel({
exclude: "node_modules/**",
}),
uglify(),
],
external: ["@material-ui/core/styles", "@material-ui/styles"],
};
import { createMuiTheme } from "@material-ui/core/styles";
const theme = createMuiTheme();
export default theme;
import { createMuiTheme } from "@material-ui/core/styles";
import { colorRed, colorBlue, colorBlackFont, colorGrayLight } from "./colors"; import { colorRed, colorBlue, colorBlackFont, colorGrayLight } from "./colors";
import ButtonOverrides from "./overrides/buttons"; import ButtonOverrides from "./overrides/buttons";
export const theme = { export const themeConfig = {
props: { props: {
MuiButton: { MuiButton: {
color: "secondary", color: "secondary",
...@@ -57,3 +59,5 @@ export const theme = { ...@@ -57,3 +59,5 @@ export const theme = {
borderRadius: 2, borderRadius: 2,
}, },
}; };
export const theme = createMuiTheme(themeConfig);
import defaultTheme from "../defaultTheme";
import { colorBlueHover, colorGrayHover, colorGrayLight } from "../colors"; import { colorBlueHover, colorGrayHover, colorGrayLight } from "../colors";
const containedOverrides = { const containedOverrides = {
...@@ -7,6 +8,7 @@ const containedOverrides = { ...@@ -7,6 +8,7 @@ const containedOverrides = {
"&:disabled": { "&:disabled": {
borderColor: colorGrayLight, borderColor: colorGrayLight,
color: colorGrayLight, color: colorGrayLight,
boxShadow: defaultTheme.shadows[2],
}, },
}; };
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment