CSS imports disappear in webpack 5 production builds when sideEffects is omitted
0 reputation · 05 Nov 2020, 20:10 UTC
CSS imports missing in webpack 5 production builds
Goal: Determine how webpack 5 should interpret a missing sideEffects field in package.json when deciding whether to preserve CSS imports during production‑mode tree shaking.
In development mode, webpack does not apply sideEffects‑based tree shaking, so CSS imports remain in the bundle regardless of the field. In production mode, the absence of a sideEffects field leads webpack to treat modules as pure and drop CSS imports, causing styles to disappear even though they work locally.
The unresolved decision is whether webpack should treat an unspecified sideEffects field as an explicit opt‑out of side‑effect elimination (i.e., assume no side effects) or as a default that assumes all modules have side effects. This choice affects bundle size correctness and the reliability of style‑loading across environments.
- Should webpack treat a missing sideEffects field as an opt‑out, thereby removing CSS imports in production?
- Should webpack assume all modules have side effects when the field is omitted, preserving CSS imports?
- What are the trade‑offs between bundle size and runtime correctness for each approach?