Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rspack-contrib/prebundle
Prebundle Node.js dependencies, output a single js file, a package.json file and the dts files.
https://github.com/rspack-contrib/prebundle
dependencies ncc prebundle webpack
Last synced: 8 days ago
JSON representation
Prebundle Node.js dependencies, output a single js file, a package.json file and the dts files.
- Host: GitHub
- URL: https://github.com/rspack-contrib/prebundle
- Owner: rspack-contrib
- License: mit
- Created: 2024-04-24T09:13:58.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-12-01T01:39:48.000Z (26 days ago)
- Last Synced: 2024-12-11T02:11:55.540Z (16 days ago)
- Topics: dependencies, ncc, prebundle, webpack
- Language: JavaScript
- Homepage:
- Size: 226 KB
- Stars: 21
- Watchers: 4
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Prebundle
Prebundle Node.js dependencies, output a single js file, a package.json file and the dts files.
Based on [ncc](https://github.com/vercel/ncc) and [rollup-plugin-dts](https://www.npmjs.com/package/rollup-plugin-dts).
## Motivation
Prebundle is used to:
- Reduce dependencies of core packages, install faster.
- Improve stability by locking the sub-dependency version .
- Fix peer dependency warning of some packages.## Command
Run following command to prebundle all dependencies:
```bash
npx prebundle
```Run following command to prebundle single dependencies:
```bash
npx prebundle# For example, prebundle commander
npx prebundle commander
```## Dependency Config
Supported dependency config:
### externals
Externals to leave as requires of the build.
```ts
// prebundle.config.mjs
export default {
dependencies: [
{
name: 'foo',
externals: {
webpack: '../webpack',
},
},
],
};
```You can also configure `externals` for all packages like this:
```ts
// prebundle.config.mjs
export default {
externals: {
webpack: '../webpack',
},
dependencies: [{ name: 'foo' }, { name: 'foo' }],
};
```### dtsExternals
Externals for dts.
```ts
// prebundle.config.mjs
export default {
dependencies: [
{
name: 'foo',
dtsExternals: ['webpack'],
},
],
};
```### minify
Whether to minify the code, default `false`.
```ts
// prebundle.config.mjs
export default {
dependencies: [
{
name: 'foo',
minify: false,
},
],
};
```### packageJsonField
Copy extra fields from original package.json to target package.json.
```ts
// prebundle.config.mjs
export default {
dependencies: [
{
name: 'foo',
packageJsonField: ['options'],
},
],
};
```Following fields will be copied by default:
- `name`
- `author`
- `version`
- `funding`
- `license`
- `types`
- `typing`
- `typings`### beforeBundle
Callback before bundle.
```ts
// prebundle.config.mjs
export default {
dependencies: [
{
name: 'foo',
beforeBundle(task) {
console.log('do something');
},
},
],
};
```### emitFiles
Emit extra entry files to map imports.
```ts
// prebundle.config.mjs
export default {
dependencies: [
{
name: 'foo',
emitFiles: [
{
path: 'foo.js',
content: `module.exports = require('./').foo;`,
},
],
},
],
};
```### ignoreDts
Ignore the original .d.ts declaration file, then generate a fake .d.ts file.
This can be used to reduce file size for the packages that do not require type definitions, such as webpack plugin.
```ts
// prebundle.config.mjs
export default {
dependencies: [
{
name: 'foo',
ignoreDts: true,
},
],
};
```### target
Target ECMAScript version, default `es2021`.
```ts
// prebundle.config.mjs
export default {
dependencies: [
{
name: 'foo',
target: 'es2015',
},
],
};
```### prettier
Whether to prettier the code and strip comments, default `false`.
```ts
// prebundle.config.mjs
export default {
prettier: true,
};
```