Sending Grunt Jade configurations to a specific file

I'm currently using grunt-contrib-jade and I'm trying to utilize the pkg.name and pkg.version variables to generate my css file name. Unfortunately, I haven't been able to make this work on my own and would appreciate any assistance. Below is what I have so far:

Snippet from jade task in Gruntfile

compile: {
    options: {
        data  : {
            app    : '<%= pkg.name %>',
            version: '<%= pkg.version %>',
        },
        pretty: true
    }

And then in my jade file:

link(href='_assets/css/<%= app %>-<%= version %>.css', rel='stylesheet', media='screen')

I'm uncertain how to include the data from the compile options defined in the jade task within the Gruntfile.

Any insight or guidance you can offer would be greatly appreciated. Thank you!

Answer №1

Seems like you forgot to include package.json in your Grunt configuration. To fix this, simply add the following code snippet to your grunt file:

grunt.initConfig({
   pkg: require("./package.json"),// <---- don't forget this line
   compile: {
       options: {
          data  : {
              app    : '<%= pkg.name %>',
              version: '<%= pkg.version %>',
          },
          pretty: true
       }
  }
});

In my opinion, it's better to place it within a meta object like shown below:

grunt.initConfig({
   meta{
      pkg: require("./package.json"),// <---- don't forget this line
   },
   compile: {
       options: {
          data  : {
              app    : '<%= meta.pkg.name %>', // <-- pay attention to adding meta
              version: '<%= meta.pkg.version %>',// <-- make sure to add meta
          },
          pretty: true
       }
  }
});

Alternatively, you can try the following approach:

var pkg = require("./package.json");

grunt.initConfig({
   compile: {
       options: {
          data  : {
              app    : pkg.name, // <-- no need for quotes or micro templating
              version: pkg.version ,// <-- no need for quotes or micro templating
          },
          pretty: true
       }
  }
});

This method may not be as flexible as the previous one.

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

My Gatsby website is being rendered in its HTML form on Netlify

The website build is located at . It appears that the javascript functionality is not working, and only the html version (usually meant for search engines) is being displayed. It seems like this issue is only affecting the home page. You can check out the ...

Best practices for server side countdown implementation

Issue I am facing a challenge with displaying a server-side countdown on the client side. Initially, I set it up using socket.io to emit data every 100 milliseconds. While I like this approach, I am concerned about potential performance issues. On the o ...

Learn how to obtain a response for a specific query using the `useQueries` function

Can we identify the response obtained from using useQueries? For instance, const ids = ['dg1', 'pt3', 'bn5']; const data = useQueries( ids.map(id => ( { queryKey: ['friends', id], queryFn: () =&g ...

Filtering an array of objects by multiple arrays of keys

My data set consists of an array of objects const Data = [ {first_name: 'Ammy', city_name: 'LA', age: 22, designation: 'officer'}, {first_name: 'Dave', city_name: 'Paris', age: 23, designation: 'en ...

Creating a dropdown menu for an extensive list of 100 menu items: a step-by-step guide

In my React JS front-end project, I have implemented a drop-down menu using Material-UI. Currently, the menu items are hardcoded which works fine for a small number of items. However, this approach becomes cumbersome when dealing with a larger number of ...

What is the most effective way to retrieve distinct values in Mongoose?

I am looking to extract unique values from a collection. Here is an example: const userID = `user1`; const users = await Chat .find({'$or': [{to: userID}, {from: userID}]}) .select(`-_id to from`) .lean(); // users will contain: [ {from: ...

Angular - Navigate to Login Page post registration and display a confirmation message

As a newcomer to Angular, I am currently working on an Angular and Spring Boot application. So far, I have created components for user login and registration along with validation features. Now, my goal is to redirect the user to the login page upon succes ...

What is the best way to obtain the present date in Nuxt directly from the server?

While conducting code tests, I realized that I required the current time from the server to run the tests effectively. In JavaScript, you can easily obtain the current date on the client side using the command: new Date();. However, when working with Nuxt ...

Can Firebase data be updated in real-time in a Vue app?

Utilizing Firebase for Authentication and integrating a database into a Vue app, my current task involves monitoring changes within a 'friends' collection specific to a user. The objective is to seamlessly display the list of friends while refle ...

Attempting to execute a function within a MAP operation

My attempt to integrate a function into my map is resulting in only the function running and not the rest of the code. Edit: After reflecting on the situation, it dawned on me that I need to elaborate further. The goal here is to execute this.math in orde ...

What is the process for including body text in a Bootstrap tooltip?

I am attempting to enhance a Bootstrap tooltip by adding body text, as it typically only includes a basic title. After reviewing the Bootstrap 5 documentation, it seems that the simplest approach is to utilize the template option: template Base HTML used ...

Front-end displaying empty data fields on my webpage

I've been struggling to understand why my data isn't mapping correctly on these two components. I have attempted two debugging methods to analyze my code and have observed the data object for both the navigation and footer. Unable to comprehend ...

How to retrieve the value of a SelectField component within a constant using Material-UI

I am currently facing an issue with my Drawer component that contains a SelectField with some fields. I am struggling to get the value and implement the onChange functionality of the Field. Below is the snippet of my code: const DrawerCargoAddItem = (p ...

Linux web server blocking requests across different domains, even with correct Access-Control-Allow-Origin headers set

I am facing an issue with my Ubuntu web server running a React app. There are two files on the server that handle requests made by the website, but for some reason, clients are unable to make requests to the server. Server.js: const express = require(&apos ...

"Unexpected outcome: Angular's HTTP request for a JSON file yields an undefined

Learning Angular has been a challenging experience for me. I am currently working on reading a json file into a chart on my main app page to visualize temperature data from my PI. Despite trying various methods found online, I have not been successful so f ...

Using jQuery to convert JSON data into an array

My JSON data structure is as follows: { "default": [ [ 1325876000000, 0 ], [ 1325876000000, 0 ], [ 1325876000000, 0 ], [ 1325876000000, 0 ] ], "direct": [ [ 13 ...

What is the best way to create a visual separation between these two arrows using styled-components?

Currently, I am immersing myself in styled-components and attempting to replicate the image provided below. Although I can achieve this with CSS, I am solely focusing on utilizing styled components for this task. <Container> {sliderItems.map((item) ...

How can Reactjs access a configuration file?

I am struggling to find a solution for reading a properties file in reactJS. I have come across the "properties-reader" module but I can't figure out how to make the require function work. Is there an easier way? For instance, import React, { Com ...

Adjust the input and transition the UI slider

Currently, I am facing an issue with two sliders and inputs. When the number in the top slider is changed, the number and slide in the bottom block do not update accordingly. What steps should I take to address this? $(document).ready(function() { var $ ...

Using JQuery's ajax() method within a for loop

I'm currently working on implementing default edit mode in a Razor view. Everything seems to be functioning properly except for the filling function for the dropdown list. As part of my task, I need to populate the state dropdown list based on the cur ...