Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,19 @@ promised content.

#### `skipDuplicates`

Type: `Boolean`
Type: `Boolean` or `"same-file"`
Default: `true`

By default, similar files (based on the same content) are being skipped.
It's to optimize output and skip similar files like `normalize.css` for example.
If this behavior is not what you want, just set this option to `false` to
disable it.

Setting this option to `"same-file"` skips repeated imports of the same file,
but not different files sharing the same content. Use it when imported files
contain at-rules whose paths resolve relative to the file's own location, so
that byte-identical files at different paths are not actually duplicates.

#### `addModulesDirectories`

Type: `Array`
Expand Down
5 changes: 3 additions & 2 deletions lib/parse-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ async function loadImportContent(
}

// skip previous imported files not containing @import rules
// (content dedup does not apply in "same-file" mode)
if (
options.skipDuplicates &&
options.skipDuplicates === true &&
state.hashFiles[content]?.[stmtDuplicateCheckKey]
) {
return
Expand All @@ -196,7 +197,7 @@ async function loadImportContent(
const styles = importedResult.root
result.messages = result.messages.concat(importedResult.messages)

if (options.skipDuplicates) {
if (options.skipDuplicates === true) {
const hasImport = styles.some(child => {
return child.type === "atrule" && child.name === "import"
})
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/imports/same-file-dedup/a/shared.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shared {}
1 change: 1 addition & 0 deletions test/fixtures/imports/same-file-dedup/b/shared.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shared {}
3 changes: 3 additions & 0 deletions test/fixtures/same-file-dedup.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@import "same-file-dedup/a/shared.css";
@import "same-file-dedup/b/shared.css";
@import "same-file-dedup/a/shared.css";
2 changes: 2 additions & 0 deletions test/fixtures/same-file-dedup.expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
shared {}
shared {}
9 changes: 9 additions & 0 deletions test/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ test(

test("should import stylesheets with same content", checkFixture, "same")

test(
"should only skip same-file duplicates with skipDuplicates: same-file",
checkFixture,
"same-file-dedup",
{
skipDuplicates: "same-file",
},
)

test("should ignore & adjust external import", checkFixture, "ignore")

test("should not fail with only one absolute import", t => {
Expand Down