How to combine multiple CSS files into a single output file?
In SASS, this was done in a SCSS file by adding in other SCSS files via the @use method.
I have found that this can be done by adding in package.json itself with "cat" to concatenate files from a directory. However I'd like more control than that. I want to specify which files, in which order and perhaps have more than one output file for different sets of inputs.
Is there something I could add to module.exports that would allow me to list input and output files or something like that?
{
"name": "postcss-boo",
"version": "1.0.0",
"description": "PostCSS configuration for BOO",
"main": "index.js",
"scripts": {
"build:css": "postcss src/root.css --dir dist",
"concat:css": "cat src/* > src/all.css",
"watch:css": "postcss src/root.css --dir dist --w"
},
"keywords": [],
"author": "BOO",
"license": "ISC",
"devDependencies": {
"autoprefixer": "^10.4.21",
"cross-env": "^10.0.0",
"cssnano": "^7.1.1",
"postcss": "^8.5.6",
"postcss-cli": "^11.0.1",
"postcss-preset-env": "^10.3.0",
}
}
Config:
const postcssPresetEnv = require("postcss-preset-env");
const postcssSortMediaQueries = require("postcss-sort-media-queries");
const cssNano = require("cssnano");
module.exports = {
plugins: [
postcssPresetEnv({ stage: 1 }),
cssNano(),
],
};
@import- npmjs.com/package/postcss-import, developer.mozilla.org/en-US/docs/Web/CSS/@import . Basically create a file that imports other styles. You can customize the import order and select which files to import that way. And use the postcss-import plugin that will inline those imports the specified order.@importis a pretty standard way. It's similar on lightningcss too (lightningcss.dev/bundling.html), and other plugins also exist for postcss - github.com/csstools/postcss-plugins/tree/main/plugin-packs/… which also use@import.npm run build)