Skip to content

Commit 5bab3f8

Browse files
authored
fix(gen-rollup-conf): bypass index files in bundled JS (#160)
This skips index files traversal in bundled files and requires the final file directly.
1 parent edfdd17 commit 5bab3f8

File tree

1 file changed

+40
-19
lines changed
  • src/module/generate-rollup-configuration

1 file changed

+40
-19
lines changed

src/module/generate-rollup-configuration/index.ts

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,41 @@ const validate: (
165165
/**
166166
* Transform ESNext import paths to match the build version being constructed.
167167
*
168-
* @param variant - ESNext or peer build. This is not available for standalone
169-
* as only peer and ESNext have imports.
168+
* @param buildVariant - ESNext or peer build. This is not available for
169+
* standalone as only peer and ESNext have imports.
170+
* @param moduleFormat - What kind of module system to use.
170171
*
171172
* @returns Path overrides for Rollup.
172173
*/
173-
const getPaths = (variant: "esnext" | "peer"): Record<string, string> => ({
174-
"vis-charts/esnext": `vis-charts/${variant}`,
175-
"vis-data/esnext": `vis-data/${variant}`,
176-
"vis-graph3d/esnext": `vis-graph3d/${variant}`,
177-
"vis-network/esnext": `vis-network/${variant}`,
178-
"vis-timeline/esnext": `vis-timeline/${variant}`,
179-
"vis-util/esnext": `vis-util/${variant}`,
180-
"vis-uuid/esnext": `vis-uuid/${variant}`
181-
});
174+
function getPaths(
175+
buildVariant: "esnext" | "peer",
176+
moduleFormat: "esm" | "umd"
177+
): Record<string, string> {
178+
function getPath(
179+
lib:
180+
| "charts"
181+
| "data"
182+
| "graph3d"
183+
| "network"
184+
| "timeline"
185+
| "util"
186+
| "uuid"
187+
): Record<string, string> {
188+
return {
189+
[`vis-${lib}/esnext`]: `vis-${lib}/${buildVariant}/${moduleFormat}/vis-${lib}.js`
190+
};
191+
}
192+
193+
return {
194+
...getPath("charts"),
195+
...getPath("data"),
196+
...getPath("graph3d"),
197+
...getPath("network"),
198+
...getPath("timeline"),
199+
...getPath("util"),
200+
...getPath("uuid")
201+
};
202+
}
182203

183204
const injectCSS = true;
184205
const minimize = true;
@@ -601,12 +622,12 @@ export function generateRollupConfiguration(
601622
{
602623
...commonOutputESM,
603624
entryFileNames: `peer/esm/${libraryFilename}.js`,
604-
paths: getPaths("peer")
625+
paths: getPaths("peer", "esm")
605626
},
606627
{
607628
...commonOutputUMD,
608629
entryFileNames: `peer/umd/${libraryFilename}.js`,
609-
paths: getPaths("peer")
630+
paths: getPaths("peer", "umd")
610631
}
611632
],
612633
plugins: getPlugins("peer", {
@@ -621,12 +642,12 @@ export function generateRollupConfiguration(
621642
{
622643
...commonOutputESM,
623644
entryFileNames: `peer/esm/${libraryFilename}.min.js`,
624-
paths: getPaths("peer")
645+
paths: getPaths("peer", "esm")
625646
},
626647
{
627648
...commonOutputUMD,
628649
entryFileNames: `peer/umd/${libraryFilename}.min.js`,
629-
paths: getPaths("peer")
650+
paths: getPaths("peer", "umd")
630651
}
631652
],
632653
plugins: getPlugins("peer", {
@@ -643,12 +664,12 @@ export function generateRollupConfiguration(
643664
{
644665
...commonOutputESM,
645666
entryFileNames: `esnext/esm/${libraryFilename}.js`,
646-
paths: getPaths("esnext")
667+
paths: getPaths("esnext", "esm")
647668
},
648669
{
649670
...commonOutputUMD,
650671
entryFileNames: `esnext/umd/${libraryFilename}.js`,
651-
paths: getPaths("esnext")
672+
paths: getPaths("esnext", "umd")
652673
}
653674
],
654675
plugins: getPlugins("esnext", {
@@ -662,12 +683,12 @@ export function generateRollupConfiguration(
662683
{
663684
...commonOutputESM,
664685
entryFileNames: `esnext/esm/${libraryFilename}.min.js`,
665-
paths: getPaths("esnext")
686+
paths: getPaths("esnext", "esm")
666687
},
667688
{
668689
...commonOutputUMD,
669690
entryFileNames: `esnext/umd/${libraryFilename}.min.js`,
670-
paths: getPaths("esnext")
691+
paths: getPaths("esnext", "umd")
671692
}
672693
],
673694
plugins: getPlugins("esnext", {

0 commit comments

Comments
 (0)