-
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.
Merge pull request #43 from euberdeveloper/esm
Esm
- Loading branch information
Showing
102 changed files
with
869 additions
and
1,870 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
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 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 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: { | ||
'../lib/index.js': '../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
Oops, something went wrong.