-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: euberdeveloper <euberdeveloper@gmail.com>
- Loading branch information
1 parent
bcbb6aa
commit d1071f1
Showing
3 changed files
with
66 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import fs from 'node:fs'; | ||
import { build } from 'esbuild'; | ||
import * as importMap from "esbuild-plugin-import-map"; | ||
|
||
import packageJson from './package.json' assert { type: 'json' }; | ||
|
||
importMap.load({ | ||
imports: { | ||
'./index': '../lib/esm/index.esm.js' | ||
} | ||
}); | ||
|
||
function getExternalDependencies(allow = []) { | ||
const deps = packageJson.dependencies ? Object.keys(packageJson.dependencies).filter(dep => !allow.includes(dep)) : []; | ||
const peerDeps = packageJson.peerDependencies ? Object.keys(packageJson.peerDependencies).filter(dep => !allow.includes(dep)) : []; | ||
return [...deps, ...peerDeps]; | ||
} | ||
|
||
async function buildModule() { | ||
const shared = { | ||
platform: 'node', | ||
entryPoints: ['source/lib/index.ts'], | ||
bundle: true, | ||
minify: true, | ||
treeShaking: true, | ||
sourcemap: true | ||
}; | ||
|
||
await build({ | ||
...shared, | ||
outfile: 'bundled/lib/commonjs/index.js', | ||
format: 'cjs', | ||
external: getExternalDependencies() | ||
}); | ||
|
||
await build({ | ||
...shared, | ||
outfile: 'bundled/lib/esm/index.esm.js', | ||
format: 'esm', | ||
external: getExternalDependencies() | ||
}); | ||
|
||
await build({ | ||
...shared, | ||
entryPoints: ['source/bin/index.ts'], | ||
outfile: 'bundled/bin/index.js', | ||
format: 'esm', | ||
external: getExternalDependencies(), | ||
plugins: [importMap.plugin()], | ||
define: { | ||
'__VERSION__': `"${packageJson.version}"` | ||
} | ||
}); | ||
} | ||
|
||
function generateCommonjsPackageJson() { | ||
const packageJsonCommonJs = JSON.stringify({ ...packageJson, type: undefined }, null, 2); | ||
fs.writeFileSync('./bundled/lib/commonjs/package.json', packageJsonCommonJs); | ||
} | ||
|
||
await buildModule(); | ||
generateCommonjsPackageJson(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.