Executing cssnano Using the Command Prompt

Although I'm not an expert in node JS, I have come across cssnano as a JavaScript tool for minifying CSS, which apparently does a more sophisticated job compared to the outdated YUI compressor. My only issue is that I am struggling to understand how to use this tool on individual files like I can with the YUI compressor.

The command I'm familiar with looks like this

java -jar compilers\yuicompressor-2.4.7.jar --type=css --line-break=2048  infile.css -o "outfile.css"

This process is straightforward because I have a custom tool that runs through all my CSS files and applies this command to each one. However, I haven't been able to figure out how to swap out YUI with cssnano to achieve the same outcome.

Answer №1

Finally cracked the code.

I had to come up with a solution by creating a separate .js file and storing this piece of code:

const cssOptimize = require('css-optimizer');
const fs = require('fs');

cssOptimize.minify(fs.readFileSync(process.argv[2])).then(function (result) {
  fs.writeFileSync(process.argv[3], result);
});

After that, I executed it through the command line using:

node scripts\optimizecss.js input.css "output.css"

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

Should API calls be made from the frontend or the backend of the application?

Situation: I am managing a Node and Angular web application that requires data from an external API (a third-party service), specifically here: . Query: Is it more advisable to make the external call directly from the Angular frontend using GET http://thi ...

Tips for dynamically displaying images in both horizontal and vertical orientations

I would like to showcase images in the imageList. Here is what I want: AB CD How can this be achieved? It's not a matter of being even or odd Perhaps the list could look something like this: ABCDE FG I simply want a new row or display:block when ...

I can't seem to shake off this constant error. Uncaught TypeError: Unable to access property 'classList' of null

I am facing an issue with the "Contact Me" tab as it does not display its content when clicked. Here is the code snippet: <body> <ul class="tabs"> <li data-tab-target="#home" class="active tab">Home< ...

Executing Ionic, npm, and Cordova commands necessitates the use of sudo for proper functioning

After browsing through some forums, it seems like the use of "sudo" is causing an error for me when I try to run sudo ionic emulate ios. This issue was discussed in this post on Stack Overflow: New to ionic - can’t build for ios (9) on El Capitan, and su ...

Having trouble running tests on the Express.js server

I'm struggling to run basic tests on my expressjs server and close it immediately. I have exported the server as a promise, but can't seem to figure out how to achieve this. Below is the code for my server file : index.js const config = require( ...

Transferring information from the backend (powered by nodejs) to the frontend using JavaScript

I have data stored in my MongoDB database and I am retrieving this data from the DB to save it to an array. When a button is clicked on the webpage, I want to send this data to my JavaScript file and use the DOM to display it on the page. On page load, I ...

Sending a parameter from a Pug template to JSX

I am currently in the process of developing a game using Express and React. My main challenge lies in accessing the userId within my index.jsx file to execute certain actions on my controllers, such as increasing the user's score. The route I have se ...

Session.userData does not seem to store the request body from BotFramework's Post Request

When I make a POST request, I am sending user-submitted information to an API that provides specific information for the user. Now, I want to store the data from the POST request as a variable so that I can access it in other functions or dialogs. I have ...

What are your thoughts on nesting an "li" tag within an "a" tag?

Consider this scenario: <ul> <a href="http://google.com"><li id="someId"></li></a> ... ... ... </ul> This is a solution I came up with to work around my current css styling. Now, I'm debating whether or not to ref ...

Concurrent HTTP requests in Node.js

I am embarking on my nodejs journey and aiming to develop a straightforward nodejs application that should: - initially fetch some data via http, - utilize the received json for subsequent requests (some can be run in parallel, while others must be execute ...

Getting Your Content Centered Horizontally with Fixed Positioning in CSS

I would like the div to be centered horizontally with a fixed position, but it doesn't seem to work in my code. Can someone help me troubleshoot? Check out the demo here. HTML: <div id="fancybox-thumbs" class="bottom" style="width: 675px;"> ...

What is the best way to establish communication between Node/Express routes and Socket.io?

I am looking to utilize socket.io for monitoring daily active users of an application. The setup for my socket connection is as follows: let visitorData = {}; io.on('connection', (socket) => { socket.on('user', (data) => { ...

How can I extract the particular user role in my project from GCP IAM?

As I develop my Node.js server utilizing Google Oauth2 for user authentication, I have configured Oauth2 within my organization's project on the Google Cloud Platform. Only members of my organization are permitted to access the service, with each user ...

Monitoring user engagement using Socket.io and Firebase

In my Node/Express app, I am working on monitoring active users without using sessions. The app relies on an external API for handling JWT tokens that are directly passed to the client for storing and subsequent API requests. To track active users, I am u ...

Challenge with CSS Layering

I'm currently experiencing some issues with layering on my website. The problem at hand is that visitors are unable to interact with links within the div layers for some unknown reason. They can't click on the sidebar images or highlight text. I& ...

The Express API is failing to recognize the data keys that were sent from the React frontend, despite being clearly specified

I am facing an issue while trying to send data to a REST API using React hosted in a separate application. The API does not seem to receive the keys sent, even though I checked the results in Chrome and found this output:(2) ["imageSrc", File]0: "imageSrc" ...

Express Node receives two incoming requests from a single remote AJAX request

When I make a simple ajax call, my server-side debugger (node) always shows 2 calls being made. Initially, I suspected it was due to the favicon, but upon further investigation, I don't think that's the case. I attempted to handle the favicon s ...

Exploring the Connection Between Express.js and CORS

I developed a frontend using react.js and an API server using express.js. To handle CORS, I utilized the cors package as shown below: var passport = require("passport"); const express = require('express'); const cors = require('cor ...

authorization for certain express routes using passport.js

Securing certain express routes with Passport.js authentication Steps for authenticating specific routes in Passport.js Looking for a method to authenticate particular routes using Passport.js Your assistance is greatly appreciated... ...

Explanation for aligning anchors within an HTML <div>

I'm faced with this HTML snippet: <div class="row"> <div class="col-md-10 social-icons"> <a href="https://www.youtube.com/" target="_blank"><img src="/images/youtube-i.png"></a> <a href="https://gi ...