-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Conversation
|
07160d3
to
20b9d3c
Compare
Thanks. FWIW, after #6379 lands, this will need to be refactored to move the config loading into the plugin's |
e74fb69
to
bb6c569
Compare
Do you mean this? diff --git a/packages/optimizers/cssnano/src/CSSNanoOptimizer.js b/packages/optimizers/cssnano/src/CSSNanoOptimizer.js
index bb96edebb..1ff1a250f 100644
--- a/packages/optimizers/cssnano/src/CSSNanoOptimizer.js
+++ b/packages/optimizers/cssnano/src/CSSNanoOptimizer.js
@@ -9,11 +9,21 @@ import {loadConfig} from '@parcel/utils';
import path from 'path';
export default (new Optimizer({
+ async loadConfig({ options }) {
+ return ((await loadConfig(
+ options.inputFS,
+ path.join(options.entryRoot, 'index.css'),
+ ['.cssnanorc ', 'cssnano.config.json', 'cssnano.config.js'],
+ options.projectRoot,
+ )) ?? {}: CSSNanoOptions);
+ }
+
async optimize({
bundle,
contents: prevContents,
getSourceMapReference,
map: prevMap,
+ config,
options,
}) {
if (!bundle.env.shouldOptimize) {
@@ -26,14 +36,7 @@ export default (new Optimizer({
);
}
- const userConfig = ((await loadConfig(
- options.inputFS,
- path.join(options.entryRoot, 'index.css'),
- ['.cssnanorc ', 'cssnano.config.json', 'cssnano.config.js'],
- options.projectRoot,
- )) ?? {}: CSSNanoOptions);
-
+ const result = await postcss([cssnano(config)]).process(prevContents, {
// Suppress postcss's warning about a missing `from` property. In this
// case, the input map contains all of the sources.
from: undefined, |
Almost, use |
So this one: ❯ git diff
diff --git a/packages/optimizers/cssnano/package.json b/packages/optimizers/cssnano/package.json
index 597fe8cbf..44a02c47c 100644
--- a/packages/optimizers/cssnano/package.json
+++ b/packages/optimizers/cssnano/package.json
@@ -22,7 +22,6 @@
"dependencies": {
"@parcel/plugin": "2.0.0-beta.3.1",
"@parcel/source-map": "2.0.0-rc.4",
- "@parcel/utils": "2.0.0-beta.3.1",
"cssnano": "^5.0.5",
"postcss": "^8.3.0"
}
diff --git a/packages/optimizers/cssnano/src/CSSNanoOptimizer.js b/packages/optimizers/cssnano/src/CSSNanoOptimizer.js
index bb96edebb..b2ed83fa6 100644
--- a/packages/optimizers/cssnano/src/CSSNanoOptimizer.js
+++ b/packages/optimizers/cssnano/src/CSSNanoOptimizer.js
@@ -5,15 +5,22 @@ 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 {loadConfig} from '@parcel/utils';
import path from 'path';
export default (new Optimizer({
+ async loadConfig({ config, options }) {
+ return ((await config.getConfigFrom(
+ path.join(options.entryRoot, 'index.css'),
+ ['.cssnanorc', 'cssnano.config.json', 'cssnano.config.js'],
+ )) ?? {}: CSSNanoOptions);
+ },
+
async optimize({
bundle,
contents: prevContents,
getSourceMapReference,
map: prevMap,
+ config,
options,
}) {
if (!bundle.env.shouldOptimize) {
@@ -26,14 +33,7 @@ export default (new Optimizer({
);
}
- const userConfig = ((await loadConfig(
- options.inputFS,
- path.join(options.entryRoot, 'index.css'),
- ['.cssnanorc ', 'cssnano.config.json', 'cssnano.config.js'],
- options.projectRoot,
- )) ?? {}: CSSNanoOptions);
-
+ const result = await postcss([cssnano(config)]).process(prevContents, {
// Suppress postcss's warning about a missing `from` property. In this
// case, the input map contains all of the sources.
from: undefined, |
Yes. And you should also remove the space in |
Actually, you need to do call parcel/packages/packagers/js/src/index.js Line 21 in 1ba0bd1
Flow should also already be complaining about that |
Well, Flow complains about other things too. |
549f99f
to
2753d41
Compare
2753d41
to
bf02014
Compare
😄 My branch was out of date. |
8ad793c
to
1dfccab
Compare
↪️ Pull Request
Fixes #1721
Already fixed. Closes #6102
💻 Examples
🚨 Test instructions
Install cssnano-preset-advanced, then make the following file at the project root.
cssnano.config.js
Build and pack this cssnano package, then install it in your project. Using pnpm you can simply do this in your package.json
✔️ PR Todo