Guide on running CSSO command line CSS minifier in node.js

I have been attempting to utilize the CSSO command-line tool with node.js.

Unfortunately, I am struggling to figure out how to simply call the csso command.

You can find CSSO's documentation on this page: https://github.com/css/csso#33-from-the-command-line

I followed the steps on the documentation page to download CSSO using NPM. It is already installed as I can use

require("csso").justDoIt(".....")
, but that method does not work for me. I need to execute it in a command line because I require this CSS minifier during some Visual Studio build process.


Please note that using another compressor is not a solution. I have tried YUI, AjaxMin, and others with command-line interfaces, but they do not merge duplicated classes, identifiers, and selectors into a single one.

Thank you in advance!!!

Answer №1

If you need to make adjustments to the csso file located in the bin folder, you can simply modify the /csso/lib/csso.js file. You could potentially work around it by using a command like:

node /path/to/csso/lib/csso.js -i -o

This code hasn't been tested, so you may need to tweak some variables to get it working properly. However, this should give you a starting point for finding a solution!

Answer №2

Utilize node's child process

var spawn = require('child_process').spawn,
csso  = spawn('csso/bin/csso', ['test.css']);

csso.stdout.on('data', function (data) {
  console.log('stdout: ' + data);
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Updating documents with Mongoose's Modle.update() method leads to incorrect updates and triggers a Cast

Could use some assistance clarifying a few things. I'm working with the following Model: var Event = new Schema({ event_code: String , segments: [Segment] }); The creation of new documents is flawless. However, running into issues when updating ...

Querying for geographic points within a specified radius using Mongoose

While attempting to find geo points within a certain radius, I came across a tutorial that explains how to do it. The tutorial includes the following snippet: To begin, we need to create a schema. The documentation provides examples on how to store geosp ...

Errors in autocomplete within eslint-config-react-app for 'react/cjs/react.development'

Context In a basic ReactJS project, I aimed to enhance its functionality by incorporating ESLint capabilities: npm install --save-dev eslint-config-react-app eslint@^8.0.0 Here is the modified package.json after integrating ESLint: { "name": ...

"Is there a way to display a pop-up window instead of redirecting to Facebook

I found a helpful guide on passportjs.org for authenticating users through Facebook. However, instead of redirecting to the Facebook site, I am looking to display a popup window for authentication. Any suggestions on how to accomplish this? ...

Commands for Yarn, such as type checking, testing, and formatting with Prettier, are encountering

I have been encountering errors in my Jenkins builds for the past 3 weeks. Despite numerous attempts, I cannot seem to get these commands to work within the Jenkins pipeline code using our shared libraries. The same commands work fine locally. The errors ...

The array initially provides accurate values, however, upon subsequent calls, it inexplicably returns all values as "undefined"

After successfully reading a bunch of JSON files and storing them into an array, I encountered a strange issue. When I console logged the array initially, all the values were correct. However, upon rendering a page and logging the array again, all values ...

How to fix the problem with return values in NodeJS (Express) and Eslint?

const checkAuthorization = function(request, response, next) { const token = request.headers.authorization; if (!token) { return response.status(401).json({ message: 'Invalid or missing token' }); } const accessToken = token.split(&a ...

Creating custom interactions for pact-js-mocha that simulate error responses

I've been working on the pact-js-mocha example and I'm facing some challenges when it comes to verifying an interaction where the expected response is an error. The specific interaction I need to verify is as follows: PactConsumer(PactOpts, func ...

Is redirecting the user after authentication possible? The replace function is not available for use

I am working on implementing user authentication before displaying the home page in my react app. Many tutorials suggest using a "replace" method within react-router, but I keep encountering errors that say replace is not a function. Below is my code snip ...

Develop a CakePHP CRUD view using a JavaScript framework

Creating a CRUD view in Cake PHP is simple with the following command: bin/cake bake all users This command builds the users table for CRUD operations. Is there a JavaScript framework that offers similar simplicity? ...

What's the deal with Mongoose and preloading data?

There is an issue I am facing with regards to retrieving a document from mongodb. In my node.js server configuration, I have the following call: app.get('/ruimtes/:afkortingCampus', function (req, res) { Ruimtes.find({'campusAfkorting&apo ...

The reason for the failure of npm install in Express.js is due to an issue with getaddrinfo E

For the past two years, I have been running a Node.JS / Express.JS server-side program inside a Node.JS docker container without any issues. However, recently upon installation, it started throwing a strange error. I typically use docker-compose to install ...

The unexpected error occurs when using JSON.parse() with the message 'Unexpected end of JSON input'

The output produced by console.log(d) is in hexadecimal code: <Buffer 7b 22 73 75 63 63 65 73 73 22 3a 74 72 75 65 2c 22 64 61 74 61 22 3a 7b 22 73 75 6d 6d 61 72 79 22 3a 7b 22 74 6f 74 61 6c 22 3a 31 39 39 32 35 36 30 ... 293 more bytes> <Buff ...

Is it feasible to generate emojis using a gulp Icon-font task?

I'm in the process of creating a script that can generate fonts from SVG images, and so far it's been successful (using similar code to what's provided on https://www.npmjs.com/package/gulp-iconfont) Now I have a more specific question - is ...

Creating a parameter/wildcard within an npm script's key or name

I have a package.json file that looks like this: { "name": "example", "version": "1.0.0", "description": "example", (...) "scripts": { "something:special": "script-that-does-something.sh", (...) }, (...) } The script script-that ...

Scraping data from a webpage using Node.js and the Document Object Model

I am attempting to extract information from a specific website using Node.js. Despite my best efforts, I have not made much progress in achieving this task. My goal is to retrieve a magnet URI link which is located within the following HTML structure: < ...

combine two separate typescript declaration files into a single package

Can anyone help me figure out how to merge two typescript definition packages, @types/package-a and @types/package-b, into one definition package? package-a.d.ts [export package-a {...}] package-b.d.ts [exports package-b {...}] package-mine.d.ts [ export ...

Replace a data value in a JSON file with a value from a different JSON file

I have a task involving two JSON files known as data.json and values.json. My goal is to extract the values of aws and bucket from values.json and incorporate them into data.json using node js. How can I achieve this functionality? Currently, I have devel ...

Fetching the exchanged messages between the sender and recipient - utilizing MongoDB, Express, and React for chat functionality

I am dealing with two collections named students and teachers in the mongodb database. The structure of a conversation between a student and a teacher involves arrays of messages within each object, as well as the IDs of the sender and receiver. I am seeki ...

When Express serves a React build, the webpage displays as blank

My current project structure looks like this: app server.js frontend build index.html The build directory is the result of running npm run build in my React app (created using create-react-app). There are additional files but I will exclude them ...