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

refactor: update to cssnano 5. #357

Merged
merged 1 commit into from
Aug 12, 2021
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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"jest": "^26.6.3",
"less": "^3.12.2",
"node-sass": "^5.0.0",
"postcss": "^8.1.14",
"postcss": "^8.2.7",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update to enforce at least version 8.2.10 to avoid vulnerability as per https://www.npmjs.com/advisories/1693

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not make much difference as the ^ in front of the version number should let you update to the latest postcss version anyway. In any case it would be better to do it in a separate PR since this one also updates cssnano which is potentially more breaking than bumping postcss version.

"rollup": "^2.34.2",
"stylus": "^0.54.8",
"sugarss": "^3.0.3",
Expand All @@ -53,7 +53,7 @@
"dependencies": {
"chalk": "^4.1.0",
"concat-with-sourcemaps": "^1.1.0",
"cssnano": "^4.1.10",
"cssnano": "^5.0.1",
"import-cwd": "^3.0.0",
"p-queue": "^6.6.2",
"pify": "^5.0.0",
Expand Down Expand Up @@ -103,4 +103,4 @@
"next"
]
}
}
}
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export default (options = {}) => {
let { code, codeFileName, map, mapFileName } = getExtracted()
// Perform cssnano on the extracted file
if (postcssLoaderOptions.minimize) {
const cssOptions = postcssLoaderOptions.minimize
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the README (https://github.com/egoist/rollup-plugin-postcss#minimize) minimize can be boolean. In that case, I don't think the current code sets PostCSS options correctly.

const cssOptions = {}
cssOptions.from = codeFileName
if (sourceMap === 'inline') {
cssOptions.map = { inline: true }
Expand All @@ -233,7 +233,7 @@ export default (options = {}) => {
cssOptions.to = codeFileName
}

const result = await require('cssnano').process(code, cssOptions)
const result = await require('cssnano')(postcssLoaderOptions.minimize).process(code, cssOptions)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With cssnano 5, you need to call cssnano(), pass cssnano specific options to it. This returns a normal PostCSS processor, which you then call to process the CSS.

code = result.css

if (sourceMap === true && result.map && result.map.toString) {
Expand Down
Loading