Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

chore: add dual ESM/CJS build for all workspace packages (#3607)

Igor Dykhtaf4961c61b930
diff --git a/src/actions/babel.config.js b/src/actions/babel.config.js
index eb16706b6..3b4d402a3 100644
--- a/src/actions/babel.config.js
+++ b/src/actions/babel.config.js
@@ -3,21 +3,14 @@
const KeplerPackage = require('./package');
-const PRESETS = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'];
-const PLUGINS = [
+// Plugins shared by both CJS and ESM builds.
+const SHARED_PLUGINS = [
['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}],
- '@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-logical-assignment-operators',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-export-namespace-from',
- [
- '@babel/transform-runtime',
- {
- regenerator: true
- }
- ],
[
'search-and-replace',
{
@@ -30,22 +23,35 @@ const PLUGINS = [
}
]
];
-const ENV = {
- test: {
- plugins: ['istanbul']
- },
- debug: {
- sourceMaps: 'inline',
- retainLines: true
- }
-};
module.exports = function babel(api) {
- api.cache(true);
+ // Cache per BABEL_ENV so that CJS and ESM builds get separate cached results.
+ api.cache.using(() => process.env.BABEL_ENV || process.env.NODE_ENV || 'development');
+
+ const isEsm = api.env('esm');
+ const isTest = api.env('test');
+ const isDebug = api.env('debug');
+
+ // ESM build: modules:false preserves import/export so Vite/esbuild can tree-shake.
+ // CJS build (default / test): transforms import/export to require/module.exports.
+ const presets = [
+ ['@babel/preset-env', isEsm ? {modules: false} : {}],
+ '@babel/preset-react',
+ '@babel/preset-typescript'
+ ];
+
+ const plugins = [
+ ...SHARED_PLUGINS,
+ // CJS and test builds need the CommonJS transform; ESM must omit it.
+ ...(isEsm ? [] : ['@babel/plugin-transform-modules-commonjs']),
+ // Runtime helpers: ESM variant uses ESM imports, no require() calls.
+ ['@babel/transform-runtime', {regenerator: true, ...(isEsm ? {useESModules: true} : {})}],
+ ...(isTest ? ['istanbul'] : [])
+ ];
return {
- presets: PRESETS,
- plugins: PLUGINS,
- env: ENV
+ presets,
+ plugins,
+ ...(isDebug ? {sourceMaps: 'inline', retainLines: true} : {})
};
};
diff --git a/src/actions/package.json b/src/actions/package.json
index 5ec00f7e1..61a9629cf 100644
--- a/src/actions/package.json
+++ b/src/actions/package.json
@@ -4,7 +4,7 @@
"version": "3.3.0-alpha.5",
"description": "kepler.gl constants used by kepler.gl components, actions and reducers",
"license": "MIT",
- "main": "dist/index.js",
+ "main": "dist/cjs/index.js",
"types": "dist/index.d.ts",
"keywords": [
"babel",
@@ -19,10 +19,10 @@
"url": "https://github.com/keplergl/kepler.gl.git"
},
"scripts": {
- "build": "rm -fr dist && babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build": "rm -fr dist && babel src --out-dir dist/cjs --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts' && BABEL_ENV=esm babel src --out-dir dist/esm --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:types": "tsc --project ./tsconfig.production.json",
"prepublishOnly": "babel-node ../../scripts/license-header/bin --license ../../FILE-HEADER && yarn build && yarn build:types",
- "stab": "mkdir -p dist && touch dist/index.js"
+ "stab": "mkdir -p dist/cjs dist/esm && touch dist/cjs/index.js dist/esm/index.js"
},
"files": [
"dist"
@@ -63,5 +63,14 @@
"node": "20.19.3",
"yarn": "4.4.0"
},
- "packageManager": "[email protected]"
+ "packageManager": "[email protected]",
+ "module": "dist/esm/index.js",
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "import": "./dist/esm/index.js",
+ "require": "./dist/cjs/index.js",
+ "default": "./dist/cjs/index.js"
+ }
+ }
}
diff --git a/src/ai-assistant/babel.config.js b/src/ai-assistant/babel.config.js
index eb16706b6..3b4d402a3 100644
--- a/src/ai-assistant/babel.config.js
+++ b/src/ai-assistant/babel.config.js
@@ -3,21 +3,14 @@
const KeplerPackage = require('./package');
-const PRESETS = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'];
-const PLUGINS = [
+// Plugins shared by both CJS and ESM builds.
+const SHARED_PLUGINS = [
['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}],
- '@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-logical-assignment-operators',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-export-namespace-from',
- [
- '@babel/transform-runtime',
- {
- regenerator: true
- }
- ],
[
'search-and-replace',
{
@@ -30,22 +23,35 @@ const PLUGINS = [
}
]
];
-const ENV = {
- test: {
- plugins: ['istanbul']
- },
- debug: {
- sourceMaps: 'inline',
- retainLines: true
- }
-};
module.exports = function babel(api) {
- api.cache(true);
+ // Cache per BABEL_ENV so that CJS and ESM builds get separate cached results.
+ api.cache.using(() => process.env.BABEL_ENV || process.env.NODE_ENV || 'development');
+
+ const isEsm = api.env('esm');
+ const isTest = api.env('test');
+ const isDebug = api.env('debug');
+
+ // ESM build: modules:false preserves import/export so Vite/esbuild can tree-shake.
+ // CJS build (default / test): transforms import/export to require/module.exports.
+ const presets = [
+ ['@babel/preset-env', isEsm ? {modules: false} : {}],
+ '@babel/preset-react',
+ '@babel/preset-typescript'
+ ];
+
+ const plugins = [
+ ...SHARED_PLUGINS,
+ // CJS and test builds need the CommonJS transform; ESM must omit it.
+ ...(isEsm ? [] : ['@babel/plugin-transform-modules-commonjs']),
+ // Runtime helpers: ESM variant uses ESM imports, no require() calls.
+ ['@babel/transform-runtime', {regenerator: true, ...(isEsm ? {useESModules: true} : {})}],
+ ...(isTest ? ['istanbul'] : [])
+ ];
return {
- presets: PRESETS,
- plugins: PLUGINS,
- env: ENV
+ presets,
+ plugins,
+ ...(isDebug ? {sourceMaps: 'inline', retainLines: true} : {})
};
};
diff --git a/src/ai-assistant/package.json b/src/ai-assistant/package.json
index 2067144a1..7726023a9 100644
--- a/src/ai-assistant/package.json
+++ b/src/ai-assistant/package.json
@@ -4,7 +4,7 @@
"version": "3.3.0-alpha.5",
"description": "kepler.gl AI assistant",
"license": "MIT",
- "main": "dist/index.js",
+ "main": "dist/cjs/index.js",
"types": "dist/index.d.ts",
"keywords": [
"babel",
@@ -19,10 +19,10 @@
"url": "https://github.com/keplergl/kepler.gl.git"
},
"scripts": {
- "build": "rm -fr dist && babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build": "rm -fr dist && babel src --out-dir dist/cjs --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts' && BABEL_ENV=esm babel src --out-dir dist/esm --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:types": "tsc --project ./tsconfig.production.json",
"prepublishOnly": "babel-node ../../scripts/license-header/bin --license ../../FILE-HEADER && yarn build && yarn build:types",
- "stab": "mkdir -p dist && touch dist/index.js"
+ "stab": "mkdir -p dist/cjs dist/esm && touch dist/cjs/index.js dist/esm/index.js"
},
"files": [
"dist"
@@ -68,5 +68,14 @@
"node": "20.19.3",
"yarn": "4.4.0"
},
- "packageManager": "[email protected]"
+ "packageManager": "[email protected]",
+ "module": "dist/esm/index.js",
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "import": "./dist/esm/index.js",
+ "require": "./dist/cjs/index.js",
+ "default": "./dist/cjs/index.js"
+ }
+ }
}
diff --git a/src/cloud-providers/babel.config.js b/src/cloud-providers/babel.config.js
index eb16706b6..3b4d402a3 100644
--- a/src/cloud-providers/babel.config.js
+++ b/src/cloud-providers/babel.config.js
@@ -3,21 +3,14 @@
const KeplerPackage = require('./package');
-const PRESETS = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'];
-const PLUGINS = [
+// Plugins shared by both CJS and ESM builds.
+const SHARED_PLUGINS = [
['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}],
- '@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-logical-assignment-operators',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-export-namespace-from',
- [
- '@babel/transform-runtime',
- {
- regenerator: true
- }
- ],
[
'search-and-replace',
{
@@ -30,22 +23,35 @@ const PLUGINS = [
}
]
];
-const ENV = {
- test: {
- plugins: ['istanbul']
- },
- debug: {
- sourceMaps: 'inline',
- retainLines: true
- }
-};
module.exports = function babel(api) {
- api.cache(true);
+ // Cache per BABEL_ENV so that CJS and ESM builds get separate cached results.
+ api.cache.using(() => process.env.BABEL_ENV || process.env.NODE_ENV || 'development');
+
+ const isEsm = api.env('esm');
+ const isTest = api.env('test');
+ const isDebug = api.env('debug');
+
+ // ESM build: modules:false preserves import/export so Vite/esbuild can tree-shake.
+ // CJS build (default / test): transforms import/export to require/module.exports.
+ const presets = [
+ ['@babel/preset-env', isEsm ? {modules: false} : {}],
+ '@babel/preset-react',
+ '@babel/preset-typescript'
+ ];
+
+ const plugins = [
+ ...SHARED_PLUGINS,
+ // CJS and test builds need the CommonJS transform; ESM must omit it.
+ ...(isEsm ? [] : ['@babel/plugin-transform-modules-commonjs']),
+ // Runtime helpers: ESM variant uses ESM imports, no require() calls.
+ ['@babel/transform-runtime', {regenerator: true, ...(isEsm ? {useESModules: true} : {})}],
+ ...(isTest ? ['istanbul'] : [])
+ ];
return {
- presets: PRESETS,
- plugins: PLUGINS,
- env: ENV
+ presets,
+ plugins,
+ ...(isDebug ? {sourceMaps: 'inline', retainLines: true} : {})
};
};
diff --git a/src/cloud-providers/package.json b/src/cloud-providers/package.json
index 984123f51..67a757ec5 100644
--- a/src/cloud-providers/package.json
+++ b/src/cloud-providers/package.json
@@ -4,7 +4,7 @@
"version": "3.3.0-alpha.5",
"description": "kepler.gl constants used by kepler.gl components, actions and reducers",
"license": "MIT",
- "main": "dist/index.js",
+ "main": "dist/cjs/index.js",
"types": "dist/index.d.ts",
"keywords": [
"babel",
@@ -19,10 +19,10 @@
"url": "https://github.com/keplergl/kepler.gl.git"
},
"scripts": {
- "build": "rm -fr dist && babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build": "rm -fr dist && babel src --out-dir dist/cjs --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts' && BABEL_ENV=esm babel src --out-dir dist/esm --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:types": "tsc --project ./tsconfig.production.json",
"prepublishOnly": "babel-node ../../scripts/license-header/bin --license ../../FILE-HEADER && yarn build && yarn build:types",
- "stab": "mkdir -p dist && touch dist/index.js"
+ "stab": "mkdir -p dist/cjs dist/esm && touch dist/cjs/index.js dist/esm/index.js"
},
"files": [
"dist"
@@ -48,5 +48,14 @@
"node": "20.19.3",
"yarn": "4.4.0"
},
- "packageManager": "[email protected]"
+ "packageManager": "[email protected]",
+ "module": "dist/esm/index.js",
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "import": "./dist/esm/index.js",
+ "require": "./dist/cjs/index.js",
+ "default": "./dist/cjs/index.js"
+ }
+ }
}
diff --git a/src/common-utils/babel.config.js b/src/common-utils/babel.config.js
index eb16706b6..3b4d402a3 100644
--- a/src/common-utils/babel.config.js
+++ b/src/common-utils/babel.config.js
@@ -3,21 +3,14 @@
const KeplerPackage = require('./package');
-const PRESETS = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'];
-const PLUGINS = [
+// Plugins shared by both CJS and ESM builds.
+const SHARED_PLUGINS = [
['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}],
- '@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-logical-assignment-operators',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-export-namespace-from',
- [
- '@babel/transform-runtime',
- {
- regenerator: true
- }
- ],
[
'search-and-replace',
{
@@ -30,22 +23,35 @@ const PLUGINS = [
}
]
];
-const ENV = {
- test: {
- plugins: ['istanbul']
- },
- debug: {
- sourceMaps: 'inline',
- retainLines: true
- }
-};
module.exports = function babel(api) {
- api.cache(true);
+ // Cache per BABEL_ENV so that CJS and ESM builds get separate cached results.
+ api.cache.using(() => process.env.BABEL_ENV || process.env.NODE_ENV || 'development');
+
+ const isEsm = api.env('esm');
+ const isTest = api.env('test');
+ const isDebug = api.env('debug');
+
+ // ESM build: modules:false preserves import/export so Vite/esbuild can tree-shake.
+ // CJS build (default / test): transforms import/export to require/module.exports.
+ const presets = [
+ ['@babel/preset-env', isEsm ? {modules: false} : {}],
+ '@babel/preset-react',
+ '@babel/preset-typescript'
+ ];
+
+ const plugins = [
+ ...SHARED_PLUGINS,
+ // CJS and test builds need the CommonJS transform; ESM must omit it.
+ ...(isEsm ? [] : ['@babel/plugin-transform-modules-commonjs']),
+ // Runtime helpers: ESM variant uses ESM imports, no require() calls.
+ ['@babel/transform-runtime', {regenerator: true, ...(isEsm ? {useESModules: true} : {})}],
+ ...(isTest ? ['istanbul'] : [])
+ ];
return {
- presets: PRESETS,
- plugins: PLUGINS,
- env: ENV
+ presets,
+ plugins,
+ ...(isDebug ? {sourceMaps: 'inline', retainLines: true} : {})
};
};
diff --git a/src/common-utils/package.json b/src/common-utils/package.json
index 5a0a48d10..60f952c6b 100644
--- a/src/common-utils/package.json
+++ b/src/common-utils/package.json
@@ -4,7 +4,7 @@
"version": "3.3.0-alpha.5",
"description": "kepler.gl common utils",
"license": "MIT",
- "main": "dist/index.js",
+ "main": "dist/cjs/index.js",
"types": "dist/index.d.ts",
"keywords": [
"babel",
@@ -19,10 +19,10 @@
"url": "https://github.com/keplergl/kepler.gl.git"
},
"scripts": {
- "build": "rm -fr dist && babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build": "rm -fr dist && babel src --out-dir dist/cjs --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts' && BABEL_ENV=esm babel src --out-dir dist/esm --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:types": "tsc --project ./tsconfig.production.json",
"prepublishOnly": "babel-node ../../scripts/license-header/bin --license ../../FILE-HEADER && yarn build && yarn build:types",
- "stab": "mkdir -p dist && touch dist/index.js"
+ "stab": "mkdir -p dist/cjs dist/esm && touch dist/cjs/index.js dist/esm/index.js"
},
"files": [
"dist"
@@ -51,5 +51,14 @@
"node": "20.19.3",
"yarn": "4.4.0"
},
- "packageManager": "[email protected]"
+ "packageManager": "[email protected]",
+ "module": "dist/esm/index.js",
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "import": "./dist/esm/index.js",
+ "require": "./dist/cjs/index.js",
+ "default": "./dist/cjs/index.js"
+ }
+ }
}
diff --git a/src/components/babel.config.js b/src/components/babel.config.js
index eb16706b6..3b4d402a3 100644
--- a/src/components/babel.config.js
+++ b/src/components/babel.config.js
@@ -3,21 +3,14 @@
const KeplerPackage = require('./package');
-const PRESETS = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'];
-const PLUGINS = [
+// Plugins shared by both CJS and ESM builds.
+const SHARED_PLUGINS = [
['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}],
- '@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-logical-assignment-operators',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-export-namespace-from',
- [
- '@babel/transform-runtime',
- {
- regenerator: true
- }
- ],
[
'search-and-replace',
{
@@ -30,22 +23,35 @@ const PLUGINS = [
}
]
];
-const ENV = {
- test: {
- plugins: ['istanbul']
- },
- debug: {
- sourceMaps: 'inline',
- retainLines: true
- }
-};
module.exports = function babel(api) {
- api.cache(true);
+ // Cache per BABEL_ENV so that CJS and ESM builds get separate cached results.
+ api.cache.using(() => process.env.BABEL_ENV || process.env.NODE_ENV || 'development');
+
+ const isEsm = api.env('esm');
+ const isTest = api.env('test');
+ const isDebug = api.env('debug');
+
+ // ESM build: modules:false preserves import/export so Vite/esbuild can tree-shake.
+ // CJS build (default / test): transforms import/export to require/module.exports.
+ const presets = [
+ ['@babel/preset-env', isEsm ? {modules: false} : {}],
+ '@babel/preset-react',
+ '@babel/preset-typescript'
+ ];
+
+ const plugins = [
+ ...SHARED_PLUGINS,
+ // CJS and test builds need the CommonJS transform; ESM must omit it.
+ ...(isEsm ? [] : ['@babel/plugin-transform-modules-commonjs']),
+ // Runtime helpers: ESM variant uses ESM imports, no require() calls.
+ ['@babel/transform-runtime', {regenerator: true, ...(isEsm ? {useESModules: true} : {})}],
+ ...(isTest ? ['istanbul'] : [])
+ ];
return {
- presets: PRESETS,
- plugins: PLUGINS,
- env: ENV
+ presets,
+ plugins,
+ ...(isDebug ? {sourceMaps: 'inline', retainLines: true} : {})
};
};
diff --git a/src/components/package.json b/src/components/package.json
index 35a2bba17..a2286c6d7 100644
--- a/src/components/package.json
+++ b/src/components/package.json
@@ -4,7 +4,7 @@
"version": "3.3.0-alpha.5",
"description": "kepler.gl constants used by kepler.gl components, actions and reducers",
"license": "MIT",
- "main": "dist/index.js",
+ "main": "dist/cjs/index.js",
"types": "dist/index.d.ts",
"keywords": [
"babel",
@@ -19,10 +19,10 @@
"url": "https://github.com/keplergl/kepler.gl.git"
},
"scripts": {
- "build": "rm -fr dist && ../../node_modules/.bin/babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build": "rm -fr dist && babel src --out-dir dist/cjs --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts' && BABEL_ENV=esm babel src --out-dir dist/esm --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:types": "tsc --project ./tsconfig.production.json",
"prepublishOnly": "babel-node ../../scripts/license-header/bin --license ../../FILE-HEADER && yarn build && yarn build:types",
- "stab": "mkdir -p dist && touch dist/index.js"
+ "stab": "mkdir -p dist/cjs dist/esm && touch dist/cjs/index.js dist/esm/index.js"
},
"files": [
"dist"
@@ -140,5 +140,20 @@
"node": "20.19.3",
"yarn": "4.4.0"
},
- "packageManager": "[email protected]"
+ "packageManager": "[email protected]",
+ "module": "dist/esm/index.js",
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "import": "./dist/esm/index.js",
+ "require": "./dist/cjs/index.js",
+ "default": "./dist/cjs/index.js"
+ },
+ "./*": {
+ "types": "./dist/*.d.ts",
+ "import": "./dist/esm/*.js",
+ "require": "./dist/cjs/*.js",
+ "default": "./dist/cjs/*.js"
+ }
+ }
}
diff --git a/src/components/src/index.ts b/src/components/src/index.ts
index 437624ae9..a25a53325 100644
--- a/src/components/src/index.ts
+++ b/src/components/src/index.ts
@@ -503,6 +503,7 @@ export {
DROPPABLE_MAP_CONTAINER_TYPE,
SORTABLE_LAYER_TYPE,
SORTABLE_EFFECT_TYPE,
+ SORTABLE_EFFECT_PANEL_TYPE,
SORTABLE_SIDE_PANEL_TYPE,
SORTABLE_LAYER_GROUP_TYPE,
SORTABLE_LAYER_GROUP_DROPPABLE_TYPE,
diff --git a/src/constants/babel.config.js b/src/constants/babel.config.js
index eb16706b6..3b4d402a3 100644
--- a/src/constants/babel.config.js
+++ b/src/constants/babel.config.js
@@ -3,21 +3,14 @@
const KeplerPackage = require('./package');
-const PRESETS = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'];
-const PLUGINS = [
+// Plugins shared by both CJS and ESM builds.
+const SHARED_PLUGINS = [
['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}],
- '@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-logical-assignment-operators',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-export-namespace-from',
- [
- '@babel/transform-runtime',
- {
- regenerator: true
- }
- ],
[
'search-and-replace',
{
@@ -30,22 +23,35 @@ const PLUGINS = [
}
]
];
-const ENV = {
- test: {
- plugins: ['istanbul']
- },
- debug: {
- sourceMaps: 'inline',
- retainLines: true
- }
-};
module.exports = function babel(api) {
- api.cache(true);
+ // Cache per BABEL_ENV so that CJS and ESM builds get separate cached results.
+ api.cache.using(() => process.env.BABEL_ENV || process.env.NODE_ENV || 'development');
+
+ const isEsm = api.env('esm');
+ const isTest = api.env('test');
+ const isDebug = api.env('debug');
+
+ // ESM build: modules:false preserves import/export so Vite/esbuild can tree-shake.
+ // CJS build (default / test): transforms import/export to require/module.exports.
+ const presets = [
+ ['@babel/preset-env', isEsm ? {modules: false} : {}],
+ '@babel/preset-react',
+ '@babel/preset-typescript'
+ ];
+
+ const plugins = [
+ ...SHARED_PLUGINS,
+ // CJS and test builds need the CommonJS transform; ESM must omit it.
+ ...(isEsm ? [] : ['@babel/plugin-transform-modules-commonjs']),
+ // Runtime helpers: ESM variant uses ESM imports, no require() calls.
+ ['@babel/transform-runtime', {regenerator: true, ...(isEsm ? {useESModules: true} : {})}],
+ ...(isTest ? ['istanbul'] : [])
+ ];
return {
- presets: PRESETS,
- plugins: PLUGINS,
- env: ENV
+ presets,
+ plugins,
+ ...(isDebug ? {sourceMaps: 'inline', retainLines: true} : {})
};
};
diff --git a/src/constants/package.json b/src/constants/package.json
index c9a3b4ac3..7cc0948a3 100644
--- a/src/constants/package.json
+++ b/src/constants/package.json
@@ -4,7 +4,7 @@
"version": "3.3.0-alpha.5",
"description": "kepler.gl constants used by kepler.gl components, actions and reducers",
"license": "MIT",
- "main": "dist/index.js",
+ "main": "dist/cjs/index.js",
"types": "dist/index.d.ts",
"keywords": [
"babel",
@@ -19,10 +19,10 @@
"url": "https://github.com/keplergl/kepler.gl.git"
},
"scripts": {
- "build": "rm -fr dist && babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build": "rm -fr dist && babel src --out-dir dist/cjs --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts' && BABEL_ENV=esm babel src --out-dir dist/esm --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:types": "tsc --project ./tsconfig.production.json",
"prepublishOnly": "babel-node ../../scripts/license-header/bin --license ../../FILE-HEADER && yarn build && yarn build:types",
- "stab": "mkdir -p dist && touch dist/index.js"
+ "stab": "mkdir -p dist/cjs dist/esm && touch dist/cjs/index.js dist/esm/index.js"
},
"files": [
"dist"
@@ -61,5 +61,14 @@
"packageManager": "[email protected]",
"devDependencies": {
"@types/d3-time": "^2"
+ },
+ "module": "dist/esm/index.js",
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "import": "./dist/esm/index.js",
+ "require": "./dist/cjs/index.js",
+ "default": "./dist/cjs/index.js"
+ }
}
}
diff --git a/src/deckgl-arrow-layers/babel.config.js b/src/deckgl-arrow-layers/babel.config.js
index eb16706b6..3b4d402a3 100644
--- a/src/deckgl-arrow-layers/babel.config.js
+++ b/src/deckgl-arrow-layers/babel.config.js
@@ -3,21 +3,14 @@
const KeplerPackage = require('./package');
-const PRESETS = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'];
-const PLUGINS = [
+// Plugins shared by both CJS and ESM builds.
+const SHARED_PLUGINS = [
['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}],
- '@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-logical-assignment-operators',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-export-namespace-from',
- [
- '@babel/transform-runtime',
- {
- regenerator: true
- }
- ],
[
'search-and-replace',
{
@@ -30,22 +23,35 @@ const PLUGINS = [
}
]
];
-const ENV = {
- test: {
- plugins: ['istanbul']
- },
- debug: {
- sourceMaps: 'inline',
- retainLines: true
- }
-};
module.exports = function babel(api) {
- api.cache(true);
+ // Cache per BABEL_ENV so that CJS and ESM builds get separate cached results.
+ api.cache.using(() => process.env.BABEL_ENV || process.env.NODE_ENV || 'development');
+
+ const isEsm = api.env('esm');
+ const isTest = api.env('test');
+ const isDebug = api.env('debug');
+
+ // ESM build: modules:false preserves import/export so Vite/esbuild can tree-shake.
+ // CJS build (default / test): transforms import/export to require/module.exports.
+ const presets = [
+ ['@babel/preset-env', isEsm ? {modules: false} : {}],
+ '@babel/preset-react',
+ '@babel/preset-typescript'
+ ];
+
+ const plugins = [
+ ...SHARED_PLUGINS,
+ // CJS and test builds need the CommonJS transform; ESM must omit it.
+ ...(isEsm ? [] : ['@babel/plugin-transform-modules-commonjs']),
+ // Runtime helpers: ESM variant uses ESM imports, no require() calls.
+ ['@babel/transform-runtime', {regenerator: true, ...(isEsm ? {useESModules: true} : {})}],
+ ...(isTest ? ['istanbul'] : [])
+ ];
return {
- presets: PRESETS,
- plugins: PLUGINS,
- env: ENV
+ presets,
+ plugins,
+ ...(isDebug ? {sourceMaps: 'inline', retainLines: true} : {})
};
};
diff --git a/src/deckgl-arrow-layers/package.json b/src/deckgl-arrow-layers/package.json
index fe5bb1290..ead33284b 100644
--- a/src/deckgl-arrow-layers/package.json
+++ b/src/deckgl-arrow-layers/package.json
@@ -4,7 +4,7 @@
"version": "3.3.0-alpha.5",
"description": "Deck.gl layers with GeoArrow and GeoParquet support",
"license": "MIT",
- "main": "dist/index.js",
+ "main": "dist/cjs/index.js",
"types": "dist/index.d.ts",
"keywords": [
"babel",
@@ -19,10 +19,10 @@
"url": "https://github.com/keplergl/kepler.gl.git"
},
"scripts": {
- "build": "rm -fr dist && babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build": "rm -fr dist && babel src --out-dir dist/cjs --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts' && BABEL_ENV=esm babel src --out-dir dist/esm --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:types": "tsc --project ./tsconfig.production.json",
"prepublishOnly": "babel-node ../../scripts/license-header/bin --license ../../FILE-HEADER && yarn build && yarn build:types",
- "stab": "mkdir -p dist && touch dist/index.js"
+ "stab": "mkdir -p dist/cjs dist/esm && touch dist/cjs/index.js dist/esm/index.js"
},
"files": [
"dist"
@@ -59,5 +59,14 @@
"node": "20.19.3",
"yarn": "4.4.0"
},
- "packageManager": "[email protected]"
+ "packageManager": "[email protected]",
+ "module": "dist/esm/index.js",
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "import": "./dist/esm/index.js",
+ "require": "./dist/cjs/index.js",
+ "default": "./dist/cjs/index.js"
+ }
+ }
}
diff --git a/src/deckgl-layers/babel.config.js b/src/deckgl-layers/babel.config.js
index eb16706b6..3b4d402a3 100644
--- a/src/deckgl-layers/babel.config.js
+++ b/src/deckgl-layers/babel.config.js
@@ -3,21 +3,14 @@
const KeplerPackage = require('./package');
-const PRESETS = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'];
-const PLUGINS = [
+// Plugins shared by both CJS and ESM builds.
+const SHARED_PLUGINS = [
['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}],
- '@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-logical-assignment-operators',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-export-namespace-from',
- [
- '@babel/transform-runtime',
- {
- regenerator: true
- }
- ],
[
'search-and-replace',
{
@@ -30,22 +23,35 @@ const PLUGINS = [
}
]
];
-const ENV = {
- test: {
- plugins: ['istanbul']
- },
- debug: {
- sourceMaps: 'inline',
- retainLines: true
- }
-};
module.exports = function babel(api) {
- api.cache(true);
+ // Cache per BABEL_ENV so that CJS and ESM builds get separate cached results.
+ api.cache.using(() => process.env.BABEL_ENV || process.env.NODE_ENV || 'development');
+
+ const isEsm = api.env('esm');
+ const isTest = api.env('test');
+ const isDebug = api.env('debug');
+
+ // ESM build: modules:false preserves import/export so Vite/esbuild can tree-shake.
+ // CJS build (default / test): transforms import/export to require/module.exports.
+ const presets = [
+ ['@babel/preset-env', isEsm ? {modules: false} : {}],
+ '@babel/preset-react',
+ '@babel/preset-typescript'
+ ];
+
+ const plugins = [
+ ...SHARED_PLUGINS,
+ // CJS and test builds need the CommonJS transform; ESM must omit it.
+ ...(isEsm ? [] : ['@babel/plugin-transform-modules-commonjs']),
+ // Runtime helpers: ESM variant uses ESM imports, no require() calls.
+ ['@babel/transform-runtime', {regenerator: true, ...(isEsm ? {useESModules: true} : {})}],
+ ...(isTest ? ['istanbul'] : [])
+ ];
return {
- presets: PRESETS,
- plugins: PLUGINS,
- env: ENV
+ presets,
+ plugins,
+ ...(isDebug ? {sourceMaps: 'inline', retainLines: true} : {})
};
};
diff --git a/src/deckgl-layers/package.json b/src/deckgl-layers/package.json
index c7af3f717..a37ac4e35 100644
--- a/src/deckgl-layers/package.json
+++ b/src/deckgl-layers/package.json
@@ -4,7 +4,7 @@
"version": "3.3.0-alpha.5",
"description": "kepler.gl constants used by kepler.gl components, actions and reducers",
"license": "MIT",
- "main": "dist/index.js",
+ "main": "dist/cjs/index.js",
"types": "dist/index.d.ts",
"keywords": [
"babel",
@@ -19,10 +19,10 @@
"url": "https://github.com/keplergl/kepler.gl.git"
},
"scripts": {
- "build": "rm -fr dist && babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build": "rm -fr dist && babel src --out-dir dist/cjs --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts' && BABEL_ENV=esm babel src --out-dir dist/esm --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:types": "tsc --project ./tsconfig.production.json",
"prepublishOnly": "babel-node ../../scripts/license-header/bin --license ../../FILE-HEADER && yarn build && yarn build:types",
- "stab": "mkdir -p dist && touch dist/index.js"
+ "stab": "mkdir -p dist/cjs dist/esm && touch dist/cjs/index.js dist/esm/index.js"
},
"files": [
"dist"
@@ -75,5 +75,14 @@
"node": "20.19.3",
"yarn": "4.4.0"
},
- "packageManager": "[email protected]"
+ "packageManager": "[email protected]",
+ "module": "dist/esm/index.js",
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "import": "./dist/esm/index.js",
+ "require": "./dist/cjs/index.js",
+ "default": "./dist/cjs/index.js"
+ }
+ }
}
diff --git a/src/duckdb/babel.config.js b/src/duckdb/babel.config.js
index eb16706b6..3b4d402a3 100644
--- a/src/duckdb/babel.config.js
+++ b/src/duckdb/babel.config.js
@@ -3,21 +3,14 @@
const KeplerPackage = require('./package');
-const PRESETS = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'];
-const PLUGINS = [
+// Plugins shared by both CJS and ESM builds.
+const SHARED_PLUGINS = [
['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}],
- '@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-logical-assignment-operators',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-export-namespace-from',
- [
- '@babel/transform-runtime',
- {
- regenerator: true
- }
- ],
[
'search-and-replace',
{
@@ -30,22 +23,35 @@ const PLUGINS = [
}
]
];
-const ENV = {
- test: {
- plugins: ['istanbul']
- },
- debug: {
- sourceMaps: 'inline',
- retainLines: true
- }
-};
module.exports = function babel(api) {
- api.cache(true);
+ // Cache per BABEL_ENV so that CJS and ESM builds get separate cached results.
+ api.cache.using(() => process.env.BABEL_ENV || process.env.NODE_ENV || 'development');
+
+ const isEsm = api.env('esm');
+ const isTest = api.env('test');
+ const isDebug = api.env('debug');
+
+ // ESM build: modules:false preserves import/export so Vite/esbuild can tree-shake.
+ // CJS build (default / test): transforms import/export to require/module.exports.
+ const presets = [
+ ['@babel/preset-env', isEsm ? {modules: false} : {}],
+ '@babel/preset-react',
+ '@babel/preset-typescript'
+ ];
+
+ const plugins = [
+ ...SHARED_PLUGINS,
+ // CJS and test builds need the CommonJS transform; ESM must omit it.
+ ...(isEsm ? [] : ['@babel/plugin-transform-modules-commonjs']),
+ // Runtime helpers: ESM variant uses ESM imports, no require() calls.
+ ['@babel/transform-runtime', {regenerator: true, ...(isEsm ? {useESModules: true} : {})}],
+ ...(isTest ? ['istanbul'] : [])
+ ];
return {
- presets: PRESETS,
- plugins: PLUGINS,
- env: ENV
+ presets,
+ plugins,
+ ...(isDebug ? {sourceMaps: 'inline', retainLines: true} : {})
};
};
diff --git a/src/duckdb/package.json b/src/duckdb/package.json
index 7022da7e3..8779802d3 100644
--- a/src/duckdb/package.json
+++ b/src/duckdb/package.json
@@ -4,23 +4,26 @@
"version": "3.3.0-alpha.5",
"description": "DuckDB plugin for Kepler.gl",
"license": "MIT",
- "main": "dist/index.js",
+ "main": "dist/cjs/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
- "import": "./dist/index.js",
- "require": "./dist/index.js"
+ "import": "./dist/esm/index.js",
+ "require": "./dist/cjs/index.js",
+ "default": "./dist/cjs/index.js"
},
"./components": {
"types": "./dist/components/index.d.ts",
- "import": "./dist/components/index.js",
- "require": "./dist/components/index.js"
+ "import": "./dist/esm/components/index.js",
+ "require": "./dist/cjs/components/index.js",
+ "default": "./dist/cjs/components/index.js"
},
"./table": {
"types": "./dist/table/index.d.ts",
- "import": "./dist/table/index.js",
- "require": "./dist/table/index.js"
+ "import": "./dist/esm/table/index.js",
+ "require": "./dist/cjs/table/index.js",
+ "default": "./dist/cjs/table/index.js"
}
},
"keywords": [
@@ -31,10 +34,10 @@
"url": "https://github.com/keplergl/kepler.gl.git"
},
"scripts": {
- "build": "rm -fr dist && babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build": "rm -fr dist && babel src --out-dir dist/cjs --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts' && BABEL_ENV=esm babel src --out-dir dist/esm --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:types": "tsc --project ./tsconfig.production.json",
"prepublishOnly": "babel-node ../../scripts/license-header/bin --license ../../FILE-HEADER && yarn build && yarn build:types",
- "stab": "mkdir -p dist/components dist/table && echo \"export * from '../src';\" > dist/index.js && echo \"export * from '../../src/components';\" > dist/components/index.js && echo \"export * from '../../src/table';\" > dist/table/index.js"
+ "stab": "mkdir -p dist/cjs/components dist/cjs/table dist/esm/components dist/esm/table && echo \"'use strict'; Object.assign(module.exports, require('../../src'));\" > dist/cjs/index.js && echo \"export * from '../../src';\" > dist/esm/index.js && echo \"'use strict'; Object.assign(module.exports, require('../../../src/components'));\" > dist/cjs/components/index.js && echo \"export * from '../../../src/components';\" > dist/esm/components/index.js && echo \"'use strict'; Object.assign(module.exports, require('../../../src/table'));\" > dist/cjs/table/index.js && echo \"export * from '../../../src/table';\" > dist/esm/table/index.js"
},
"files": [
"dist"
@@ -70,5 +73,6 @@
"node": "20.19.3",
"yarn": "4.4.0"
},
- "packageManager": "[email protected]"
+ "packageManager": "[email protected]",
+ "module": "dist/esm/index.js"
}
diff --git a/src/effects/babel.config.js b/src/effects/babel.config.js
index eb16706b6..3b4d402a3 100644
--- a/src/effects/babel.config.js
+++ b/src/effects/babel.config.js
@@ -3,21 +3,14 @@
const KeplerPackage = require('./package');
-const PRESETS = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'];
-const PLUGINS = [
+// Plugins shared by both CJS and ESM builds.
+const SHARED_PLUGINS = [
['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}],
- '@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-logical-assignment-operators',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-export-namespace-from',
- [
- '@babel/transform-runtime',
- {
- regenerator: true
- }
- ],
[
'search-and-replace',
{
@@ -30,22 +23,35 @@ const PLUGINS = [
}
]
];
-const ENV = {
- test: {
- plugins: ['istanbul']
- },
- debug: {
- sourceMaps: 'inline',
- retainLines: true
- }
-};
module.exports = function babel(api) {
- api.cache(true);
+ // Cache per BABEL_ENV so that CJS and ESM builds get separate cached results.
+ api.cache.using(() => process.env.BABEL_ENV || process.env.NODE_ENV || 'development');
+
+ const isEsm = api.env('esm');
+ const isTest = api.env('test');
+ const isDebug = api.env('debug');
+
+ // ESM build: modules:false preserves import/export so Vite/esbuild can tree-shake.
+ // CJS build (default / test): transforms import/export to require/module.exports.
+ const presets = [
+ ['@babel/preset-env', isEsm ? {modules: false} : {}],
+ '@babel/preset-react',
+ '@babel/preset-typescript'
+ ];
+
+ const plugins = [
+ ...SHARED_PLUGINS,
+ // CJS and test builds need the CommonJS transform; ESM must omit it.
+ ...(isEsm ? [] : ['@babel/plugin-transform-modules-commonjs']),
+ // Runtime helpers: ESM variant uses ESM imports, no require() calls.
+ ['@babel/transform-runtime', {regenerator: true, ...(isEsm ? {useESModules: true} : {})}],
+ ...(isTest ? ['istanbul'] : [])
+ ];
return {
- presets: PRESETS,
- plugins: PLUGINS,
- env: ENV
+ presets,
+ plugins,
+ ...(isDebug ? {sourceMaps: 'inline', retainLines: true} : {})
};
};
diff --git a/src/effects/package.json b/src/effects/package.json
index 6b208a5ea..f53f4e8c2 100644
--- a/src/effects/package.json
+++ b/src/effects/package.json
@@ -4,7 +4,7 @@
"version": "3.3.0-alpha.5",
"description": "kepler.gl viaual effects",
"license": "MIT",
- "main": "dist/index.js",
+ "main": "dist/cjs/index.js",
"types": "dist/index.d.ts",
"keywords": [
"babel",
@@ -19,10 +19,10 @@
"url": "https://github.com/keplergl/kepler.gl.git"
},
"scripts": {
- "build": "rm -fr dist && babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build": "rm -fr dist && babel src --out-dir dist/cjs --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts' && BABEL_ENV=esm babel src --out-dir dist/esm --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:types": "tsc --project ./tsconfig.production.json",
"prepublishOnly": "babel-node ../../scripts/license-header/bin --license ../../FILE-HEADER && yarn build && yarn build:types",
- "stab": "mkdir -p dist && touch dist/index.js"
+ "stab": "mkdir -p dist/cjs dist/esm && touch dist/cjs/index.js dist/esm/index.js"
},
"files": [
"dist"
@@ -57,5 +57,14 @@
"node": "20.19.3",
"yarn": "4.4.0"
},
- "packageManager": "[email protected]"
+ "packageManager": "[email protected]",
+ "module": "dist/esm/index.js",
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "import": "./dist/esm/index.js",
+ "require": "./dist/cjs/index.js",
+ "default": "./dist/cjs/index.js"
+ }
+ }
}
diff --git a/src/layers/babel.config.js b/src/layers/babel.config.js
index eb16706b6..3b4d402a3 100644
--- a/src/layers/babel.config.js
+++ b/src/layers/babel.config.js
@@ -3,21 +3,14 @@
const KeplerPackage = require('./package');
-const PRESETS = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'];
-const PLUGINS = [
+// Plugins shared by both CJS and ESM builds.
+const SHARED_PLUGINS = [
['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}],
- '@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-logical-assignment-operators',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-export-namespace-from',
- [
- '@babel/transform-runtime',
- {
- regenerator: true
- }
- ],
[
'search-and-replace',
{
@@ -30,22 +23,35 @@ const PLUGINS = [
}
]
];
-const ENV = {
- test: {
- plugins: ['istanbul']
- },
- debug: {
- sourceMaps: 'inline',
- retainLines: true
- }
-};
module.exports = function babel(api) {
- api.cache(true);
+ // Cache per BABEL_ENV so that CJS and ESM builds get separate cached results.
+ api.cache.using(() => process.env.BABEL_ENV || process.env.NODE_ENV || 'development');
+
+ const isEsm = api.env('esm');
+ const isTest = api.env('test');
+ const isDebug = api.env('debug');
+
+ // ESM build: modules:false preserves import/export so Vite/esbuild can tree-shake.
+ // CJS build (default / test): transforms import/export to require/module.exports.
+ const presets = [
+ ['@babel/preset-env', isEsm ? {modules: false} : {}],
+ '@babel/preset-react',
+ '@babel/preset-typescript'
+ ];
+
+ const plugins = [
+ ...SHARED_PLUGINS,
+ // CJS and test builds need the CommonJS transform; ESM must omit it.
+ ...(isEsm ? [] : ['@babel/plugin-transform-modules-commonjs']),
+ // Runtime helpers: ESM variant uses ESM imports, no require() calls.
+ ['@babel/transform-runtime', {regenerator: true, ...(isEsm ? {useESModules: true} : {})}],
+ ...(isTest ? ['istanbul'] : [])
+ ];
return {
- presets: PRESETS,
- plugins: PLUGINS,
- env: ENV
+ presets,
+ plugins,
+ ...(isDebug ? {sourceMaps: 'inline', retainLines: true} : {})
};
};
diff --git a/src/layers/package.json b/src/layers/package.json
index f51878c76..7dd3ca793 100644
--- a/src/layers/package.json
+++ b/src/layers/package.json
@@ -4,7 +4,7 @@
"version": "3.3.0-alpha.5",
"description": "kepler.gl constants used by kepler.gl components, actions and reducers",
"license": "MIT",
- "main": "dist/index.js",
+ "main": "dist/cjs/index.js",
"types": "dist/index.d.ts",
"keywords": [
"babel",
@@ -19,10 +19,10 @@
"url": "https://github.com/keplergl/kepler.gl.git"
},
"scripts": {
- "build": "rm -fr dist && babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build": "rm -fr dist && babel src --out-dir dist/cjs --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts' && BABEL_ENV=esm babel src --out-dir dist/esm --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:types": "tsc --project ./tsconfig.production.json",
"prepublishOnly": "babel-node ../../scripts/license-header/bin --license ../../FILE-HEADER && yarn build && yarn build:types",
- "stab": "mkdir -p dist && touch dist/index.js"
+ "stab": "mkdir -p dist/cjs dist/esm && touch dist/cjs/index.js dist/esm/index.js"
},
"files": [
"dist"
@@ -107,5 +107,14 @@
"node": "20.19.3",
"yarn": "4.4.0"
},
- "packageManager": "[email protected]"
+ "packageManager": "[email protected]",
+ "module": "dist/esm/index.js",
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "import": "./dist/esm/index.js",
+ "require": "./dist/cjs/index.js",
+ "default": "./dist/cjs/index.js"
+ }
+ }
}
diff --git a/src/localization/babel.config.js b/src/localization/babel.config.js
index eb16706b6..3b4d402a3 100644
--- a/src/localization/babel.config.js
+++ b/src/localization/babel.config.js
@@ -3,21 +3,14 @@
const KeplerPackage = require('./package');
-const PRESETS = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'];
-const PLUGINS = [
+// Plugins shared by both CJS and ESM builds.
+const SHARED_PLUGINS = [
['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}],
- '@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-logical-assignment-operators',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-export-namespace-from',
- [
- '@babel/transform-runtime',
- {
- regenerator: true
- }
- ],
[
'search-and-replace',
{
@@ -30,22 +23,35 @@ const PLUGINS = [
}
]
];
-const ENV = {
- test: {
- plugins: ['istanbul']
- },
- debug: {
- sourceMaps: 'inline',
- retainLines: true
- }
-};
module.exports = function babel(api) {
- api.cache(true);
+ // Cache per BABEL_ENV so that CJS and ESM builds get separate cached results.
+ api.cache.using(() => process.env.BABEL_ENV || process.env.NODE_ENV || 'development');
+
+ const isEsm = api.env('esm');
+ const isTest = api.env('test');
+ const isDebug = api.env('debug');
+
+ // ESM build: modules:false preserves import/export so Vite/esbuild can tree-shake.
+ // CJS build (default / test): transforms import/export to require/module.exports.
+ const presets = [
+ ['@babel/preset-env', isEsm ? {modules: false} : {}],
+ '@babel/preset-react',
+ '@babel/preset-typescript'
+ ];
+
+ const plugins = [
+ ...SHARED_PLUGINS,
+ // CJS and test builds need the CommonJS transform; ESM must omit it.
+ ...(isEsm ? [] : ['@babel/plugin-transform-modules-commonjs']),
+ // Runtime helpers: ESM variant uses ESM imports, no require() calls.
+ ['@babel/transform-runtime', {regenerator: true, ...(isEsm ? {useESModules: true} : {})}],
+ ...(isTest ? ['istanbul'] : [])
+ ];
return {
- presets: PRESETS,
- plugins: PLUGINS,
- env: ENV
+ presets,
+ plugins,
+ ...(isDebug ? {sourceMaps: 'inline', retainLines: true} : {})
};
};
diff --git a/src/localization/package.json b/src/localization/package.json
index 2532d5ad2..1834e9635 100644
--- a/src/localization/package.json
+++ b/src/localization/package.json
@@ -4,7 +4,7 @@
"version": "3.3.0-alpha.5",
"description": "kepler.gl constants used by kepler.gl components, actions and reducers",
"license": "MIT",
- "main": "dist/index.js",
+ "main": "dist/cjs/index.js",
"types": "dist/index.d.ts",
"keywords": [
"babel",
@@ -19,10 +19,10 @@
"url": "https://github.com/keplergl/kepler.gl.git"
},
"scripts": {
- "build": "rm -fr dist && babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build": "rm -fr dist && babel src --out-dir dist/cjs --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts' && BABEL_ENV=esm babel src --out-dir dist/esm --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:types": "tsc --project ./tsconfig.production.json",
"prepublishOnly": "babel-node ../../scripts/license-header/bin --license ../../FILE-HEADER && yarn build && yarn build:types",
- "stab": "mkdir -p dist && touch dist/index.js"
+ "stab": "mkdir -p dist/cjs dist/esm && touch dist/cjs/index.js dist/esm/index.js"
},
"files": [
"dist"
@@ -49,5 +49,14 @@
"node": "20.19.3",
"yarn": "4.4.0"
},
- "packageManager": "[email protected]"
+ "packageManager": "[email protected]",
+ "module": "dist/esm/index.js",
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "import": "./dist/esm/index.js",
+ "require": "./dist/cjs/index.js",
+ "default": "./dist/cjs/index.js"
+ }
+ }
}
diff --git a/src/processors/babel.config.js b/src/processors/babel.config.js
index eb16706b6..3b4d402a3 100644
--- a/src/processors/babel.config.js
+++ b/src/processors/babel.config.js
@@ -3,21 +3,14 @@
const KeplerPackage = require('./package');
-const PRESETS = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'];
-const PLUGINS = [
+// Plugins shared by both CJS and ESM builds.
+const SHARED_PLUGINS = [
['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}],
- '@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-logical-assignment-operators',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-export-namespace-from',
- [
- '@babel/transform-runtime',
- {
- regenerator: true
- }
- ],
[
'search-and-replace',
{
@@ -30,22 +23,35 @@ const PLUGINS = [
}
]
];
-const ENV = {
- test: {
- plugins: ['istanbul']
- },
- debug: {
- sourceMaps: 'inline',
- retainLines: true
- }
-};
module.exports = function babel(api) {
- api.cache(true);
+ // Cache per BABEL_ENV so that CJS and ESM builds get separate cached results.
+ api.cache.using(() => process.env.BABEL_ENV || process.env.NODE_ENV || 'development');
+
+ const isEsm = api.env('esm');
+ const isTest = api.env('test');
+ const isDebug = api.env('debug');
+
+ // ESM build: modules:false preserves import/export so Vite/esbuild can tree-shake.
+ // CJS build (default / test): transforms import/export to require/module.exports.
+ const presets = [
+ ['@babel/preset-env', isEsm ? {modules: false} : {}],
+ '@babel/preset-react',
+ '@babel/preset-typescript'
+ ];
+
+ const plugins = [
+ ...SHARED_PLUGINS,
+ // CJS and test builds need the CommonJS transform; ESM must omit it.
+ ...(isEsm ? [] : ['@babel/plugin-transform-modules-commonjs']),
+ // Runtime helpers: ESM variant uses ESM imports, no require() calls.
+ ['@babel/transform-runtime', {regenerator: true, ...(isEsm ? {useESModules: true} : {})}],
+ ...(isTest ? ['istanbul'] : [])
+ ];
return {
- presets: PRESETS,
- plugins: PLUGINS,
- env: ENV
+ presets,
+ plugins,
+ ...(isDebug ? {sourceMaps: 'inline', retainLines: true} : {})
};
};
diff --git a/src/processors/package.json b/src/processors/package.json
index 2091586cd..1adb60e3b 100644
--- a/src/processors/package.json
+++ b/src/processors/package.json
@@ -4,7 +4,7 @@
"version": "3.3.0-alpha.5",
"description": "kepler.gl constants used by kepler.gl components, actions and reducers",
"license": "MIT",
- "main": "dist/index.js",
+ "main": "dist/cjs/index.js",
"types": "dist/index.d.ts",
"keywords": [
"babel",
@@ -19,10 +19,10 @@
"url": "https://github.com/keplergl/kepler.gl.git"
},
"scripts": {
- "build": "rm -fr dist && babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build": "rm -fr dist && babel src --out-dir dist/cjs --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts' && BABEL_ENV=esm babel src --out-dir dist/esm --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:types": "tsc --project ./tsconfig.production.json",
"prepublishOnly": "babel-node ../../scripts/license-header/bin --license ../../FILE-HEADER && yarn build && yarn build:types",
- "stab": "mkdir -p dist && touch dist/index.js"
+ "stab": "mkdir -p dist/cjs dist/esm && touch dist/cjs/index.js dist/esm/index.js"
},
"files": [
"dist"
@@ -67,5 +67,14 @@
"node": "20.19.3",
"yarn": "4.4.0"
},
- "packageManager": "[email protected]"
+ "packageManager": "[email protected]",
+ "module": "dist/esm/index.js",
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "import": "./dist/esm/index.js",
+ "require": "./dist/cjs/index.js",
+ "default": "./dist/cjs/index.js"
+ }
+ }
}
diff --git a/src/reducers/babel.config.js b/src/reducers/babel.config.js
index eb16706b6..3b4d402a3 100644
--- a/src/reducers/babel.config.js
+++ b/src/reducers/babel.config.js
@@ -3,21 +3,14 @@
const KeplerPackage = require('./package');
-const PRESETS = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'];
-const PLUGINS = [
+// Plugins shared by both CJS and ESM builds.
+const SHARED_PLUGINS = [
['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}],
- '@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-logical-assignment-operators',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-export-namespace-from',
- [
- '@babel/transform-runtime',
- {
- regenerator: true
- }
- ],
[
'search-and-replace',
{
@@ -30,22 +23,35 @@ const PLUGINS = [
}
]
];
-const ENV = {
- test: {
- plugins: ['istanbul']
- },
- debug: {
- sourceMaps: 'inline',
- retainLines: true
- }
-};
module.exports = function babel(api) {
- api.cache(true);
+ // Cache per BABEL_ENV so that CJS and ESM builds get separate cached results.
+ api.cache.using(() => process.env.BABEL_ENV || process.env.NODE_ENV || 'development');
+
+ const isEsm = api.env('esm');
+ const isTest = api.env('test');
+ const isDebug = api.env('debug');
+
+ // ESM build: modules:false preserves import/export so Vite/esbuild can tree-shake.
+ // CJS build (default / test): transforms import/export to require/module.exports.
+ const presets = [
+ ['@babel/preset-env', isEsm ? {modules: false} : {}],
+ '@babel/preset-react',
+ '@babel/preset-typescript'
+ ];
+
+ const plugins = [
+ ...SHARED_PLUGINS,
+ // CJS and test builds need the CommonJS transform; ESM must omit it.
+ ...(isEsm ? [] : ['@babel/plugin-transform-modules-commonjs']),
+ // Runtime helpers: ESM variant uses ESM imports, no require() calls.
+ ['@babel/transform-runtime', {regenerator: true, ...(isEsm ? {useESModules: true} : {})}],
+ ...(isTest ? ['istanbul'] : [])
+ ];
return {
- presets: PRESETS,
- plugins: PLUGINS,
- env: ENV
+ presets,
+ plugins,
+ ...(isDebug ? {sourceMaps: 'inline', retainLines: true} : {})
};
};
diff --git a/src/reducers/package.json b/src/reducers/package.json
index 1676d3877..24e634877 100644
--- a/src/reducers/package.json
+++ b/src/reducers/package.json
@@ -4,7 +4,7 @@
"version": "3.3.0-alpha.5",
"description": "kepler.gl constants used by kepler.gl components, actions and reducers",
"license": "MIT",
- "main": "dist/index.js",
+ "main": "dist/cjs/index.js",
"types": "dist/index.d.ts",
"keywords": [
"babel",
@@ -19,10 +19,10 @@
"url": "https://github.com/keplergl/kepler.gl.git"
},
"scripts": {
- "build": "rm -fr dist && babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build": "rm -fr dist && babel src --out-dir dist/cjs --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts' && BABEL_ENV=esm babel src --out-dir dist/esm --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:types": "tsc --project ./tsconfig.production.json",
"prepublishOnly": "babel-node ../../scripts/license-header/bin --license ../../FILE-HEADER && yarn build && yarn build:types",
- "stab": "mkdir -p dist && touch dist/index.js"
+ "stab": "mkdir -p dist/cjs dist/esm && touch dist/cjs/index.js dist/esm/index.js"
},
"files": [
"dist"
@@ -79,5 +79,14 @@
"node": "20.19.3",
"yarn": "4.4.0"
},
- "packageManager": "[email protected]"
+ "packageManager": "[email protected]",
+ "module": "dist/esm/index.js",
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "import": "./dist/esm/index.js",
+ "require": "./dist/cjs/index.js",
+ "default": "./dist/cjs/index.js"
+ }
+ }
}
diff --git a/src/schemas/babel.config.js b/src/schemas/babel.config.js
index eb16706b6..3b4d402a3 100644
--- a/src/schemas/babel.config.js
+++ b/src/schemas/babel.config.js
@@ -3,21 +3,14 @@
const KeplerPackage = require('./package');
-const PRESETS = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'];
-const PLUGINS = [
+// Plugins shared by both CJS and ESM builds.
+const SHARED_PLUGINS = [
['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}],
- '@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-logical-assignment-operators',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-export-namespace-from',
- [
- '@babel/transform-runtime',
- {
- regenerator: true
- }
- ],
[
'search-and-replace',
{
@@ -30,22 +23,35 @@ const PLUGINS = [
}
]
];
-const ENV = {
- test: {
- plugins: ['istanbul']
- },
- debug: {
- sourceMaps: 'inline',
- retainLines: true
- }
-};
module.exports = function babel(api) {
- api.cache(true);
+ // Cache per BABEL_ENV so that CJS and ESM builds get separate cached results.
+ api.cache.using(() => process.env.BABEL_ENV || process.env.NODE_ENV || 'development');
+
+ const isEsm = api.env('esm');
+ const isTest = api.env('test');
+ const isDebug = api.env('debug');
+
+ // ESM build: modules:false preserves import/export so Vite/esbuild can tree-shake.
+ // CJS build (default / test): transforms import/export to require/module.exports.
+ const presets = [
+ ['@babel/preset-env', isEsm ? {modules: false} : {}],
+ '@babel/preset-react',
+ '@babel/preset-typescript'
+ ];
+
+ const plugins = [
+ ...SHARED_PLUGINS,
+ // CJS and test builds need the CommonJS transform; ESM must omit it.
+ ...(isEsm ? [] : ['@babel/plugin-transform-modules-commonjs']),
+ // Runtime helpers: ESM variant uses ESM imports, no require() calls.
+ ['@babel/transform-runtime', {regenerator: true, ...(isEsm ? {useESModules: true} : {})}],
+ ...(isTest ? ['istanbul'] : [])
+ ];
return {
- presets: PRESETS,
- plugins: PLUGINS,
- env: ENV
+ presets,
+ plugins,
+ ...(isDebug ? {sourceMaps: 'inline', retainLines: true} : {})
};
};
diff --git a/src/schemas/package.json b/src/schemas/package.json
index ad3eda9f0..053bb33a3 100644
--- a/src/schemas/package.json
+++ b/src/schemas/package.json
@@ -4,7 +4,7 @@
"version": "3.3.0-alpha.5",
"description": "kepler.gl schemas used by kepler.gl components, actions and reducers",
"license": "MIT",
- "main": "dist/index.js",
+ "main": "dist/cjs/index.js",
"types": "dist/index.d.ts",
"keywords": [
"babel",
@@ -19,10 +19,10 @@
"url": "https://github.com/keplergl/kepler.gl.git"
},
"scripts": {
- "build": "rm -fr dist && babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build": "rm -fr dist && babel src --out-dir dist/cjs --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts' && BABEL_ENV=esm babel src --out-dir dist/esm --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:types": "tsc --project ./tsconfig.production.json",
"prepublishOnly": "babel-node ../../scripts/license-header/bin --license ../../FILE-HEADER && yarn build && yarn build:types",
- "stab": "mkdir -p dist && touch dist/index.js"
+ "stab": "mkdir -p dist/cjs dist/esm && touch dist/cjs/index.js dist/esm/index.js"
},
"files": [
"dist"
@@ -59,5 +59,14 @@
"node": "20.19.3",
"yarn": "4.4.0"
},
- "packageManager": "[email protected]"
+ "packageManager": "[email protected]",
+ "module": "dist/esm/index.js",
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "import": "./dist/esm/index.js",
+ "require": "./dist/cjs/index.js",
+ "default": "./dist/cjs/index.js"
+ }
+ }
}
diff --git a/src/styles/babel.config.js b/src/styles/babel.config.js
index eb16706b6..3b4d402a3 100644
--- a/src/styles/babel.config.js
+++ b/src/styles/babel.config.js
@@ -3,21 +3,14 @@
const KeplerPackage = require('./package');
-const PRESETS = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'];
-const PLUGINS = [
+// Plugins shared by both CJS and ESM builds.
+const SHARED_PLUGINS = [
['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}],
- '@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-logical-assignment-operators',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-export-namespace-from',
- [
- '@babel/transform-runtime',
- {
- regenerator: true
- }
- ],
[
'search-and-replace',
{
@@ -30,22 +23,35 @@ const PLUGINS = [
}
]
];
-const ENV = {
- test: {
- plugins: ['istanbul']
- },
- debug: {
- sourceMaps: 'inline',
- retainLines: true
- }
-};
module.exports = function babel(api) {
- api.cache(true);
+ // Cache per BABEL_ENV so that CJS and ESM builds get separate cached results.
+ api.cache.using(() => process.env.BABEL_ENV || process.env.NODE_ENV || 'development');
+
+ const isEsm = api.env('esm');
+ const isTest = api.env('test');
+ const isDebug = api.env('debug');
+
+ // ESM build: modules:false preserves import/export so Vite/esbuild can tree-shake.
+ // CJS build (default / test): transforms import/export to require/module.exports.
+ const presets = [
+ ['@babel/preset-env', isEsm ? {modules: false} : {}],
+ '@babel/preset-react',
+ '@babel/preset-typescript'
+ ];
+
+ const plugins = [
+ ...SHARED_PLUGINS,
+ // CJS and test builds need the CommonJS transform; ESM must omit it.
+ ...(isEsm ? [] : ['@babel/plugin-transform-modules-commonjs']),
+ // Runtime helpers: ESM variant uses ESM imports, no require() calls.
+ ['@babel/transform-runtime', {regenerator: true, ...(isEsm ? {useESModules: true} : {})}],
+ ...(isTest ? ['istanbul'] : [])
+ ];
return {
- presets: PRESETS,
- plugins: PLUGINS,
- env: ENV
+ presets,
+ plugins,
+ ...(isDebug ? {sourceMaps: 'inline', retainLines: true} : {})
};
};
diff --git a/src/styles/package.json b/src/styles/package.json
index 16dd790f7..bdbbd7277 100644
--- a/src/styles/package.json
+++ b/src/styles/package.json
@@ -4,7 +4,7 @@
"version": "3.3.0-alpha.5",
"description": "kepler.gl constants used by kepler.gl components, actions and reducers",
"license": "MIT",
- "main": "dist/index.js",
+ "main": "dist/cjs/index.js",
"types": "dist/index.d.ts",
"keywords": [
"babel",
@@ -19,10 +19,10 @@
"url": "https://github.com/keplergl/kepler.gl.git"
},
"scripts": {
- "build": "rm -fr dist && babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build": "rm -fr dist && babel src --out-dir dist/cjs --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts' && BABEL_ENV=esm babel src --out-dir dist/esm --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:types": "tsc --project ./tsconfig.production.json",
"prepublishOnly": "babel-node ../../scripts/license-header/bin --license ../../FILE-HEADER && yarn build && yarn build:types",
- "stab": "mkdir -p dist && touch dist/index.js"
+ "stab": "mkdir -p dist/cjs dist/esm && touch dist/cjs/index.js dist/esm/index.js"
},
"files": [
"dist"
@@ -49,5 +49,14 @@
"node": "20.19.3",
"yarn": "4.4.0"
},
- "packageManager": "[email protected]"
+ "packageManager": "[email protected]",
+ "module": "dist/esm/index.js",
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "import": "./dist/esm/index.js",
+ "require": "./dist/cjs/index.js",
+ "default": "./dist/cjs/index.js"
+ }
+ }
}
diff --git a/src/table/babel.config.js b/src/table/babel.config.js
index eb16706b6..3b4d402a3 100644
--- a/src/table/babel.config.js
+++ b/src/table/babel.config.js
@@ -3,21 +3,14 @@
const KeplerPackage = require('./package');
-const PRESETS = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'];
-const PLUGINS = [
+// Plugins shared by both CJS and ESM builds.
+const SHARED_PLUGINS = [
['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}],
- '@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-logical-assignment-operators',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-export-namespace-from',
- [
- '@babel/transform-runtime',
- {
- regenerator: true
- }
- ],
[
'search-and-replace',
{
@@ -30,22 +23,35 @@ const PLUGINS = [
}
]
];
-const ENV = {
- test: {
- plugins: ['istanbul']
- },
- debug: {
- sourceMaps: 'inline',
- retainLines: true
- }
-};
module.exports = function babel(api) {
- api.cache(true);
+ // Cache per BABEL_ENV so that CJS and ESM builds get separate cached results.
+ api.cache.using(() => process.env.BABEL_ENV || process.env.NODE_ENV || 'development');
+
+ const isEsm = api.env('esm');
+ const isTest = api.env('test');
+ const isDebug = api.env('debug');
+
+ // ESM build: modules:false preserves import/export so Vite/esbuild can tree-shake.
+ // CJS build (default / test): transforms import/export to require/module.exports.
+ const presets = [
+ ['@babel/preset-env', isEsm ? {modules: false} : {}],
+ '@babel/preset-react',
+ '@babel/preset-typescript'
+ ];
+
+ const plugins = [
+ ...SHARED_PLUGINS,
+ // CJS and test builds need the CommonJS transform; ESM must omit it.
+ ...(isEsm ? [] : ['@babel/plugin-transform-modules-commonjs']),
+ // Runtime helpers: ESM variant uses ESM imports, no require() calls.
+ ['@babel/transform-runtime', {regenerator: true, ...(isEsm ? {useESModules: true} : {})}],
+ ...(isTest ? ['istanbul'] : [])
+ ];
return {
- presets: PRESETS,
- plugins: PLUGINS,
- env: ENV
+ presets,
+ plugins,
+ ...(isDebug ? {sourceMaps: 'inline', retainLines: true} : {})
};
};
diff --git a/src/table/package.json b/src/table/package.json
index 16255cacd..8d25670e6 100644
--- a/src/table/package.json
+++ b/src/table/package.json
@@ -4,7 +4,7 @@
"version": "3.3.0-alpha.5",
"description": "kepler.gl constants used by kepler.gl components, actions and reducers",
"license": "MIT",
- "main": "dist/index.js",
+ "main": "dist/cjs/index.js",
"types": "dist/index.d.ts",
"keywords": [
"babel",
@@ -19,10 +19,10 @@
"url": "https://github.com/keplergl/kepler.gl.git"
},
"scripts": {
- "build": "rm -fr dist && babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build": "rm -fr dist && babel src --out-dir dist/cjs --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts' && BABEL_ENV=esm babel src --out-dir dist/esm --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:types": "tsc --project ./tsconfig.production.json",
"prepublishOnly": "babel-node ../../scripts/license-header/bin --license ../../FILE-HEADER && yarn build && yarn build:types",
- "stab": "mkdir -p dist && touch dist/index.js"
+ "stab": "mkdir -p dist/cjs dist/esm && touch dist/cjs/index.js dist/esm/index.js"
},
"files": [
"dist"
@@ -60,5 +60,14 @@
"node": "20.19.3",
"yarn": "4.4.0"
},
- "packageManager": "[email protected]"
+ "packageManager": "[email protected]",
+ "module": "dist/esm/index.js",
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "import": "./dist/esm/index.js",
+ "require": "./dist/cjs/index.js",
+ "default": "./dist/cjs/index.js"
+ }
+ }
}
diff --git a/src/tasks/babel.config.js b/src/tasks/babel.config.js
index eb16706b6..3b4d402a3 100644
--- a/src/tasks/babel.config.js
+++ b/src/tasks/babel.config.js
@@ -3,21 +3,14 @@
const KeplerPackage = require('./package');
-const PRESETS = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'];
-const PLUGINS = [
+// Plugins shared by both CJS and ESM builds.
+const SHARED_PLUGINS = [
['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}],
- '@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-logical-assignment-operators',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-export-namespace-from',
- [
- '@babel/transform-runtime',
- {
- regenerator: true
- }
- ],
[
'search-and-replace',
{
@@ -30,22 +23,35 @@ const PLUGINS = [
}
]
];
-const ENV = {
- test: {
- plugins: ['istanbul']
- },
- debug: {
- sourceMaps: 'inline',
- retainLines: true
- }
-};
module.exports = function babel(api) {
- api.cache(true);
+ // Cache per BABEL_ENV so that CJS and ESM builds get separate cached results.
+ api.cache.using(() => process.env.BABEL_ENV || process.env.NODE_ENV || 'development');
+
+ const isEsm = api.env('esm');
+ const isTest = api.env('test');
+ const isDebug = api.env('debug');
+
+ // ESM build: modules:false preserves import/export so Vite/esbuild can tree-shake.
+ // CJS build (default / test): transforms import/export to require/module.exports.
+ const presets = [
+ ['@babel/preset-env', isEsm ? {modules: false} : {}],
+ '@babel/preset-react',
+ '@babel/preset-typescript'
+ ];
+
+ const plugins = [
+ ...SHARED_PLUGINS,
+ // CJS and test builds need the CommonJS transform; ESM must omit it.
+ ...(isEsm ? [] : ['@babel/plugin-transform-modules-commonjs']),
+ // Runtime helpers: ESM variant uses ESM imports, no require() calls.
+ ['@babel/transform-runtime', {regenerator: true, ...(isEsm ? {useESModules: true} : {})}],
+ ...(isTest ? ['istanbul'] : [])
+ ];
return {
- presets: PRESETS,
- plugins: PLUGINS,
- env: ENV
+ presets,
+ plugins,
+ ...(isDebug ? {sourceMaps: 'inline', retainLines: true} : {})
};
};
diff --git a/src/tasks/package.json b/src/tasks/package.json
index 496dfcc17..3a0d43a5c 100644
--- a/src/tasks/package.json
+++ b/src/tasks/package.json
@@ -4,7 +4,7 @@
"version": "3.3.0-alpha.5",
"description": "kepler.gl constants used by kepler.gl components, actions and reducers",
"license": "MIT",
- "main": "dist/index.js",
+ "main": "dist/cjs/index.js",
"types": "dist/index.d.ts",
"keywords": [
"babel",
@@ -19,10 +19,10 @@
"url": "https://github.com/keplergl/kepler.gl.git"
},
"scripts": {
- "build": "rm -fr dist && babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build": "rm -fr dist && babel src --out-dir dist/cjs --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts' && BABEL_ENV=esm babel src --out-dir dist/esm --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:types": "tsc --project ./tsconfig.production.json",
"prepublishOnly": "babel-node ../../scripts/license-header/bin --license ../../FILE-HEADER && yarn build && yarn build:types",
- "stab": "mkdir -p dist && touch dist/index.js"
+ "stab": "mkdir -p dist/cjs dist/esm && touch dist/cjs/index.js dist/esm/index.js"
},
"files": [
"dist"
@@ -48,5 +48,14 @@
"node": "20.19.3",
"yarn": "4.4.0"
},
- "packageManager": "[email protected]"
+ "packageManager": "[email protected]",
+ "module": "dist/esm/index.js",
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "import": "./dist/esm/index.js",
+ "require": "./dist/cjs/index.js",
+ "default": "./dist/cjs/index.js"
+ }
+ }
}
diff --git a/src/utils/babel.config.js b/src/utils/babel.config.js
index eb16706b6..3b4d402a3 100644
--- a/src/utils/babel.config.js
+++ b/src/utils/babel.config.js
@@ -3,21 +3,14 @@
const KeplerPackage = require('./package');
-const PRESETS = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'];
-const PLUGINS = [
+// Plugins shared by both CJS and ESM builds.
+const SHARED_PLUGINS = [
['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}],
- '@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-logical-assignment-operators',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-export-namespace-from',
- [
- '@babel/transform-runtime',
- {
- regenerator: true
- }
- ],
[
'search-and-replace',
{
@@ -30,22 +23,35 @@ const PLUGINS = [
}
]
];
-const ENV = {
- test: {
- plugins: ['istanbul']
- },
- debug: {
- sourceMaps: 'inline',
- retainLines: true
- }
-};
module.exports = function babel(api) {
- api.cache(true);
+ // Cache per BABEL_ENV so that CJS and ESM builds get separate cached results.
+ api.cache.using(() => process.env.BABEL_ENV || process.env.NODE_ENV || 'development');
+
+ const isEsm = api.env('esm');
+ const isTest = api.env('test');
+ const isDebug = api.env('debug');
+
+ // ESM build: modules:false preserves import/export so Vite/esbuild can tree-shake.
+ // CJS build (default / test): transforms import/export to require/module.exports.
+ const presets = [
+ ['@babel/preset-env', isEsm ? {modules: false} : {}],
+ '@babel/preset-react',
+ '@babel/preset-typescript'
+ ];
+
+ const plugins = [
+ ...SHARED_PLUGINS,
+ // CJS and test builds need the CommonJS transform; ESM must omit it.
+ ...(isEsm ? [] : ['@babel/plugin-transform-modules-commonjs']),
+ // Runtime helpers: ESM variant uses ESM imports, no require() calls.
+ ['@babel/transform-runtime', {regenerator: true, ...(isEsm ? {useESModules: true} : {})}],
+ ...(isTest ? ['istanbul'] : [])
+ ];
return {
- presets: PRESETS,
- plugins: PLUGINS,
- env: ENV
+ presets,
+ plugins,
+ ...(isDebug ? {sourceMaps: 'inline', retainLines: true} : {})
};
};
diff --git a/src/utils/package.json b/src/utils/package.json
index 2dfe4ee8b..05e7f2f4c 100644
--- a/src/utils/package.json
+++ b/src/utils/package.json
@@ -4,7 +4,7 @@
"version": "3.3.0-alpha.5",
"description": "kepler.gl constants used by kepler.gl components, actions and reducers",
"license": "MIT",
- "main": "dist/index.js",
+ "main": "dist/cjs/index.js",
"types": "dist/index.d.ts",
"keywords": [
"babel",
@@ -19,10 +19,10 @@
"url": "https://github.com/keplergl/kepler.gl.git"
},
"scripts": {
- "build": "rm -fr dist && babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build": "rm -fr dist && babel src --out-dir dist/cjs --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts' && BABEL_ENV=esm babel src --out-dir dist/esm --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:types": "tsc --project ./tsconfig.production.json",
"prepublishOnly": "babel-node ../../scripts/license-header/bin --license ../../FILE-HEADER && yarn build && yarn build:types",
- "stab": "mkdir -p dist && touch dist/index.js"
+ "stab": "mkdir -p dist/cjs dist/esm && touch dist/cjs/index.js dist/esm/index.js"
},
"files": [
"dist"
@@ -80,5 +80,14 @@
"node": "20.19.3",
"yarn": "4.4.0"
},
- "packageManager": "[email protected]"
+ "packageManager": "[email protected]",
+ "module": "dist/esm/index.js",
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "import": "./dist/esm/index.js",
+ "require": "./dist/cjs/index.js",
+ "default": "./dist/cjs/index.js"
+ }
+ }
}
diff --git a/src/utils/src/export-map-html.ts b/src/utils/src/export-map-html.ts
index c79b66347..c6d9558fa 100644
--- a/src/utils/src/export-map-html.ts
+++ b/src/utils/src/export-map-html.ts
@@ -173,7 +173,7 @@ export const exportMapToHTML = (options, version = KEPLER_GL_VERSION) => {
* Provide your MapBox Token
**/
window.MAPBOX_TOKEN = '${options.mapboxApiAccessToken || 'PROVIDE_MAPBOX_TOKEN'}';
- window.WARNING_MESSAGE = 'Please Provide a Mapbox Token in order to use Kepler.gl. Edit this file and fill out MAPBOX_TOKEN with your access key';
+ window.WARNING_MESSAGE = 'No Mapbox token provided. Mapbox basemaps will not be available. To enable them, edit this file and set MAPBOX_TOKEN to your Mapbox access key.';
</script>
<!-- GA: Delete this as you wish, However to pat ourselves on the back, we only track anonymous pageview to understand how many people are using kepler.gl. -->
@@ -210,7 +210,7 @@ export const exportMapToHTML = (options, version = KEPLER_GL_VERSION) => {
<script type="text/kepler-bootstrap">
/* Validate Mapbox Token */
if ((MAPBOX_TOKEN || '') === '' || MAPBOX_TOKEN === 'PROVIDE_MAPBOX_TOKEN') {
- alert(WARNING_MESSAGE);
+ console.warn('[kepler.gl]', WARNING_MESSAGE);
}
/** STORE **/
diff --git a/test/browser/components/hooks/use-dnd-effects.spec.js b/test/browser/components/hooks/use-dnd-effects.spec.js
index 5448e219d..783451d77 100644
--- a/test/browser/components/hooks/use-dnd-effects.spec.js
+++ b/test/browser/components/hooks/use-dnd-effects.spec.js
@@ -8,7 +8,7 @@ import {reorderEffect, updateEffect} from '@kepler.gl/actions';
import {
SORTABLE_EFFECT_PANEL_TYPE,
SORTABLE_EFFECT_TYPE
-} from '@kepler.gl/components/common/dnd-layer-items';
+} from '@kepler.gl/components';
import {reorderEffectOrder} from '@kepler.gl/utils';
// Mock useDispatch hook
diff --git a/test/browser/components/hooks/use-dnd-layers.spec.js b/test/browser/components/hooks/use-dnd-layers.spec.js
index 1d4ea5aaf..743daaf02 100644
--- a/test/browser/components/hooks/use-dnd-layers.spec.js
+++ b/test/browser/components/hooks/use-dnd-layers.spec.js
@@ -9,7 +9,7 @@ import {
DROPPABLE_MAP_CONTAINER_TYPE,
SORTABLE_LAYER_TYPE,
SORTABLE_LAYER_GROUP_DROPPABLE_TYPE
-} from '@kepler.gl/components/common/dnd-layer-items';
+} from '@kepler.gl/components';
import {reorderLayerOrder} from '@kepler.gl/reducers';
jest.mock('react-redux', () => ({