An open API service indexing awesome lists of open source software.

https://github.com/sunny-117/tiny-webpack

โœจ A JavaScript bundler with Webpack-like features, supporting modern frontend workflows.
https://github.com/sunny-117/tiny-webpack

code codesplitting dynamic-import loader loader-plugin mpa plugins prefetch preload tree-shaking webpack5

Last synced: 2 days ago
JSON representation

โœจ A JavaScript bundler with Webpack-like features, supporting modern frontend workflows.

Awesome Lists containing this project

README

          

# tiny-webpack

[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![bundle][bundle-src]][bundle-href]
[![JSDocs][jsdocs-src]][jsdocs-href]
[![License][license-src]][license-href]

![alt text](./assets/logo.png)

โœจ A JavaScript bundler with Webpack-like features, supporting modern frontend workflows.

๐Ÿ“ฆ Features
----------
- ๐Ÿงฉ **Loader & Plugin System**
- ๐Ÿ•ฐ๏ธ **Lazy Loading & Dynamic Import**
- ๐Ÿ“ฆ **Third-party Module Resolution**
- โœ‚๏ธ **Code Splitting & SplitChunks**
- ๐ŸŒณ **Tree Shaking**
- โšก **Preload/Prefetch Support**
- ๐Ÿƒ **Loader Runner**
- ๐Ÿง  **Multi-page Application (MPA) Support**

๐Ÿš€ Quick Start
-------------
### Installation
```bash
npm install tiny-webpack --save-dev
# or
yarn add tiny-webpack -D
```

### Basic Usage
```javascript
// jspack.config.js
import { resolve } from 'path'

export default {
entry: './src/index.js',
output: {
path: resolve(__dirname, 'dist'),
filename: 'bundle.js'
}
}
// test.js
import { jspack } from 'tiny-webpack'

import jspackOptions from './jspack.config.js'

const compiler = jspack(jspackOptions)
compiler.run((err, stats) => {
console.log(err, stats.toJson())
})
```

โš™๏ธ Configuration Guide
----------------------
### Core Options
| Key | Type | Default | Description |
|-----|------|---------|-------------|
| `entry` | string/object | - | Entry point(s) |
| `output.path` | string | - | Output directory |
| `output.filename` | string | `[name].js` | Output filename pattern |
| `mode` | `development/production` | `development` | Build environment |

### Loader Configuration
```javascript
// handle less file
export default {
module: {
rules: [
{
test: /\.less$/,
use: [
'style-loader',
'less-loader'
]
}
]
}
}
```

### Multi-page Application
```javascript
const HtmlWebpackPlugin = require('html-webpack-plugin')

export default {
entry: {
page1: './src/page1.js',
page2: './src/page2.js'
},
plugins: [
new HtmlWebpackPlugin({
template: './src/template.html',
chunks: ['page1'],
filename: 'page1.html'
})
]
}
```

๐Ÿ”ง Advanced Features
-------------------
### Code Splitting
```javascript
optimization: {
splitChunks: {
chunks: 'all',
minSize: 30000,
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
priority: 10
}
}
}
}
```

### ๆ‡’ๅŠ ่ฝฝ็คบไพ‹
```javascript
// dymamic import
button.addEventListener('click', async () => {
const module = await import('./lazy-module.js')
module.doSomething()
})
```

๐Ÿ“š API Reference
---------------
### Loader Interface
```javascript
// ่‡ชๅฎšไน‰loader็คบไพ‹
export default function (source) {
return `
import { createElement } from 'react'
${source}
`
}
```

### Plugin Development
```javascript
class MyPlugin {
apply(compiler) {
compiler.hooks.emit.tap('MyPlugin', (assets) => {
// handle assets here
})
}
}
```

๐Ÿ“ Project Structure
-------------------
```
project-root/
โ”œโ”€โ”€ src/
โ”‚ โ”œโ”€โ”€ index.js # entry
โ”‚ โ””โ”€โ”€ styles.less # LESS
โ”œโ”€โ”€ loaders/ # custom loader
โ”œโ”€โ”€ jspack.config.js # config
โ””โ”€โ”€ dist/ # output
```

๐Ÿ› ๏ธ Development Guide
-------------------
### custom loader resolver
```javascript
export default {
resolveLoader: {
modules: ['custom_loaders', 'node_modules']
}
}
```

### performance optimization
```javascript
// prefetch example
import(/* webpackPrefetch: true */ './critical-module.js')
```

## Contributing

```shell
pnpm i
pnpm run dev # tsup ็ผ–่ฏ‘ tiny-webpack
cd playground
pnpm build
```

## License

[MIT](./LICENSE) License ยฉ [Sunny-117](https://github.com/Sunny-117)

[npm-version-src]: https://img.shields.io/npm/v/tiny-webpack?style=flat&colorA=080f12&colorB=1fa669
[npm-version-href]: https://npmjs.com/package/tiny-webpack
[npm-downloads-src]: https://img.shields.io/npm/dm/tiny-webpack?style=flat&colorA=080f12&colorB=1fa669
[npm-downloads-href]: https://npmjs.com/package/tiny-webpack
[bundle-src]: https://img.shields.io/bundlephobia/minzip/tiny-webpack?style=flat&colorA=080f12&colorB=1fa669&label=minzip
[bundle-href]: https://bundlephobia.com/result?p=tiny-webpack
[license-src]: https://img.shields.io/github/license/Sunny-117/tiny-webpack.svg?style=flat&colorA=080f12&colorB=1fa669
[license-href]: https://github.com/Sunny-117/tiny-webpack/blob/main/LICENSE
[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
[jsdocs-href]: https://www.jsdocs.io/package/tiny-webpack