Skip to content

Commit

Permalink
rollup config and plugin added in vite config
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitmalhotra1420 committed May 13, 2024
1 parent 19097a4 commit 8bc0009
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"chalk": "5.0.1",
"compressorjs": "^1.2.1",
"constants-browserify": "1.0.0",
"cpus": "^1.0.3",
"cross-env": "^7.0.3",
"crypto-browserify": "^3.12.0",
"crypto-js": "4.0.0",
Expand Down
33 changes: 33 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import cpus from 'cpus';
import react from '@vitejs/plugin-react';
import { parse } from 'envfile';
import fs from 'fs';
Expand Down Expand Up @@ -51,6 +52,22 @@ if (localSDKLinking) {
};
}

function differMuiSourcemapsPlugins() {
const muiPackages = ['@mui/material', '@emotion/styled', '@emotion/react'];

return {
name: 'differ-mui-sourcemap',
transform(code: string, id: string) {
if (muiPackages.some((pkg) => id.includes(pkg))) {
return {
code: code,
map: null,
};
}
},
};
}

// https://vitejs.dev/config/
export default defineConfig({
resolve: {
Expand All @@ -72,6 +89,7 @@ export default defineConfig({
}),
nodePolyfills(),
vitePluginRequire.default(),
differMuiSourcemapsPlugins(),
],
define: {
global: 'globalThis',
Expand All @@ -89,5 +107,20 @@ export default defineConfig({
commonjsOptions: {
transformMixedEsModules: true,
},
rollupOptions: {
maxParallelFileOps: Math.max(1, cpus().length - 1),
output: {
manualChunks: (id) => {
if (id.includes('node_modules')) {
return 'vendor';
}
},
sourcemapIgnoreList: (relativeSourcePath) => {
const normalizedPath = path.normalize(relativeSourcePath);
return normalizedPath.includes('node_modules');
},
},
cache: false,
},
},
});
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9716,6 +9716,13 @@ __metadata:
languageName: node
linkType: hard

"cpus@npm:^1.0.3":
version: 1.0.3
resolution: "cpus@npm:1.0.3"
checksum: 10/c92467fe2d132326f6fa36c91bf7b12b237fab94852fe25b28b0645d5b9278abbe1d12a12018dfbffccd4cdf71b3fb5294af8c09e20fbbe662074e40c99146d7
languageName: node
linkType: hard

"crc-32@npm:^1.2.0":
version: 1.2.2
resolution: "crc-32@npm:1.2.2"
Expand Down Expand Up @@ -17852,6 +17859,7 @@ __metadata:
chalk: "npm:5.0.1"
compressorjs: "npm:^1.2.1"
constants-browserify: "npm:1.0.0"
cpus: "npm:^1.0.3"
cross-env: "npm:^7.0.3"
crypto-browserify: "npm:^3.12.0"
crypto-js: "npm:4.0.0"
Expand Down

0 comments on commit 8bc0009

Please sign in to comment.