Skip to content

Commit

Permalink
Minify mui css
Browse files Browse the repository at this point in the history
  • Loading branch information
revskill10 committed Nov 3, 2018
1 parent f68515a commit cf32272
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
"test": "jest",
"analyze": "BUNDLE_ANALYZE=both next build",
"analyze:server": "BUNDLE_ANALYZE=server next build",
"analyze:browser": "BUNDLE_ANALYZE=browser next build",
"release": "npx semantic-release",
"semantic-release": "semantic-release"
"analyze:browser": "BUNDLE_ANALYZE=browser next build"
},
"dependencies": {
"@material-ui/core": "3.3.2",
Expand All @@ -36,6 +34,7 @@
"axios": "0.18.0",
"cookie": "0.3.1",
"cookie-parser": "1.4.3",
"csso": "3.5.1",
"dotenv": "6.1.0",
"exceljs": "1.6.2",
"express": "4.16.4",
Expand Down
8 changes: 6 additions & 2 deletions packages/containers/next-document.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Head, Main, NextScript } from 'next/document'

const Document = ({styleTags, pageContext}) =>
<html lang="en" dir="ltr">
const Document = ({styleTags, pageContext}) => {
return (
<html lang="en" dir="ltr">
<Head>
<meta charSet="utf-8" />
{/* Use minimum-scale=1 to enable GPU rasterization */}
Expand All @@ -22,5 +23,8 @@ const Document = ({styleTags, pageContext}) =>
<NextScript />
</body>
</html>
)
}


export default Document
7 changes: 6 additions & 1 deletion packages/lib/hocs/with-document.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Document from 'next/document'
import { ServerStyleSheet } from 'styled-components'
import flush from 'styled-jsx/server';
import PropTypes from 'prop-types';
import csso from 'csso'

export const withDocument = Container =>
class extends Document {
Expand Down Expand Up @@ -45,6 +46,10 @@ export const withDocument = Container =>
});

const styleTags = sheet.getStyleElement()
const css = pageContext.sheetsRegistry.toString()
const ast = csso.syntax.parse(css);
const compressedAst = csso.compress(ast).ast;
const minifiedCss = csso.syntax.generate(compressedAst);
return {
...page,
pageContext,
Expand All @@ -54,7 +59,7 @@ export const withDocument = Container =>
<style
id="jss-server-side"
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{ __html: pageContext.sheetsRegistry.toString() }}
dangerouslySetInnerHTML={{ __html: minifiedCss }}
/>
{flush() || null}
</React.Fragment>
Expand Down

1 comment on commit cf32272

@vercel
Copy link

@vercel vercel bot commented on cf32272 Nov 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now could not deploy this pull request since the now.json file explicitly sets dotenv to true.
However, there's no .env file in the repo.

Commit a .env file or unset the dotenv flag.
For secret environment variables, check out Now Secrets.

Please sign in to comment.