Optimize several projects or pages with RequireJS

How can I improve the efficiency of my multiple requirejs projects? For example, I have this structure below with two main.js in different locations/folders,

build/
   build.js

dev/    
   index.php
    core/
      js/
       main.js
       libs/
          jquery.js


    local/
      js/
        main.js

My build/build.js

({
    // Location of HTML and JS files.
    appDir: "../dev/",

    // Directory containing JS:
    baseUrl: "local/view/javascript/base/",

    // Output directory for optimized project.
    dir: "../dist",

    // Define modules to compile.
    modules: [
        {
            name: 'main',

            mainConfigFile: '../dev/local/js/main.js'
        },
        {

            name: 'main',

            mainConfigFile: '../dev/core/js/main.js'
        }
    ]
})

It keeps failing to compress or find dependencies, like,

ERROR: ENOENT, no such file or directory 'c:\wamp\websitename\dist\local\js\jquery.js

My query.js is located in core/js/libs/ - why is it looking for it in local\js?

What did I overlook?

Answer №1

primary is mentioned twice within your sections setup. By specifying to r.js, you are essentially instructing it to "generate the section main under ../output with certain parameters and also produce another section main under ../output but with different specifications." It's not feasible for r.js to create two distinct sections that should ultimately be the same file in ../output.

Additionally, placing configFile inside a module configuration directly as done here is incorrect. This should be a global setting; if customization on a per-section basis is desired, then override should be utilized. Moreover, indicating the configFile does not inform r.js which specific section needs optimization.

Based on the issue outlined in your query, the following adjustment appears necessary:

({
    // Location of HTML and JS files.
    appDir: "../source/",

    // Root directory for JS content:
    baseUrl: "local/view/js/base/",

    // Destination for the optimized project.
    dir: "../output",

    // Declaration of modules for compilation.
    sections: [
        {
            // Assign a unique identifier.
            name: 'main_local',

            // As this section is non-existent in the original source, specify its creation.
            create: true,

            // List of applicable components.
            include: ['../source/local/js/main.js'],

            // Special configuration for configFile at this level only.
            override: {
                configFile: '../source/local/js/main.js'
            }
        },
        {
            name: 'main_core',
            create: true,
            include: ['../source/core/js/main.js'],

            override: {
                configFile: '../source/core/js/main.js'
            }
        },
    ]
})

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

Node.js: Extract the object's name and value that are sent from the frontend

I'm in the process of creating a microservice using nodejs. The request is returning the following JSON. { "distCd": "abcd", "distName": "parentLife Distributor (TOD)", "stateCd": "", "subdistInd": false, "maindistInd": true ...

Exploring the Contrasts in Utilizing AJAX: A Comparative Analysis of Two

