Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nasriyasoftware/postbuild
PostBuild is a utility pacakge for TypeScript run useful tasks after transpiling TypeScript into ESM and CJS JavaScript file.
https://github.com/nasriyasoftware/postbuild
babel babel-plugin cjs commonjs commonjs-modules ecmascript esm esmodules node nodejs tsc typescript
Last synced: 26 days ago
JSON representation
PostBuild is a utility pacakge for TypeScript run useful tasks after transpiling TypeScript into ESM and CJS JavaScript file.
- Host: GitHub
- URL: https://github.com/nasriyasoftware/postbuild
- Owner: nasriyasoftware
- License: other
- Created: 2024-06-08T06:31:35.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-17T18:48:14.000Z (3 months ago)
- Last Synced: 2024-09-29T02:40:32.091Z (about 1 month ago)
- Topics: babel, babel-plugin, cjs, commonjs, commonjs-modules, ecmascript, esm, esmodules, node, nodejs, tsc, typescript
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/@nasriya/postbuild
- Size: 60.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
[![N|Solid](https://static.wixstatic.com/media/72ffe6_da8d2142d49c42b29c96ba80c8a91a6c~mv2.png)](https://nasriya.net)
# PostBuild.
[![Static Badge](https://img.shields.io/badge/license-Free_(Restricted)-blue)](https://github.com/nasriyasoftware/PostBuild?tab=License-1-ov-file) ![Repository Size](https://img.shields.io/github/repo-size/nasriyasoftware/PostBuild.svg) ![Last Commit](https://img.shields.io/github/last-commit/nasriyasoftware/PostBuild.svg) [![Status](https://img.shields.io/badge/Status-Stable-green.svg)](link-to-your-status-page)
##### Visit us at [www.nasriya.net](https://nasriya.net).PostBuild is a utility pacakge for **TypeScript** that runs useful tasks after transpiling TypeScript into **ESM** and **CJS** JavaScript file.
Made with ❤️ in **Palestine** 🇵🇸
> [!IMPORTANT]
> 🌟 **Support Our Open-Source Development!** 🌟
> We need your support to keep our projects going! If you find our > work valuable, please consider contributing. Your support helps us > continue to develop and maintain these tools.
>
> **[Click here to support us!](https://fund.nasriya.net/)**
>
> Every contribution, big or small, makes a difference. Thank you for > your generosity and support!
___
## Installation
Install the pacakge as a dev. dependency:
```shell
npm i --save-dev @nasriya/postbuild
```## Config File
The `postbuild.configs.json` is the file where all your configurations reside, and is needed to perform the tasks or the build process will fail.If you don't have a file, just run the following command and a file will be generated with recommended configurations:
```shell
npm run postbuild-init
```##### Config File Content
The above comand will generate a file with all the features set to their recommended values. This table below explains them in details.| Property | Description | Posible values | Default value |
| ------------------- | ------------------------------------------------------------------------ | ------------------------ | ------------- |
| `esmDir` | The directory of the generated `ESM` folder. | `auto` or the directory | `auto` |
| `cjsDir` | The directory of the generated `CJS` folder. | `auto` or the directory | `auto` |
| `verbose` | An option to enable logging extra details . | `true` or `false` | `true` |
| `addExtensions` | Appending `.js` to all import statements. | `true` or `false` | `true` |
| `copyFiles` | An options object to copy assets to the `dist` folder after transpiling. | `object` or `undefined` | Notice below |
| `copyFiles.from` | The directory where you want to copy the assets to. | directory | `src` |
| `copyFiles.exclude` | An array of file extensions to exclude. | `string[]` | `['.ts']` |
| `aliases` | Define aliases to your imports | `Record` | Nothing |The default configurations works well if your project is structured like this:
```
├── dist/
│ ├── @types
│ ├── cjs
│ └── esm
├── src
│ ├── folder1
│ ├── folder2
│ ├── folder3
│ └── index.ts
├── package.json
└── README.md
```## Usage
The best way to use this package is to integrate it with your build process by appending the `postbuild` worker to the end of the `build` command:```json
// package.json
{
"scripts": {
"build": "npm run build:esm && npm run build:cjs && postbuild",
"build:esm": "tsc --project tsconfig.esm.json",
"build:cjs": "tsc --project tsconfig.cjs.json",
}
}
```#### Defining aliases
In `postbuild.config.json`, you can add your aliases as such:```json
{
"aliases": {
"my-module": "/modules/my-module",
"@elements/*": "/elements/"
}
}
```#### Using `__dirname`
All `__dirname` matches in `ESM` will be replaced with `import.meta.dirname`, for example:```ts
// TypeScript
const dirname: string = __dirname;
```Will be compiled to:
```js
// CommonJS (CJS)
const dirname = __dirname;
``````js
// ECMAScript Modules (ESM)
const dirname = import.meta.dirname;
```
___
## License
Please read the license from [here](https://github.com/nasriyasoftware/PostBuild?tab=License-1-ov-file).