parcel、rollup、vite、webpack は、現代の Web 開発において JavaScript や CSS、アセットを最適化しバンドルするための主要なツールです。これらは開発サーバーの提供、本番環境向けのコード圧縮、モジュールの結合などを行いますが、設計思想や適用範囲に大きな違いがあります。webpack は高度なカスタマイズ性と豊富なエコシステムを持ち、大規模な既存プロジェクトで広く使われています。vite は ES モジュールを活用した高速な開発サーバーと、本番ビルドに Rollup を採用することで、現代のフレームワーク開発において標準的な選択肢となっています。parcel は設定不要(ゼロコンフィグ)を理念とし、迅速なプロトタイピングや小規模プロジェクトに適しています。rollup は主にライブラリ開発に特化しており、ツリーシェイキングによる軽量な出力を得意としています。
現代のフロントエンド開発において、parcel、rollup、vite、webpack はコードを本番環境向けに最適化する重要なインフラストラクチャです。これらは単にファイルを結合するだけでなく、開発中の体験(DX)や本番のパフォーマンスに直接影響を与えます。それぞれの設計思想を理解し、プロジェクトの要件に合ったツールを選ぶことが、健全なアーキテクチャ構築の第一歩です。
開発中のビルド速度は生産性に直結します。特に大規模プロジェクトでは、サーバー起動待ち時間や変更反映の遅延がストレスになります。
vite は開発サーバーにネイティブ ES モジュールを使用します。
// vite: package.json スクリプト
{
"scripts": {
"dev": "vite",
"build": "vite build"
}
}
webpack は開発時にすべてのモジュールをバンドルします。
webpack-dev-server を使用して HMR を提供します。// webpack: package.json スクリプト
{
"scripts": {
"dev": "webpack serve --mode development",
"build": "webpack --mode production"
}
}
parcel は内部キャッシュと並列処理を最適化しています。
// parcel: package.json スクリプト
{
"scripts": {
"dev": "parcel index.html",
"build": "parcel build index.html"
}
}
rollup は主にライブラリビルド用であり、開発サーバー機能は付属しません。
// rollup: package.json スクリプト(watch モード)
{
"scripts": {
"dev": "rollup -c -w",
"build": "rollup -c"
}
}
ツールの設定負担は、プロジェクトの初期コストやメンテナンス性に影響します。
parcel は原則設定不要です。
.parcelrc は特殊なケースのみ使用します。// parcel: 設定ファイルは通常不要
// 必要であれば .parcelrc
{
"extends": "@parcel/config-default"
}
vite は最小限の設定で済みます。
vite.config.js でプラグインやエイリアスを定義します。// vite: vite.config.js
import { defineConfig } from 'vite'
export default defineConfig({
server: { port: 3000 },
plugins: []
})
webpack は詳細な設定を要求します。
webpack.config.js でエントリー、出力、ローダー、プラグインをすべて定義します。// webpack: webpack.config.js
module.exports = {
entry: './src/index.js',
output: { filename: 'bundle.js' },
module: { rules: [{ test: /\.css$/, use: 'style-loader' }] }
}
rollup は設定が明確で簡潔です。
rollup.config.js で入力と出力フォーマットを指定します。// rollup: rollup.config.js
export default {
input: 'src/index.js',
output: { file: 'dist/bundle.js', format: 'esm' }
}
本番環境では、ファイルサイズの最小化と読み込み速度の最適化が重要です。
vite は本番ビルドに Rollup を使用します。
// vite: build 設定
export default defineConfig({
build: {
rollupOptions: {
output: { manualChunks: { vendor: ['react'] } }
}
}
})
webpack は強力な最適化機能を持ちます。
optimization オブジェクトで細かく制御できます。// webpack: 最適化設定
module.exports = {
optimization: {
minimize: true,
splitChunks: { chunks: 'all' }
}
}
parcel は自動最適化を優先します。
// parcel: package.json で設定
{
"parcel": {
"publicUrl": "/"
}
}
rollup は出力の清潔さを重視します。
// rollup: 圧縮プラグイン使用
import terser from '@rollup/plugin-terser'
export default {
plugins: [terser()]
}
プロジェクトが成長すると、標準機能以外の処理が必要になることがあります。
webpack は最も豊富なプラグインを持っています。
// webpack: プラグイン使用
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
plugins: [new HtmlWebpackPlugin()]
}
vite は Webpack プラグインの多くをサポートします。
// vite: プラグイン使用
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()]
})
parcel はプラグインシステムを持っていますが規模は小さめです。
// parcel: .parcelrc でプラグイン指定
{
"transformers": {
"*.ts": ["@parcel/transformer-typescript-tsc"]
}
}
rollup はプラグインインターフェースがシンプルです。
// rollup: プラグイン使用
import resolve from '@rollup/plugin-node-resolve'
export default {
plugins: [resolve()]
}
ツールの選定は、最終的な成果物が何かによって大きく変わります。
vitewebpack。rolluptsup(内部で Rollup 使用)。parcelvite。webpackvite への移行を検討。| 機能 | vite | webpack | parcel | rollup |
|---|---|---|---|---|
| 主用途 | アプリ開発 | アプリ開発 | プロトタイプ | ライブラリ |
| 開発サーバー | 超高速 (ESM) | 標準 (バンドル) | 高速 (キャッシュ) | なし (Watch) |
| 設定コスト | 低 | 高 | 極低 | 中 |
| 本番ビルド | Rollup ベース | 独自最適化 | 自動最適化 | 高効率 |
| HMR 速度 | 瞬時 | プロジェクト依存 | 高速 | - |
| エコシステム | 成長中 | 最大 | 小規模 | 安定 |
vite は現代の Web アプリケーション開発における標準的な選択肢です。開発体験の良さと本番パフォーマンスのバランスが優れており、React や Vue などのフレームワークを使用する新規プロジェクトでは第一候補となります。
webpack は依然として強力なツールですが、設定の複雑さから、新規プロジェクトでは採用を慎重に検討すべきです。既存の大規模プロジェクトや、特殊なビルド要件がある場合に維持する価値があります。
parcel は設定の手間を省きたい場合や、小さなツールを素早く作りたい場合に便利です。しかし、大規模なアプリケーションの成長に伴う制御性の不足に注意が必要です。
rollup はアプリケーションビルドツールというより、ライブラリ作者のためのツールです。npm パッケージを公開する場合は、これが最適な選択になります。
最終的なアドバイス:新しいアプリを作るなら vite を使い、ライブラリを作るなら rollup を使ってください。webpack は既存プロジェクトの維持か、特別な理由がある場合に残しましょう。parcel は手軽さが必要な時のための便利な道具です。
JavaScript ライブラリやパッケージを配布用にビルドする場合は rollup が最適です。複数のエントリーポイントを持ち、ツリーシェイキングを効かせて軽量なコードを出力する必要がある場合に適しています。アプリケーション全体のビルドツールとしては、通常 Vite の内部で使用されることを前提とします。
新しいフレームワークベースのアプリケーション(Vue、React、Svelte など)を構築する場合は vite を首选します。開発サーバーの起動が瞬時で、ホットモジュール置換(HMR)も高速です。設定はシンプルでありながら、プラグインを通じて拡張性も確保されています。
設定ファイルをほとんど書かずにすぐに始めたい場合に parcel を選びます。複雑なカスタマイズが必要なく、標準的な Web 技術スタックを使用するプロジェクトや、プロトタイプを素早く作成したい時に最適です。ただし、大規模なアプリケーションや細かな制御が必要な場合には限界があります。
既存の大規模プロジェクトや、ローダーやプラグインによる細かな制御が不可欠な場合は webpack を維持または採用します。Webpack 5 は長期サポートされており、複雑なアセット処理やレガシーなブラウザ対応が必要な場合に強力です。ただし、新規プロジェクトでは設定の複雑さを考慮する必要があります。
Rollup is a module bundler for JavaScript which compiles small pieces of code into something larger and more complex, such as a library or application. It uses the standardized ES module format for code, instead of previous idiosyncratic solutions such as CommonJS and AMD. ES modules let you freely and seamlessly combine the most useful individual functions from your favorite libraries. Rollup can optimize ES modules for faster native loading in modern browsers, or output a legacy module format allowing ES module workflows today.
Install with npm install --global rollup. Rollup can be used either through a command line interface with an optional configuration file or else through its JavaScript API. Run rollup --help to see the available options and parameters. The starter project templates, rollup-starter-lib and rollup-starter-app, demonstrate common configuration options, and more detailed instructions are available throughout the user guide.
These commands assume the entry point to your application is named main.js, and that you'd like all imports compiled into a single file named bundle.js.
For browsers:
# compile to a <script> containing a self-executing function
rollup main.js --format iife --name "myBundle" --file bundle.js
For Node.js:
# compile to a CommonJS module
rollup main.js --format cjs --file bundle.js
For both browsers and Node.js:
# UMD format requires a bundle name
rollup main.js --format umd --name "myBundle" --file bundle.js
Developing software is usually easier if you break your project into smaller separate pieces, since that often removes unexpected interactions and dramatically reduces the complexity of the problems you'll need to solve, and simply writing smaller projects in the first place isn't necessarily the answer. Unfortunately, JavaScript has not historically included this capability as a core feature in the language.
This finally changed with ES modules support in JavaScript, which provides a syntax for importing and exporting functions and data so they can be shared between separate scripts. Most browsers and Node.js support ES modules. However, Node.js releases before 12.17 support ES modules only behind the --experimental-modules flag, and older browsers like Internet Explorer do not support ES modules at all. Rollup allows you to write your code using ES modules, and run your application even in environments that do not support ES modules natively. For environments that support them, Rollup can output optimized ES modules; for environments that don't, Rollup can compile your code to other formats such as CommonJS modules, AMD modules, and IIFE-style scripts. This means that you get to write future-proof code, and you also get the tremendous benefits of...
In addition to enabling the use of ES modules, Rollup also statically analyzes and optimizes the code you are importing, and will exclude anything that isn't actually used. This allows you to build on top of existing tools and modules without adding extra dependencies or bloating the size of your project.
For example, with CommonJS, the entire tool or library must be imported.
// import the entire utils object with CommonJS
var utils = require('node:utils');
var query = 'Rollup';
// use the ajax method of the utils object
utils.ajax('https://api.example.com?search=' + query).then(handleResponse);
But with ES modules, instead of importing the whole utils object, we can just import the one ajax function we need:
// import the ajax function with an ES import statement
import { ajax } from 'node:utils';
var query = 'Rollup';
// call the ajax function
ajax('https://api.example.com?search=' + query).then(handleResponse);
Because Rollup includes the bare minimum, it results in lighter, faster, and less complicated libraries and applications. Since this approach is based on explicit import and export statements, it is vastly more effective than simply running an automated minifier to detect unused variables in the compiled output code.
Rollup can import existing CommonJS modules through a plugin.
To make sure your ES modules are immediately usable by tools that work with CommonJS such as Node.js and webpack, you can use Rollup to compile to UMD or CommonJS format, and then point to that compiled version with the main property in your package.json file. If your package.json file also has a module field, ES-module-aware tools like Rollup and webpack will import the ES module version directly.
This project exists thanks to all the people who contribute. [Contribute]. . If you want to contribute yourself, head over to the contribution guidelines.
Thank you to all our backers! 🙏 [Become a backer]
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]
TNG has been supporting the work of Lukas Taegert-Atkinson on Rollup since 2017.