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
Recover reject css with webpack plugin #819
Conversation
The |
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.
You should also make sure the src/types/index.ts
are updated correctly as these will provide proper code completion when using the plugin
Just add the option in the appropriate interface like:
export interface UserDefinedOptions {
// ...
output?: string;
rejected?: boolean;
rejectedCss?: boolean;
// ...
}
@@ -136,6 +136,10 @@ new PurgeCSSPlugin({ | |||
|
|||
If `true` all removed selectors are added to the [Stats Data](https://webpack.js.org/api/stats/) as `purged`. | |||
|
|||
* #### rejectedCss |
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:
const options = {
output: '[name].rejected.[ext]'
}
@@ -127,7 +128,17 @@ export default class PurgeCSSPlugin { | |||
|
|||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | |||
// @ts-ignore | |||
compilation.updateAsset(name, new ConcatSource(purged.css)); | |||
let source: Source = new ConcatSource(purged.css) |
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.
Any reason why you are re-using the source
variable? I would suggest something more in the original style like:
compilation.updateAsset(name, new ConcatSource(purged.css));
if (purged.rejectedCss !== undefined) {
const rejectedName = path.dirname(name) + '/' + path.basename(name, '.css') + '-rejected' + path.extname(name);
const source = new ConcatSource(purged.rejectedCss);
if (compilation.getAsset(rejectedName) {
compilation.emitAsset(rejectedName, source);
} else {
compilation.updateAsset(rejectedName, source);
}
}
Some minor nitpick would be to maintain consistent with use of semi-colons in the file.
This PR is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
@Quidam74 Is there any interest in closing this issue? If so please review my PR to your fork so we can revisit this PR. |
hi there, Sorry for the long time afk. i don't understand what you want me to do, not used to work with forks. You want me to merge your pull request on my fork ? in this place : Quidam74#2 ? |
@Quidam74 Well I just realized I made a PR on your main branch, and not the feature branch. I will have to change the branch and check the changes first. But after that yes, if you could merge my PR then this feature would be ready for |
@Quidam74 I checked it and it seems good. What it does is add test coverage and allows for naming the output file (with your |
…lugin-webpackOutputPathTemplate Recover reject css with webpack plugin webpack output path template
Done ! thank you for your help ! |
This PR is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
Proposed changes
Recover purged css in separete css file for webpack plugin.
see #816 and #763.
Types of changes
What types of changes does your code introduce?
Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.Further comments
First time for me and my coworker (@Firologame) working on a public repo. Also discovering how webpack plugin work and first contact with typescript. We don't know how to create tests, but our developement didn't create any error on the existing tests. Please be gentle !
Feel free to upgrade those few changes and give us feedback, thank you for your attention !