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

Allow configuring cssnano #6422

Merged
merged 11 commits into from
Jun 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
5 changes: 3 additions & 2 deletions flow-libs/cssnano.js.flow
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// @flow strict-local

// Derived from the source of cssnano located at
// Modified from the source of cssnano located at
// https://github.com/cssnano/cssnano and its types at
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/cssnano/index.d.ts

declare module 'cssnano' {
import type { Plugin } from "postcss"
declare interface CSSNanoOptions {
configFile?: string;
preset?: [string, mixed] | string;
}
declare module.exports: (?CSSNanoOptions) => void;
declare module.exports: (?CSSNanoOptions) => Plugin;
aminya marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 1 addition & 1 deletion packages/core/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"nib": "^1.1.2",
"node-elm-compiler": "^5.0.5",
"parcel": "2.0.0-beta.3.1",
"postcss": "^8.2.1",
"postcss": "^8.3.0",
"postcss-custom-properties": "^11.0.0",
"postcss-import": "^14.0.2",
"posthtml-include": "^1.5.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/optimizers/cssnano/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@parcel/plugin": "2.0.0-beta.3.1",
"@parcel/source-map": "2.0.0-rc.4",
"cssnano": "^5.0.3",
"postcss": "^8.0.5"
"cssnano": "^5.0.5",
"postcss": "^8.3.0"
}
}
23 changes: 22 additions & 1 deletion packages/optimizers/cssnano/src/CSSNanoOptimizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,32 @@ import SourceMap from '@parcel/source-map';
import {Optimizer} from '@parcel/plugin';
import postcss from 'postcss';
import cssnano from 'cssnano';
import type {CSSNanoOptions} from 'cssnano'; // TODO the type is based on cssnano 4
import path from 'path';

