What is the method Mui uses to set up its exports if there is no `exports` property in the package.json file

Within the Mui guidelines, they propose utilizing:

import Button from '@mui/material/Button';
import TextField from '@mui/material/TextField';

for style imports as opposed to:

import { Button, TextField } from '@mui/material';

The rationale behind this recommendation seems to be that the @mui/material style import goes through a barrel file - causing issues with bundlers like Webpack such as:

  1. Inaccurate treeshaking for production bundles
  2. No treeshaking for development builds, resulting in slower build times.

Webpack relies on an exports property within the package.json file (documentation here) to define submodules accessed via @mui/material/Button style imports.

However, it appears that Mui does not actually utilize this in their package.json file

So the question remains: how do these imports function correctly without these specified exports?

Answer №1

When looking at the npm package, you'll notice that it follows the standard node module resolution.

There are no specific directories like src/lib/dist, and there is also no files property in the package.json file.

The structure looks like this:

Accordion/
  index.js
AccordionActions/
  index.js
...
index.js
package.json

The main index.js file is referenced in the main property of the package.json, following the barrel file strategy used in the @mui/material style imports.

On the other hand, the @mui/material/Button style imports work by simply referencing the directory and accessing the index file within it.

It seems that Mui's build process involves building to a completely separate directory and then copying over the package.json file, instead of selectively choosing a folder to publish using the files property.

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

Access the blob file saved in the indexedDB on an iOS device or iPad

Greetings, I am currently fetching a file using axios in the following manner: return axios({ method: "get", url: URL, responseType: "blob", }) .then((response) => { return { ...val, ...

Having to click twice in order to close the jQuery dialog box can be frustrating

I've been attempting to set up a div that pops up using jQuery dialog. Initially, when the user clicks on the button and opens the dialog, it closes with the first click. The second time they try to close the dialog, it will reopen the same popup, r ...

Updating Angular UI routes with various parameters

When utilizing Angular UI router, I have a route configured in the following manner $stateProvider.state('edit', { url: '/:file/:page', ... } After modifying the route from /edit/file1/page1 to /edit/file1/page2, the view does ...

What is the best way to choose the nearest element using the initial part of a class name?

I am working on a section of a table and need to hide a specific part when an icon is clicked. Below is the code snippet: <tr class="getmoreinfo_19"> <td>&nbsp;</td> <td colspan="3"> <div c ...

The function getSelection().focusNode does not function properly within a specified ID

My current code allows for text to be bolded and unbolded using Window.getSelection(). I found the initial solution here: Bold/unbold selected text using Window.getSelection() It works perfectly without any issues. However, when I tried to modify the code ...

I'm having trouble with the routing of a Node.js REST API built with Express and Mongoose

I am currently in the process of constructing a RESTful webservice by following a tutorial that can be found at: However, I have encountered an issue where it is returning a CANNOT GET/ reports error. Despite my efforts to troubleshoot and rectify the pro ...

What is the best method to use the dollar sign ($) to override styles in MUI 5?

In the following code snippet, we can see an attempt to provide a MUI 4 solution for changing input field styles when hovering in MUI 5. However, it seems that the code is not working as expected. The goal is to change the color of the TextField upon hov ...

What is the process for importing module functions in Svelte when utilizing npm?

I'm having trouble understanding how to properly use imports in Svelte with npm. I have a Svelte component that I can't seem to get working. Uncommenting "//import { Configuration, OpenAIApi } from "openai";" leads to the error message: [!] (plug ...

Disabling mandatory field validation for hidden fields in MVC 5

My MVC5 ViewModel has two important properties: public class RegisterViewModel { [Required] [EmailAddress] [Display(Name = "Email")] public string Email { get; set; } [Display(Name = "Date of Birth")] public Dat ...

When using Asp.Net TextBox, the focus is lost after inputting the first character

I have created an Asp.Net web form (aspx) that includes a TextBox: <div id="field"> <asp:TextBox Id="Name" runat="server" MaxLength="50"/> </div> Whenever I type characters into the TextBox, I t ...

Utilize JavaScript objects to convert subscripts into HTML elements

I am currently developing an Angular 1X application where all icon labels are stored in a JS object as shown below: var labels={ ........ iconlabel_o2:"O<sub>2</sub>", iconLabel_co2:"CO<sub>2</sub>", iconLabel_h20:"H<sub ...

What is the best way to remove all attributes from one interface when comparing to another?

Consider the following two interfaces: interface A { a: number; b: string; } interface B { b: string; } I am interested in creating a new type that includes all the keys from interface A, but excludes any keys that are also present in interface B. ...

Can you identify any issues with this Javascript code's "If" condition?

In my JavaScript code, I have an "if condition" that looks like this: for (var i in data) { //Gender.push("Gender " + data[i].JenisKelaminID); if (data[i].JenisKelaminID == 1) { Gender.push("Men"); } if (data[i].JenisKelaminID == 2) { Gend ...

A step-by-step guide on sending a question to an MS Azure chat bot through the direcline channel using client-side scripting techniques

Currently, I am utilizing the Azure Chat bot (v4 MS bot framework) and integrated it into the Direcline channel. My goal is to send a question to the chatbot when a user clicks on one of the suggested questions. In the image below, you can see the list of ...

Linking MySQL Database to Javascript Quiz (Novice)

After constructing the database for my quiz, I am facing an issue with getting the user's answers to be stored in the database. Although the quiz functions properly on my browser and questions can be answered, I am unable to calculate the final score ...

Trigger a single occurrence of the function upon element creation and pass it to VueJS methods

Currently, I am working with BootstrapVue and would like to provide a brief overview of my code: I have a v-for loop with inputs that can be dynamically created using a b-button named "addElement". Additionally, I have the option to select an item from a ...

What is the best way to access an element from an array nested within an object in Firestore?

In my Firestore database, the structure includes multiple arrays within the "reserved items" object. Each array contains more than one element. How can I extract the "returnDate" element from every single array within the object? ...

Issue with verification code for form with changing text color

I've been working on a form that collects an email and password, then checks if the email is valid by ensuring it contains an "@" symbol. If the email doesn't contain "@", the paragraph tag with the title "email" should change color. However, des ...

Load images in advance using this script

Using a script to load images on two websites, the image is placed inside a div with the ID div-to-load-external-image Encountering an issue where PageSpeed Insights advises to preload these images, seeking guidance... Any assistance will be appreciated. ...

When employing useNavigation, the URL is updated but the component does not render or appear on the

Check out this code snippet: https://codesandbox.io/p/sandbox/hardcore-lake-mptzw3 App.jsx: import ContextProvider from "./provider/contextProvider"; import Routes from "./routes"; function App() { console.log("Inside App" ...