Skip to content

Commit 318f6ff

Browse files
authored
[infra] Remove package.json module field (#46620)
1 parent 145afdc commit 318f6ff

File tree

2 files changed

+20
-28
lines changed

2 files changed

+20
-28
lines changed

docs/data/material/guides/minimizing-bundle-size/minimizing-bundle-size.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,16 @@ To prevent VS Code from automatically importing from `@mui/material`, you can u
6767
## Using Next.js 13.5 or later?
6868

6969
If you're on **Next.js 13.5 or newer**, you're in good hands. These versions include automatic import optimization via the `optimizePackageImports` option. This removes the need for manual configuration or Babel plugins to optimize imports.
70+
71+
## Using parcel
72+
73+
Parcel, by default, doesn't resolve package.json `"exports"`. This makes it always resolve to the commonjs version of our library. To make it optimally make use of our ESM version, make sure to [enable the `packageExports` option](https://parceljs.org/features/dependency-resolution/#enabling-package-exports).
74+
75+
```json
76+
// ./package.json
77+
{
78+
"@parcel/resolver-default": {
79+
"packageExports": true
80+
}
81+
}
82+
```

scripts/copyFilesUtils.mjs

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ function createExportFor(exportName, conditions) {
138138
};
139139
}
140140

141-
// TODO: remove useEsmExports paramater once X is on the ESM-exports package layout (default to true)
142-
export async function createPackageFile(useEsmExports = false) {
141+
export async function createPackageFile() {
143142
const packageData = await fse.readFile(path.resolve(packagePath, './package.json'), 'utf8');
144143
const { nyc, scripts, devDependencies, workspaces, ...packageDataOther } =
145144
JSON.parse(packageData);
@@ -170,32 +169,12 @@ export async function createPackageFile(useEsmExports = false) {
170169
}
171170
}
172171

173-
const newPackageData = useEsmExports
174-
? {
175-
...packageDataOther,
176-
private: false,
177-
...(packageDataOther.main
178-
? {
179-
main: './index.js',
180-
module: './esm/index.js',
181-
}
182-
: {}),
183-
exports: packageExports,
184-
}
185-
: {
186-
...packageDataOther,
187-
private: false,
188-
...(packageDataOther.main
189-
? {
190-
main: fse.existsSync(path.resolve(buildPath, './node/index.js'))
191-
? './node/index.js'
192-
: './index.js',
193-
module: fse.existsSync(path.resolve(buildPath, './esm/index.js'))
194-
? './esm/index.js'
195-
: './index.js',
196-
}
197-
: {}),
198-
};
172+
const newPackageData = {
173+
...packageDataOther,
174+
private: false,
175+
...(packageDataOther.main ? { main: './index.js' } : {}),
176+
exports: packageExports,
177+
};
199178

200179
const typeDefinitionsFilePath = path.resolve(buildPath, './index.d.ts');
201180
if (await fse.pathExists(typeDefinitionsFilePath)) {

0 commit comments

Comments
 (0)