What is the method for organizing dependencies exclusively in a designated folder using yarn?

Transition

After using bower for managing dependencies, I have decided to switch to yarn. The biggest challenge I am facing is moving from the existing .bowerrc file to a new .yarnrc configuration.

.bowerrc

{
     "directory": "src/vendors"
}

The difficulty lies in creating a .yarnrc file that only places dependencies into src/vendors, while keeping devDependencies in another directory like node_modules.

.yarnrc

--modules-folder src/vendors

Query

How can I segregate dependencies into src/vendors and keep devDependencies in node_modules when migrating to Yarn?

Answer №1

To achieve the desired outcome without using the .yarnrc files mentioned earlier, you can opt for a different approach by including two distinct scripts in your package.json file, as shown below:

  "scripts": {
      "install-depends": "yarn install --production=true --modules-folder ./src/vendors",
      "install-devDepends": "yarn install --production=false"
   }

Subsequently, execute these scripts in the specified sequence (running them in reverse order will result in clearing the entire node_modules directory):

  1. yarn run install-depends
  2. yarn run install-devDepends

Answer №2

Utilize the --production option when running yarn to specify which dependencies you wish to install; if set to true, only the dependencies will be installed.

To achieve this, create a .yarnrc file in your src folder with the following lines:

--modules-folder vendors
--production true

In the root of your project directory, make another .yarnrc file and set --production to false:

--production false

The structure of your folders should look like this:

.
├── package.json
├── src
│   └── .yarnrc
└── .yarnrc

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

Removing an item from an array using AngularJS with Underscore or another method

Although my question may seem similar to others, it is unique! Please review to understand my specific situation. I am dealing with an array of objects that looks like this $scope.events =[ { $$hashKey: "009" _allDay:false _i ...

Transitioning from checkbox to input field and updating the button through Ajax in a WordPress site

Is it possible to change a checkbox with only 2 values (0 and 1) into an input field where I can enter date and time, and then update it using a submit button with Ajax? Can someone please help me convert the checkbox to an input field and add an update b ...

Retrieving the values of multiple selected options from various select fields simultaneously

Picture having a dynamic number of select fields (the value of this variable is not fixed). I am looking to extract the values of the selected option from each select field using jQuery (or vanilla JavaScript). This is my approach: var cars = $(".sele ...

What is the process for dynamically updating a variable's state within a render function?

I'm currently working on a project for my class where we are tasked with creating a website using React. Unfortunately, neither myself nor my group members have been able to figure out how to render a function in a variable state and make it dynamic. ...

Issue with fullPage.js - Unable to scroll to footer on the last section of the page

I'm currently working with the fullPage.js plugin () and encountering some issues. While sliding through each section, everything functions as expected. However, when I reach the last section and try to scroll down to the footer below it, I encounter ...

Creating a dynamic 3D pie chart with Highcharts and JSON data

I am attempting to create a 3D pie chart using HighChart with JSON data. Despite enabling the 3D option, it only displays in 2D. Here is an example of the 3D pie chart I am trying to achieve: https://www.highcharts.com/demo/3d-pie Could someone please he ...

The JavaScript-rendered HTML button is unresponsive

I have a JavaScript function that controls the display of a popup window based on its visibility. The function used to work perfectly, with the close button effectively hiding the window when clicked. However, after making some changes to the code, the clo ...

Issue with file operations in Ionic1 not functioning properly after scrolling in AngularJS

Working with Ionic v1 and AngularJS, I created a file-based handheld terminal app. However, I noticed that the scroll function stopped working after performing file operations. A workaround I found is that when I click or focus on a search box, the GET re ...

While using the ionic serve command

Every time I attempt to execute Ionic, an error is triggered. Your assistance is greatly appreciated. Interestingly, the AppData file has been erased as well! 'ionic' is giving me this message: "not recognized as an internal or external command ...

how to show an error in a modal window when encountering an error

Using Blazor and Blazorstrap, typically when the server disconnects, an "Error" message is displayed. However, with the BsModal from Blazorstrap, it appears in the background layer, making it unresponsive. How can this be fixed? Is it possible to close the ...

The design of RESTful web applications with a client-server architecture

I need clarification on how client-server architecture should function for a modern web application with a RESTful backend. For a web app, the client is typically the browser while the server is the web server. Programatically speaking, there are componen ...

Check out the HTML display instead of relying on console.log

Need help displaying the result of a JavaScript statement in an HTML page instead of console.log output. I am new to coding! Here is the JS code snippet: $.ajax({ url: 'xml/articles.json', dataType: 'json', type: ...

Save picture in localStorage

Hello, I am currently working on a page where I need to retrieve an image from a JSON file and store it locally. Below is the code I have been using: <!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-1.10.1.min. ...

Creating a fresh object from a previous one using JavaScript:

I am working towards a goal where I aim to take an object with string values, translate those values, and then create a new object filled with the translated strings. For example, if I start with: const strings = { "name": "my name", "age": "my ag ...

Tips on enhancing Ajax requests with jQuery and deferred objects

Currently, I have implemented four or more ajax rest calls within the $(document).ready(function(){} function. To handle this situation, I resorted to adding .done() to the largest call as a temporary solution. While it is "working," I am looking to enha ...

Remove the list by conducting a comparison analysis

<html> <head> <title> Manipulating List Items Using JavaScript </title> <script type="text/javascript"> function appendNewNode(){ if(!document.getElementById) return; var newlisttext = document.changeform.newlist.val ...

What is causing my radio button event to activate when a separate radio button is selected?

I have implemented the code below to display "pers" and hide "bus," and vice versa. JQuery: $('input[name="perorbus"]').click(function() { if ($(this).attr('id') == 'bus') { $('#showbus&apo ...

An issue with the Babel version is preventing the Express API from starting up successfully

Error! Message: [nodemon] starting `babel-node index.js` C:\Users\Zara Gunner\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-ma ...

AngularJS bespoke provider leading to "Provider not found" error

I am facing an issue with my custom provider in AngularJS that is supposed to handle global configurations for my application. Despite my efforts, I am unable to properly inject this provider as AngularJS keeps throwing an "Unknown provider" exception. Thi ...

Having trouble updating the value of my textfield in material-ui using formik

Below is the code I'm working with to set a default value using the material-ui Textfield API within a formik fieldarray: <TextField name={`myGroups.${index}.myGroupName`} value={`Group ${index+1}`} label="Group" InputProps={{ ...