Skip to content

Commit

Permalink
chore: improve npm exports & add .mjs for ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Nov 28, 2024
1 parent bb2dc86 commit 9c76aac
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@
"types": "./dist/types/index.d.ts",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"node": "./dist/cjs/index.js",
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js",
"default": "./dist/esm/index.js"
"import": {
"types": "./dist/types/index.d.ts",
"default": "./dist/esm/index.mjs"
},
"require": {
"types": "./dist/types/index.d.ts",
"default": "./dist/cjs/index.js"
}
},
"./dist/styles/*": "./dist/styles/*",
"./package.json": "./package.json"
},
"module": "./dist/esm/index.js",
"directories": {
"example": "examples",
"test": "tests"
},
"repository": {
"type": "git",
"url": "git+https://github.com/6pac/SlickGrid.git"
},
"keywords": [
"slickgrid",
"grid"
"grid",
"datagrid"
],
"author": "Michael Leibman <[email protected]>",
"contributors": [
Expand Down Expand Up @@ -106,6 +106,6 @@
"not dead"
],
"engines": {
"node": ">=18.0.0"
"node": "^18.0.0"
}
}
11 changes: 7 additions & 4 deletions scripts/builds.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { removeImportsPlugin } from './esbuild-plugins.mjs';
import { outputFileSync } from './fs-utils.mjs';

const argv = yargs(hideBin(process.argv)).argv;
export const BUILD_FORMATS = ['cjs', 'esm'];
export const BUILD_FORMATS = ['cjs', 'esm', 'mjs'];
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const projectRootPath = path.join(__dirname, '../');
Expand Down Expand Up @@ -71,7 +71,7 @@ export async function executeCjsEsmBuilds() {
const startTime = new Date().getTime();
await bundleByFormat(format);
const endTime = new Date().getTime();
console.log(`[${c.yellow('esbuild ⚡')}] Bundled to "${format}" format in ${endTime - startTime}ms`);
console.log(`[${c.yellow('esbuild ⚡')}] Bundled to "${format === 'mjs' ? 'esm (mjs)' : format}" format in ${endTime - startTime}ms`);
}
}

Expand All @@ -80,13 +80,16 @@ export async function executeCjsEsmBuilds() {
* @param {"cjs" | "esm"} format - build format type
*/
export async function bundleByFormat(format) {
const esbuildFormat = format === 'mjs' ? 'esm' : format;
const esbuildExt = format === 'mjs' ? 'mjs' : 'js';

return runBuild({
entryPoints: ['src/index.js'],
format,
format: esbuildFormat,
target: 'es2020',
treeShaking: true,
define: { IIFE_ONLY: 'false' },
outdir: `dist/${format}`,
outfile: `dist/${esbuildFormat}/index.${esbuildExt}`,
});
}

Expand Down

0 comments on commit 9c76aac

Please sign in to comment.