export default (new Optimizer({
async loadConfig({config}) {
const configFile = await config.getConfig(
['.cssnanorc', 'cssnano.config.json', 'cssnano.config.js'],
{
packageKey: 'cssnano',
},
);
if (configFile) {
let isJavascript = path.extname(configFile.filePath) === '.js';
if (isJavascript) {
config.shouldInvalidateOnStartup();
}
config.setResult(configFile.contents);
}
},

async optimize({
bundle,
contents: prevContents,
getSourceMapReference,
map: prevMap,
config,
options,
}) {
if (!bundle.env.shouldOptimize) {
Expand All @@ -23,7 +42,9 @@ export default (new Optimizer({
);
}

const result = await postcss([cssnano]).process(prevContents, {
const result = await postcss([
cssnano((config ?? {}: CSSNanoOptions)),
]).process(prevContents, {
// Suppress postcss's warning about a missing `from` property. In this
// case, the input map contains all of the sources.
from: undefined,
Expand Down
2 changes: 1 addition & 1 deletion packages/packagers/css/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"@parcel/source-map": "2.0.0-rc.4",
"@parcel/utils": "2.0.0-beta.3.1",
"nullthrows": "^1.1.1",
"postcss": "^8.2.1"
"postcss": "^8.3.0"
}
}
2 changes: 1 addition & 1 deletion packages/transformers/css/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@parcel/source-map": "2.0.0-rc.4",
"@parcel/utils": "2.0.0-beta.3.1",
"nullthrows": "^1.1.1",
"postcss": "^8.2.1",
"postcss": "^8.3.0",
"postcss-value-parser": "^4.1.0",
"semver": "^5.4.1"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/transformers/postcss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
"semver": "^5.4.1"
},
"devDependencies": {
"postcss": "^8.2.1"
"postcss": "^8.3.0"
}
}
2 changes: 1 addition & 1 deletion packages/transformers/sugarss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"dependencies": {
"@parcel/plugin": "2.0.0-beta.3.1",
"postcss": "^8.0.5",
"postcss": "^8.3.0",
"sugarss": "^3.0.3"
}
}
98 changes: 95 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3290,7 +3290,7 @@ browserify-zlib@^0.2.0:
dependencies:
pako "~1.0.5"

browserslist@^4.0.0, browserslist@^4.14.5, browserslist@^4.16.0, browserslist@^4.16.3, browserslist@^4.6.6:
browserslist@^4.0.0, browserslist@^4.14.5, browserslist@^4.16.0, browserslist@^4.16.3, browserslist@^4.16.6, browserslist@^4.6.6:
version "4.16.6"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.16.6.tgz#d7901277a5a88e554ed305b183ec9b0c08f66fa2"
integrity sha512-Wspk/PqO+4W9qp5iUTJsa1B/QrYn1keNCcEP5OvP7WBwT4KaDly0uONYmC6Xa3Z5IqnUgS0KcgLYu1l74x0ZXQ==
Expand Down Expand Up @@ -3857,6 +3857,11 @@ colord@^1.7.0:
resolved "https://registry.yarnpkg.com/colord/-/colord-1.7.2.tgz#474f0e46333cb5c7a191dbd571edeee19a5f97b6"
integrity sha512-/sQCxy6PEhZbrAn1+NVRRefy3k4jkWQGxk7mo2o0CoNA24jq4ujDc2jXzJ5uXphm/TwfdGOP0w8U+H+9ys4Peg==

colord@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/colord/-/colord-2.0.1.tgz#1e7fb1f9fa1cf74f42c58cb9c20320bab8435aa0"
integrity sha512-vm5YpaWamD0Ov6TSG0GGmUIwstrWcfKQV/h2CmbR7PbNu41+qdB5PW9lpzhjedrpm08uuYvcXi0Oel1RLZIJuA==

colorette@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.2.2.tgz#cbcc79d5e99caea2dbf10eb3a26fd8b3e6acfa94"
Expand Down Expand Up @@ -4420,12 +4425,47 @@ cssnano-preset-default@^5.1.0:
postcss-svgo "^5.0.1"
postcss-unique-selectors "^5.0.1"

cssnano-preset-default@^5.1.2:
version "5.1.2"
resolved "https://registry.yarnpkg.com/cssnano-preset-default/-/cssnano-preset-default-5.1.2.tgz#5d4877a91769823c5da6bcebd54996ecdf8aca12"
integrity sha512-spilp8LRw0sacuxiN9A/dyyPr6G/WISKMBKcBD4NMoPV0ENx4DeuWvIIrSx9PII2nJIDCO3kywkqTPreECBVOg==
dependencies:
css-declaration-sorter "^6.0.3"
cssnano-utils "^2.0.1"
postcss-calc "^8.0.0"
postcss-colormin "^5.2.0"
postcss-convert-values "^5.0.1"
postcss-discard-comments "^5.0.1"
postcss-discard-duplicates "^5.0.1"
postcss-discard-empty "^5.0.1"
postcss-discard-overridden "^5.0.1"
postcss-merge-longhand "^5.0.2"
postcss-merge-rules "^5.0.2"
postcss-minify-font-values "^5.0.1"
postcss-minify-gradients "^5.0.1"
postcss-minify-params "^5.0.1"
postcss-minify-selectors "^5.1.0"
postcss-normalize-charset "^5.0.1"
postcss-normalize-display-values "^5.0.1"
postcss-normalize-positions "^5.0.1"
postcss-normalize-repeat-style "^5.0.1"
postcss-normalize-string "^5.0.1"
postcss-normalize-timing-functions "^5.0.1"
postcss-normalize-unicode "^5.0.1"
postcss-normalize-url "^5.0.1"
postcss-normalize-whitespace "^5.0.1"
postcss-ordered-values "^5.0.1"
postcss-reduce-initial "^5.0.1"
postcss-reduce-transforms "^5.0.1"
postcss-svgo "^5.0.2"
postcss-unique-selectors "^5.0.1"

cssnano-utils@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/cssnano-utils/-/cssnano-utils-2.0.1.tgz#8660aa2b37ed869d2e2f22918196a9a8b6498ce2"
integrity sha512-i8vLRZTnEH9ubIyfdZCAdIdgnHAUeQeByEeQ2I7oTilvP9oHO6RScpeq3GsFUVqeB8uZgOQ9pw8utofNn32hhQ==

cssnano@^5.0.0, cssnano@^5.0.3:
cssnano@^5.0.0:
version "5.0.3"
resolved "https://registry.yarnpkg.com/cssnano/-/cssnano-5.0.3.tgz#3ae26411a176168e7a0ef425f4691579e1aed12a"
integrity sha512-Ga/a+IA6U0F9+MNmqrXgwn1A3btY5jFkla2iurL7i9PTmQmMu2Kc99W9a8KSxT8iLV0aoI+Q5Q9i3SpVAVNnrQ==
Expand All @@ -4434,6 +4474,15 @@ cssnano@^5.0.0, cssnano@^5.0.3:
cssnano-preset-default "^5.1.0"
is-resolvable "^1.1.0"

cssnano@^5.0.5:
version "5.0.5"
resolved "https://registry.yarnpkg.com/cssnano/-/cssnano-5.0.5.tgz#6b8787123bf4cd5a220a2fa6cb5bc036b0854b48"
integrity sha512-L2VtPXnq6rmcMC9vkBOP131sZu3ccRQI27ejKZdmQiPDpUlFkUbpXHgKN+cibeO1U4PItxVZp1zTIn5dHsXoyg==
dependencies:
cosmiconfig "^7.0.0"
cssnano-preset-default "^5.1.2"
is-resolvable "^1.1.0"

csso@^4.0.2, csso@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/csso/-/csso-4.2.0.tgz#ea3a561346e8dc9f546d6febedd50187cf389529"
Expand Down Expand Up @@ -9987,6 +10036,16 @@ postcss-colormin@^5.1.0:
colord "^1.7.0"
postcss-value-parser "^4.1.0"

postcss-colormin@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/postcss-colormin/-/postcss-colormin-5.2.0.tgz#2b620b88c0ff19683f3349f4cf9e24ebdafb2c88"
integrity sha512-+HC6GfWU3upe5/mqmxuqYZ9B2Wl4lcoUUNkoaX59nEWV4EtADCMiBqui111Bu8R8IvaZTmqmxrqOAqjbHIwXPw==
dependencies:
browserslist "^4.16.6"
caniuse-api "^3.0.0"
colord "^2.0.1"
postcss-value-parser "^4.1.0"

postcss-convert-values@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/postcss-convert-values/-/postcss-convert-values-5.0.1.tgz#4ec19d6016534e30e3102fdf414e753398645232"
Expand Down Expand Up @@ -10050,6 +10109,17 @@ postcss-merge-rules@^5.0.1:
postcss-selector-parser "^6.0.5"
vendors "^1.0.3"

postcss-merge-rules@^5.0.2:
version "5.0.2"
resolved "https://registry.yarnpkg.com/postcss-merge-rules/-/postcss-merge-rules-5.0.2.tgz#d6e4d65018badbdb7dcc789c4f39b941305d410a"
integrity sha512-5K+Md7S3GwBewfB4rjDeol6V/RZ8S+v4B66Zk2gChRqLTCC8yjnHQ601omj9TKftS19OPGqZ/XzoqpzNQQLwbg==
dependencies:
browserslist "^4.16.6"
caniuse-api "^3.0.0"
cssnano-utils "^2.0.1"
postcss-selector-parser "^6.0.5"
vendors "^1.0.3"

postcss-minify-font-values@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/postcss-minify-font-values/-/postcss-minify-font-values-5.0.1.tgz#a90cefbfdaa075bd3dbaa1b33588bb4dc268addf"
Expand Down Expand Up @@ -10280,6 +10350,14 @@ postcss-svgo@^5.0.1:
postcss-value-parser "^4.1.0"
svgo "^2.3.0"

postcss-svgo@^5.0.2:
version "5.0.2"
resolved "https://registry.yarnpkg.com/postcss-svgo/-/postcss-svgo-5.0.2.tgz#bc73c4ea4c5a80fbd4b45e29042c34ceffb9257f"
integrity sha512-YzQuFLZu3U3aheizD+B1joQ94vzPfE6BNUcSYuceNxlVnKKsOtdo6hL9/zyC168Q8EwfLSgaDSalsUGa9f2C0A==
dependencies:
postcss-value-parser "^4.1.0"
svgo "^2.3.0"

postcss-unique-selectors@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/postcss-unique-selectors/-/postcss-unique-selectors-5.0.1.tgz#3be5c1d7363352eff838bd62b0b07a0abad43bfc"
Expand Down Expand Up @@ -10330,7 +10408,7 @@ postcss@^7.0.14, postcss@^7.0.17, postcss@^7.0.32, postcss@^7.0.5, postcss@^7.0.
source-map "^0.6.1"
supports-color "^6.1.0"

postcss@^8.0.5, postcss@^8.1.6, postcss@^8.2.1, postcss@^8.2.9:
postcss@^8.1.6, postcss@^8.2.1, postcss@^8.2.9:
version "8.2.15"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.2.15.tgz#9e66ccf07292817d226fc315cbbf9bc148fbca65"
integrity sha512-2zO3b26eJD/8rb106Qu2o7Qgg52ND5HPjcyQiK2B98O388h43A448LCslC0dI2P97wCAQRJsFvwTRcXxTKds+Q==
Expand All @@ -10339,6 +10417,15 @@ postcss@^8.0.5, postcss@^8.1.6, postcss@^8.2.1, postcss@^8.2.9:
nanoid "^3.1.23"
source-map "^0.6.1"

postcss@^8.3.0:
version "8.3.0"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.3.0.tgz#b1a713f6172ca427e3f05ef1303de8b65683325f"
integrity sha512-+ogXpdAjWGa+fdYY5BQ96V/6tAo+TdSSIMP5huJBIygdWwKtVoB5JWZ7yUd4xZ8r+8Kvvx4nyg/PQ071H4UtcQ==
dependencies:
colorette "^1.2.2"
nanoid "^3.1.23"
source-map-js "^0.6.2"

posthtml-expressions@^1.6.0:
version "1.7.1"
resolved "https://registry.yarnpkg.com/posthtml-expressions/-/posthtml-expressions-1.7.1.tgz#b62b47a9c2cc8216cbbb07d2e9e7b293f3c1f5bc"
Expand Down Expand Up @@ -11872,6 +11959,11 @@ sort-keys@^2.0.0:
dependencies:
is-plain-obj "^1.0.0"

source-map-js@^0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-0.6.2.tgz#0bb5de631b41cfbda6cfba8bd05a80efdfd2385e"
integrity sha512-/3GptzWzu0+0MBQFrDKzw/DvvMTUORvgY6k6jd/VS6iCR4RDTKWH6v6WPwQoUO8667uQEf9Oe38DxAYWY5F/Ug==

source-map-resolve@^0.5.0, source-map-resolve@^0.5.2:
version "0.5.3"
resolved "https://registry.yarnpkg.com/source-map-resolve/-/source-map-resolve-0.5.3.tgz#190866bece7553e1f8f267a2ee82c606b5509a1a"
Expand Down