Skip to content

Commit

Permalink
Refactor build script & update package.json, readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Gihan Kim committed May 23, 2024
1 parent cf07c4a commit 826e248
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# esbuild-plugin-unused
# esbuild-plugin-unused-modules
esbuild plugin for extracting unused `module` file list.

## Installation
Expand All @@ -10,7 +10,7 @@ npm install -D esbuild-plugin-unused
```typescript
import fs from 'fs';
import { build } from 'esbuild';
import extractUnusedFiles from 'esbuild-plugin-unused';
import extractUnusedFiles from 'esbuild-plugin-unused-modules';

build({
...options,
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "esbuild-plugin-unused",
"name": "esbuild-plugin-unused-modules",
"version": "1.0.0",
"description": "esbuild plugin for finding unused file list",
"main": "build/index.js",
Expand All @@ -14,12 +14,13 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/tridge-hq/esbuild-plugin-unused.git"
"url": "git+https://github.com/tridge-hq/esbuild-plugin-unused-modules.git"
},
"keywords": [
"esbuild",
"plugin",
"unused",
"modules",
"file"
],
"exports": {
Expand All @@ -35,9 +36,9 @@
"author": "Gihan Kim",
"license": "MIT",
"bugs": {
"url": "https://github.com/tridge-hq/esbuild-plugin-unused/issues"
"url": "https://github.com/tridge-hq/esbuild-plugin-unused-modules/issues"
},
"homepage": "https://github.com/tridge-hq/esbuild-plugin-unused#readme",
"homepage": "https://github.com/tridge-hq/esbuild-plugin-unused-modules#readme",
"dependencies": {
"typescript": "^4.0.0"
},
Expand Down
44 changes: 28 additions & 16 deletions scripts/build.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
import path from 'path';
import { build, Format } from 'esbuild';

const formats: Format[] = ['cjs', 'esm'];
const filenameByFormat: Omit<Record<Format, string>, 'iife'> = {
cjs: 'index.js',
esm: 'index.mjs',
};

(async () => {
for (const format of formats) {
await build({
entryPoints: [path.resolve(__dirname, '..', 'src', 'index.ts')],
bundle: true,
platform: 'node',
loader: {
'.ts': 'ts'
},
external: ['path', 'fs', 'typescript'],
outfile: path.resolve(__dirname, '..', 'build', filenameByFormat[format]),
format,
}).catch((e) => {
console.error(e);
});
}
// CommonJS Build
await build({
entryPoints: [path.resolve(__dirname, '..', 'src', 'index.ts')],
bundle: true,
platform: 'node',
loader: {
'.ts': 'ts'
},
external: ['path', 'fs', 'typescript'],
outfile: path.resolve(__dirname, '..', 'build', filenameByFormat['cjs']),
format: 'cjs',
}).catch((e) => {
console.error(e);
});
// ESModule Build
await build({
entryPoints: [path.resolve(__dirname, '..', 'src', 'index.ts')],
bundle: true,
platform: 'node',
loader: {
'.ts': 'ts'
},
external: ['path', 'fs', 'typescript'],
outfile: path.resolve(__dirname, '..', 'build', filenameByFormat['esm']),
format: 'esm',
}).catch((e) => {
console.error(e);
});
})();

0 comments on commit 826e248

Please sign in to comment.