Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Css duplicates #432

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions .changeset/orange-vans-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'wmr': patch
---

Fix case where deduped css would crash the bundle
9 changes: 5 additions & 4 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

<!--
Expand All @@ -16,6 +15,7 @@ A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
Expand All @@ -25,9 +25,10 @@ Steps to reproduce the behavior:
A clear and concise description of what you expected to happen.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- WMR Version [e.g. 22]

- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- WMR Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''

---

<!--
Expand Down
23 changes: 13 additions & 10 deletions packages/wmr/src/lib/cssnano-lite.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* This is essentially the same plugins, but without SVGO.
*/
import postcss from 'postcss';
import cssDeclarationSorter from 'css-declaration-sorter';
import discardComments from 'postcss-discard-comments';
import postcssReduceInitial from 'postcss-reduce-initial';
import postcssReduceTransforms from 'postcss-reduce-transforms';
Expand Down Expand Up @@ -30,6 +31,7 @@ import postcssNormalizeTimingFunctions from 'postcss-normalize-timing-functions'

const rawCache = postcss.plugin('cssnano-util-raw-cache', () => {
return (css, result) => {
// @ts-ignore-next
result.root.rawCache = {
colon: ':',
indent: '',
Expand All @@ -50,27 +52,28 @@ const plugins = [
discardComments,
postcssReduceInitial,
postcssReduceTransforms,
postcssConvertValues,
postcssCalc,
postcssNormalizeDisplayValues,
postcssColormin,
postcssNormalizeTimingFunctions,
postcssCalc,
postcssConvertValues,
postcssOrderedValues,
postcssMinifySelectors,
postcssMinifyParams,
postcssDiscardOverridden,
postcssNormalizeString,
postcssNormalizeUnicode,
postcssMinifyFontValues,
postcssNormalizeUrl,
postcssNormalizeRepeatStyle,
postcssNormalizePositions,
postcssNormalizeWhitespace,
postcssMergeLonghand,
postcssDiscardDuplicates,
postcssDiscardOverridden,
postcssNormalizeRepeatStyle,
postcssMergeRules,
postcssDiscardEmpty,
postcssUniqueSelectors,
postcssNormalizeString,
postcssNormalizePositions,
postcssNormalizeWhitespace,
postcssNormalizeUnicode,
postcssNormalizeDisplayValues,
postcssNormalizeTimingFunctions,
cssDeclarationSorter,
rawCache
].map(fn => (fn && fn.default) || fn);

Expand Down
8 changes: 8 additions & 0 deletions packages/wmr/src/plugins/optimize-graph-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default function optimizeGraphPlugin({ publicPath = '', cssMinSize = 1000
mergeAdjacentCss(graph);
hoistCascadedCss(graph, { cssMinSize });
hoistEntryCss(graph);
graph.commit();
hoistTransitiveImports(graph);
}
};
Expand All @@ -42,13 +43,20 @@ export default function optimizeGraphPlugin({ publicPath = '', cssMinSize = 1000
class ChunkGraph {
constructor(bundle, { publicPath }) {
this.bundle = bundle;
this.bundleRemoved = new Set();
this.assetToChunkMap = constructAssetToChunkMap(bundle);
this.entries = this.findEntryChunks();
this.meta = new Map();
this.publicPath = publicPath;
// this.entryAssets = this.findEntryAssets();
}

commit() {
this.bundleRemoved.forEach(f => {
delete this.bundle[f];
});
}

/**
* Get a mutable object for storing metadata about a chunk/asset.
* @param {string} fileName
Expand Down
Loading