question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing styles in build vs start

See original GitHub issue

Hi there,

I’m having all sorts of issues that I can’t seem to pin down with my built assets not retaining a portion of their styles, using styled-components.

Eg: screen shot 2018-11-29 at 4 34 21 pm

vs

screen shot 2018-11-29 at 4 35 45 pm

My webpack config as is follows:

  webpackConfig: () => ({
    module: {
      rules: [
        {
          test: /\.js$/,
          loader: 'babel-loader',
          query: {
            plugins: ['lodash'],
            presets: [
              '@babel/preset-react',
              [
                '@babel/preset-env',
                {
                  targets: ['last 2 versions', 'ie >= 11']
                }
              ]
            ]
          },
          exclude: [
            /node_modules\/(?!(@anz)\/).*/
          ]
        },
        {
          test: /\.(otf|ttf|eot|woff(2)?)(\?[a-z0-9=&.]+)?$/,
          loader: 'file-loader'
        },
        {
          test: /\.(jpe?g|png|gif|svg|ico)$/,
          loader: 'file-loader?name=assets/[name].[ext]',
          exclude: '/node_modules/'
        }
      ]
    },
    resolve: {
      extensions: ['.js', '.jsx', '.json']
    }
  })

and frame component is:

import React from 'react'
import { StyleSheetManager } from 'styled-components'

export default ({ children, frameWindow }) => (
  <StyleSheetManager target={frameWindow.document.head}>
    {children}
  </StyleSheetManager>
)

Everything works perfectly using start but the built assets seem to lose some of their font-family, padding, and margin, while color and border seem to stay attached somehow. No webpack errors in the terminal while building, and the generated style tags in each frame’s head are empty in build, but full of expected classes etc in start.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
lolivercommented, Dec 5, 2018

Upgrading to styled-components 4.x.x and using createGlobalStyles instead of injectGlobal works, guessing this will fall in to the black hole of every other issue people have had with injectGlobal which caused them to deprecate it.

If you’re interested in looking any further in to this go ahead but I’m happy to close it and move on and just wait until we are at a point that we can upgrade styled-components.

1reaction
lolivercommented, Nov 29, 2018

https://github.com/patrickmarabeas/nothing-to-see-here/tree/stuff

Pat has kindly donated a private repo so it’s less likely I’ll get fired out of a cannon in to the sun for doing this, haha.

Read more comments on GitHub >

github_iconTop Results From Across the Web

webpack: custom style is missing after production build
When I'm running build with development mode - everything is ok and my styles are exist in the bundle. Such happens only with...
Read more >
ng build - Angular
Option Description Value Type Default Value ‑‑aot Build using Ahead of Time compilation. boolean true ‑‑base‑href Base url for the application being built. string ‑‑delete‑output‑path Delete...
Read more >
ASP.NET Core Blazor CSS isolation - Microsoft Learn
Isolate CSS styles to individual pages, views, and components to reduce or avoid: Dependencies on global styles that can be challenging to ...
Read more >
style-loader - webpack
To begin, you'll need to install style-loader : npm install --save-dev style-loader. or yarn add -D style-loader. or pnpm add -D style-loader.
Read more >
Styling - Remix
import styles from "~/styles/global.css"; // styles is now something like /build/global-AE33KB2.css export function links() { return [{ rel: "stylesheet", ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found