Y
Y
yeco2021-12-12 18:26:52
Web development
yeco, 2021-12-12 18:26:52

Is it possible to use cssNano as a function and not as a plugin?

Hello, I want to use cssNano to optimize css, but as a function, pass unoptimized css to the function, get optimized.
In the documentation I found
https://cssnano.co/docs/config-file

import postcss from "postcss";
import cssnano from "cssnano";
import litePreset from "cssnano-preset-lite";
import autoprefixer from "autoprefixer";
const preset = litePreset({ discardComments: false });

let aftercssnano = postcss([
    cssnano({ preset, plugins: [autoprefixer] }),
  ]).process("<style>.notoptimizedhere{background: green;}</style>");
  console.log(aftercssnano);

But
import postcss from "postcss";
^^^^^^

SyntaxError: Cannot use import statement outside a module

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question