Can someone explain the distinction between utilizing AJAX in the following manner, function showHint(str) { var xmlhttp; if (str.length==0) { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE ...

Combining onClick and a href within a single sentence: How can I effectively utilize both onClick

Currently, I have implemented the following code for a sliding menu bar. However, I am facing an issue where upon clicking on a href link, I want the ".gs-hamburger" function to slide up the menu bar after redirecting to the page. <nav class="gs-nav- ...

Sending an Ajax POST request from a Node.js server

I am running a Node.js server with Socket.IO that communicates with a Python server using Django. I am looking to make a POST request from the Node.js server to the Django server on a specific method without utilizing any jQuery functions due to their depe ...

What is the ideal number of child processes to fork() in a node.js application?

I have a simple question that may require different variables to answer. Currently, I am exploring node.js and considering how to implement it in a multi-core architecture. The latest version of node.js offers child_process.fork() and child.spawn() metho ...

Using arrays in the request body with Node.js Express framework

Trying to include an array in the request body for a POST call to MongoDB, aiming to insert a new document upon success. See my current code snippet below: app.post(`/api/add`, async (req, res) => { collection.create({ 'id': req.body.id, ...

jQuery error: an unexpected token was encountered

I am encountering an issue with an "unexpected token =" error on the line toggleNav = function(evt){ in the code snippet below. Despite going through various similar posts, I am unable to pinpoint why this error is occurring. Any assistance in guiding me ...

What are some reasons for the slow performance of AWS SQS?

My current project involves measuring the time it takes to send a message and receive it from an SQS queue. Surprisingly, the average time it takes is between 800-1200 ms, which seems like an excessively long period. Below is the code I have been using for ...

Avoiding unlimited re-renders when using useEffect() in React - Tips and Strategies

As a new developer, I recently built a chat application using socket io. In my code, I have the useEffect hook set to only change when the socket changes. However, I also have setMessage within the body of useEffect(), with socket as a dependency. Unfortun ...

Tips for effortlessly moving content by dragging and dropping it into a text box

Before attempting to create something, I want to verify its feasibility. Begin with a text area that can be pre-filled with text and allow users to add or delete text. Alongside the text area, there are small elements that can be images or HTML components ...

What steps do you need to take in order to transform this individual slideshow script into numerous slideshows

I came across this code online that effectively creates a slideshow. https://css-tricks.com/snippets/jquery/simple-auto-playing-slideshow/ Is there a way to modify the code to support multiple slideshows? I've made several attempts without success ...

By enabling the "useNewUrlParser" and "useUnifiedTopology" properties to true in the MongoDB connection URL, you can prevent the need for a catch block in a promise function

Within my code, I have utilized mongoose to establish a connection with a MongoDB URL. In order to prevent the occurrence of "DeprecationWarning", I have configured parameters such as "useNewUrlParser", "useUnifiedTopology", "useFindAndModify", and "useCre ...

Generate a new cookie only when it is not currently present

My objective is to: Determine if a cookie named "query" exists If it does, take no action If not, create a cookie called "query" with a value of 1 Please note: I am working with jQuery version 1.4.2 and utilizing the jQuery cookie plugin. Any recommend ...

Error encountered while attempting to send SendGrid email to multiple recipients

Currently, I am using const sgMail = require('@sendgrid/mail'); with sendgrid version 7.6.2. Whenever I attempt to add two email addresses in an array and then pass it into either send() or sendMultiple(), an error is being thrown like below. st ...

I'm attempting to access a PHP file by clicking a button using AJAX and jQuery

I am just starting to learn the basics of jQuery and AJAX. I have already attempted to solve this problem by checking previous answers on Stackoverflow, but the code provided did not work for me. I have created two pages, index.php and testing.php, with a ...

A step-by-step guide on printing out longitudes and latitudes stored in MongoDB using Mongoose with console.log()

I'm looking to retrieve latitude and longitude from this source. ** router.get("/", function(req, res) { Map.find({}, function(err, doc) { if (err) { res.send(500, { error: err }); } res.send(doc); doc.map((item ...

Skipping the configuration file during the process of converting Node.js files to an executable using pkg

I am currently working on a node.js application and in order to prevent users from reading the code, I am attempting to convert my JavaScript files to executable files. I have been using the pkg module for this task, but I have encountered an issue. The p ...

No response text returned from the local Ajax request

Currently, I am facing a challenge while attempting to send an ajax call from the client to my server containing data related to an input parameter. The issue is that although I can view the data in my server's console, it does not display in the brow ...

Unexpected error occurred when attempting to fetch the jQuery value of the radio button: "Unrecognized expression syntax error"

I am facing an issue while trying to extract the value of a radio button using $("input[@name=login]"); I keep getting an "Uncaught Syntax error, unrecognized expression" message. To view the problem, visit http://jsfiddle.net/fwnUm/. Below is the complet ...

Position of JSON data response is inaccurate

Currently, I have a function that calls an API from the server in the following manner: getDataSet(callback) { request.open('POST', `${apiPath}`); request.setRequestHeader('Content-Type', 'application/x-ww ...