Skip to content

Commit

Permalink
fix(static-site): remove gatsby-inlined-css
Browse files Browse the repository at this point in the history
Since Gatsby v2  CSS is inlined automagically and the explicit setup relying on existence of `public/styles.css` (previously containing a portion of styles to be inlined) is no longer necessary, and even worse, fails the production build with an error: 

   > Cannot find module '!raw-loader!../public/styles.css'.

This removes the explicit setup and resolves the error.

See discussion in:
 - #104
 - #75 (comment)
Relevant gatsby docs:
 - https://www.gatsbyjs.org/docs/migrating-from-v1-to-v2/#remove-inlined-css-in-htmljs

Resolves #104
  • Loading branch information
ivan-aksamentov committed Jan 30, 2020
1 parent 743379f commit c0c1615
Showing 1 changed file with 0 additions and 20 deletions.
20 changes: 0 additions & 20 deletions static-site/src/html.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,9 @@
import React from "react";
import favicon from "../../favicon.png";

let inlinedStyles = "";
if (process.env.NODE_ENV === "production") {
try {
// eslint-disable-next-line import/no-webpack-loader-syntax
inlinedStyles = require("!raw-loader!../public/styles.css");
} catch (e) {
console.log(e);
}
}

// eslint-disable-next-line react/prefer-stateless-function
export default class HTML extends React.Component {
render() {
let css;
if (process.env.NODE_ENV === "production") {
css = (
<style
id="gatsby-inlined-css"
dangerouslySetInnerHTML={{ __html: inlinedStyles }}
/>
);
}
return (
<html lang="en">
<head>
Expand All @@ -36,7 +17,6 @@ export default class HTML extends React.Component {
/>
{this.props.headComponents}
<link rel="shortcut icon" href={favicon} />
{css}
</head>
<body>
<div
Expand Down

0 comments on commit c0c1615

Please sign in to comment.