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.

Webpack CSS-build behaves differently in production than in development

See original GitHub issue

Has anyone had an issue with CSS working differently in development than in a production build?

I refactored a large App to CRA, it had a single index.scss entry point which I just import in App.js.

// index.scss
@import "somefile.scss";
@import "someotherfile.scss";
// App.js
import "./index.scss";

Well, I’m noticing that when running npm start the app works perfectly in development. But when running npm run build and then deploy it to a staging environment, the app has slight visual differences, as if “somefile.scss” had higher specificity over “someotherfile.scss” (the opposite should be true). Does webpack do something different when building stylesheets for production?

I do not know how to report this as a bug, I can’t reproduce with a small app, so I’m wondering if anyone else is having this issue. I’ve seen multiple similar issues in other repos but not CRA.

Edit

I’m using react-scripts@^2.1.3

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

0reactions
pgarciacamoucommented, Feb 8, 2019

I found the difference :: not a webpack/CRA bug (per se).

My issue is actually outside of index.scss and happens because our app is lazy-loading some other styles and manually moving them into a child iframe.

The difference between dev and production build is that webpack seems to bundle the lazily-loaded-stylesheets as chunks and loads them using <link> elements, while in development, it uses <style> elements and injects as text.

Like so:

<!-- production -->
<link href="1.chunk.123123.css" rel="stylesheet">
<!-- development -->
<style>
  .code {}
</style>

Long story short: the app was not finding the style tag to be moved and is conflicting with the top frame styles.

Read more comments on GitHub >

github_iconTop Results From Across the Web

webpack build css rules have different order then in ...
When I am running npm run build to build a distribution for my Vue.js application the CSS rules applied in the dist app...
Read more >
Why production behave different than development?
Right my website works perfectly on development, no errors, no warnings as I want to. npm run build and everything falls apart, ...
Read more >
Webpack 5 Full Project Setup - YouTube
Outputting all CSS to a file with mini- css -extract-plugin - HTML templates with html- webpack -plugin - Cleaning the output folder every...
Read more >
A mostly complete guide to webpack 5 (2020)
webpack has two modes of operations: development and production. ... To test CSS in webpack create a simple stylesheet in src/style.css :.
Read more >
How to configure Webpack 4 with VueJS : a complete guide
js files are loaded with babel-loader. The way styles are loaded is different depending if you are working in development or production: .css...
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