Skip to content

Commit

Permalink
Allow configuring cssnano
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jun 7, 2021
1 parent c06a16e commit 07160d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/optimizers/cssnano/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"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"
}
Expand Down
11 changes: 10 additions & 1 deletion packages/optimizers/cssnano/src/CSSNanoOptimizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import SourceMap from '@parcel/source-map';
import {Optimizer} from '@parcel/plugin';
import postcss from 'postcss';
import cssnano from 'cssnano';
import {loadConfig} from '@parcel/utils';
import path from 'path';

export default (new Optimizer({
async optimize({
Expand All @@ -23,7 +25,14 @@ export default (new Optimizer({
);
}

const result = await postcss([cssnano]).process(prevContents, {
const userConfig = await loadConfig(
options.inputFS,
path.join(options.entryRoot, 'index'),
['.cssnanorc ', 'cssnano.config.json', 'cssnano.config.js'],
options.projectRoot,
);

const result = await postcss([cssnano(userConfig)]).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

0 comments on commit 07160d3

Please sign in to comment.