Skip to content
Merged
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
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ postcss-import in your plugin chain will allow you to adjust assets `url()` (or
even inline them) after inlining imported files.
- In order to optimize output, **this plugin will only import a file once** on
a given scope (root, media query...).
Tests are made from the path & the content of imported files (using a hash
table).
Duplicates are detected by the resolved file path.
If this behavior is not what you want, look at `skipDuplicates` option
- If you are looking for **Glob Imports**, you can use [postcss-import-ext-glob](https://github.com/dimitrinicolas/postcss-import-ext-glob) to extend postcss-import.
- If you want to import remote sources, you can use [postcss-import-url](https://github.com/unlight/postcss-import-url) with its `dataUrls` plugin option to extend postcss-import.
Expand Down Expand Up @@ -183,10 +182,8 @@ promised content.
Type: `Boolean`
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.
By default, repeated imports of the same file are skipped.
Comment thread
Nic-Polumeyv marked this conversation as resolved.
Set this option to `false` to inline a file each time it is imported.

#### `addModulesDirectories`

Expand Down
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ function AtImport(options) {
async Once(styles, { result, atRule, postcss }) {
const state = {
importedFiles: {},
hashFiles: {},
}

if (styles.source?.input?.file) {
Expand Down
22 changes: 0 additions & 22 deletions lib/parse-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,6 @@ async function loadImportContent(
return
}

// skip previous imported files not containing @import rules
if (
options.skipDuplicates &&
state.hashFiles[content]?.[stmtDuplicateCheckKey]
) {
return
}

const importedResult = await processContent(
result,
content,
Expand All @@ -196,20 +188,6 @@ async function loadImportContent(
const styles = importedResult.root
result.messages = result.messages.concat(importedResult.messages)

if (options.skipDuplicates) {
const hasImport = styles.some(child => {
return child.type === "atrule" && child.name === "import"
})
if (!hasImport) {
// save hash files to skip them next time
if (!state.hashFiles[content]) {
state.hashFiles[content] = {}
}

state.hashFiles[content][stmtDuplicateCheckKey] = true
}
}

// recursion: import @import from imported file
return parseStyles(
result,
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 {}
4 changes: 4 additions & 0 deletions test/fixtures/no-duplicate.expected.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
foo{}
foo{}
@media screen{
foo{}
}
@media screen{
foo{}
}
Expand Down
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 {}
6 changes: 6 additions & 0 deletions test/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ test(

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

test(
"should not skip different files with the same content",
checkFixture,
"same-file-dedup",
)

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

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