-
-
Notifications
You must be signed in to change notification settings - Fork 251
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
Recover reject css with webpack plugin #819
Closed
Quidam74
wants to merge
8
commits into
FullHuman:main
from
Quidam74:recoverRejectCSSWithWebpackPlugin
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
943f177
wip add option rejectedCss to webpack
Quidam74 175dc02
emit/update name-rejected.css file near name.css
Quidam74 ba07933
change generation of path output
Quidam74 c066db9
document use of rejectedCss in readme
Quidam74 018a000
Add tests to the webpack plugin for the rejectedCss option
kevinramharak 78023b2
Implement setting rejectedCss as a webpack template string
kevinramharak df809d6
fix option interpretation
kevinramharak dff3e10
Merge pull request #2 from kevinramharak/recoverRejectCSSWithWebpackP…
Quidam74 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...ss-webpack-plugin/__tests__/cases/rejected-css-template-name/expected/styles.rejected.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
|
||
.rejected { | ||
color: blue; | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/purgecss-webpack-plugin/__tests__/cases/rejected-css-template-name/src/content.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<html> | ||
|
||
<head> | ||
<title>Purgecss webpack test</title> | ||
</head> | ||
|
||
<body> | ||
<div class="preserved"></div> | ||
</body> | ||
|
||
</html> |
1 change: 1 addition & 0 deletions
1
packages/purgecss-webpack-plugin/__tests__/cases/rejected-css-template-name/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import "./style.css"; |
8 changes: 8 additions & 0 deletions
8
packages/purgecss-webpack-plugin/__tests__/cases/rejected-css-template-name/src/style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
.preserved { | ||
color: red; | ||
} | ||
|
||
.rejected { | ||
color: blue; | ||
} |
44 changes: 44 additions & 0 deletions
44
...ages/purgecss-webpack-plugin/__tests__/cases/rejected-css-template-name/webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const path = require("path"); | ||
const glob = require("glob"); | ||
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); | ||
const PurgecssPlugin = require("../../../src").default; | ||
|
||
const PATHS = { | ||
src: path.join(__dirname, "src"), | ||
}; | ||
|
||
module.exports = { | ||
mode: "development", | ||
entry: "./src/index.js", | ||
context: path.resolve(__dirname), | ||
optimization: { | ||
splitChunks: { | ||
cacheGroups: { | ||
styles: { | ||
name: "styles", | ||
type: "css/mini-extract", | ||
test: /\.css$/, | ||
chunks: "all", | ||
enforce: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/, | ||
use: [MiniCssExtractPlugin.loader, "css-loader"], | ||
}, | ||
], | ||
}, | ||
plugins: [ | ||
new MiniCssExtractPlugin({ | ||
filename: "[name].css", | ||
}), | ||
new PurgecssPlugin({ | ||
paths: () => glob.sync(`${PATHS.src}/*`), | ||
rejectedCss: "[base].rejected.css", | ||
}), | ||
], | ||
}; |
5 changes: 5 additions & 0 deletions
5
packages/purgecss-webpack-plugin/__tests__/cases/rejected-css/expected/styles-rejected.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
|
||
.rejected { | ||
color: blue; | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/purgecss-webpack-plugin/__tests__/cases/rejected-css/src/content.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<html> | ||
|
||
<head> | ||
<title>Purgecss webpack test</title> | ||
</head> | ||
|
||
<body> | ||
<div class="preserved"></div> | ||
</body> | ||
|
||
</html> |
1 change: 1 addition & 0 deletions
1
packages/purgecss-webpack-plugin/__tests__/cases/rejected-css/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import "./style.css"; |
8 changes: 8 additions & 0 deletions
8
packages/purgecss-webpack-plugin/__tests__/cases/rejected-css/src/style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
.preserved { | ||
color: red; | ||
} | ||
|
||
.rejected { | ||
color: blue; | ||
} |
44 changes: 44 additions & 0 deletions
44
packages/purgecss-webpack-plugin/__tests__/cases/rejected-css/webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const path = require("path"); | ||
const glob = require("glob"); | ||
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); | ||
const PurgecssPlugin = require("../../../src").default; | ||
|
||
const PATHS = { | ||
src: path.join(__dirname, "src"), | ||
}; | ||
|
||
module.exports = { | ||
mode: "development", | ||
entry: "./src/index.js", | ||
context: path.resolve(__dirname), | ||
optimization: { | ||
splitChunks: { | ||
cacheGroups: { | ||
styles: { | ||
name: "styles", | ||
type: "css/mini-extract", | ||
test: /\.css$/, | ||
chunks: "all", | ||
enforce: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/, | ||
use: [MiniCssExtractPlugin.loader, "css-loader"], | ||
}, | ||
], | ||
}, | ||
plugins: [ | ||
new MiniCssExtractPlugin({ | ||
filename: "[name].css", | ||
}), | ||
new PurgecssPlugin({ | ||
paths: () => glob.sync(`${PATHS.src}/*`), | ||
rejectedCss: true, | ||
}), | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how complicated it would be, but I imagine it would be more webpack friendly if it uses their template string configuration options.
So it would allow for something like: