parcel 2.0.0-beta.3.1 → 2.0.0-dev.1513

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. package/README.md +36 -1510
  2. package/lib/cli.js +80 -144
  3. package/package.json +16 -15
  4. package/src/bin.js +4 -1
  5. package/src/cli.js +64 -38
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  <p align="center">
2
2
  <a href="https://parceljs.org/" target="_blank">
3
- <img alt="Parcel" src="https://user-images.githubusercontent.com/19409/31321658-f6aed0f2-ac3d-11e7-8100-1587e676e0ec.png" width="749">
3
+ <img alt="Parcel" src="https://user-images.githubusercontent.com/19409/135924939-03845d0b-e7bb-414b-89b6-e627dfa9f614.png" width="749">
4
4
  </a>
5
5
  </p>
6
6
 
@@ -8,1533 +8,59 @@
8
8
  [![Build Status](https://dev.azure.com/devongovett/devongovett/_apis/build/status/parcel-bundler.parcel?branchName=v2)](https://dev.azure.com/devongovett/devongovett/_build/latest?definitionId=1)
9
9
  [![npm package](https://img.shields.io/npm/v/parcel.svg)](https://www.npmjs.com/package/parcel)
10
10
  [![npm package](https://img.shields.io/npm/dm/parcel.svg)](https://www.npmjs.com/package/parcel)
11
+ [![Discord](https://img.shields.io/discord/894288336095690753)](https://discord.gg/XSCzqGRuvr)
11
12
  [![Twitter Follow](https://img.shields.io/twitter/follow/parceljs.svg?style=social)](https://twitter.com/parceljs)
12
13
 
13
- ## Features
14
-
15
- - 🚀 **Blazing fast** bundle times - multicore compilation, and a filesystem cache for fast rebuilds even after a restart.
16
- - 📦 Out of the box support for JS, CSS, HTML, file assets, and more - **no plugins to install**.
17
- - 🐠 **Automatically transforms modules** using Babel, PostCSS, and PostHTML when needed - even `node_modules`.
18
- - ✂️ Zero configuration **code splitting** using dynamic `import()` statements.
19
- - 🔥 Built in support for **hot module replacement**
20
- - 🚨 Friendly error logging experience - syntax highlighted code frames help pinpoint the problem.
21
-
22
-
23
- ---
24
-
25
- **Below is the design document that was created before work on the implementation of Parcel 2 started and some sections are outdated. The actual (somewhat complete) documentation for Parcel 2 is available here: https://v2.parceljs.org/.**
14
+ Parcel is a zero configuration build tool for the web. It combines a great out-of-the-box development experience with a scalable architecture that can take your project from just getting started to massive production application.
26
15
 
16
+ ## Features
27
17
 
28
- ----
18
+ - 😍 **Zero config** – Parcel supports many languages and file types out of the box, from web technologies like HTML, CSS, and JavaScript, to assets like images, fonts, videos, and more. It has a built-in dev server with hot reloading, beautiful error diagnostics, and much more. No configuration needed!
19
+ - ⚡️ **Lightning fast** – Parcel's JavaScript compiler is written in Rust for native performance. Your code is built in parallel using worker threads, utilizing all of the cores on your machine. Everything is cached, so you never build the same code twice. It's like using watch mode, but even when you restart Parcel!
20
+ - 🚀 **Automatic production optimization** – Parcel optimizes your whole app for production automatically. This includes tree-shaking and minifying your JavaScript, CSS, and HTML, resizing and optimizing images, content hashing, automatic code splitting, and much more.
21
+ - 🎯 **Ship for any target** – Parcel automatically transforms your code for your target environments. From modern and legacy browser support, to zero config JSX and TypeScript compilation, Parcel makes it easy to build for any target – or many!
22
+ - 🌍 **Scalable** – Parcel requires zero configuration to get started. But as your application grows and your build requirements become more complex, it's possible to extend Parcel in just about every way. A simple configuration format and powerful plugin system that's designed from the ground up for performance means Parcel can support projects of any size.
29
23
 
30
24
  ## Getting Started
31
25
 
32
- Before we get started, you'll need to install Node and Yarn (or npm) and create
33
- a `package.json` for your project if you haven't already.
34
-
35
- ```sh
36
- yarn init
37
- ```
38
-
39
- Then with Yarn you can install `parcel` into your app:
40
-
41
- ```sh
42
- yarn add --dev parcel@next
43
- ```
44
-
45
- From there you just need to point Parcel at some of your entry files. Like if
46
- you're building a website, an `index.html` file:
47
-
48
- ```html
49
- <!DOCTYPE html>
50
- <html lang="en">
51
- <head>
52
- <meta charset="utf-8" />
53
- <title>My First Parcel App</title>
54
- </head>
55
- <body>
56
- <h1>Hello, World!</h1>
57
- </body>
58
- </html>
59
- ```
60
-
61
- Now if you just run:
26
+ See the following guides in our documentation on how to get started with Parcel.
62
27
 
63
- ```sh
64
- yarn parcel index.html
65
- ```
66
-
67
- You should get a URL that looks something like: `http://localhost:1234/`.
68
-
69
- Next you can start adding dependencies by specifying them in your code (however
70
- your language specifies other assets). So for HTML we could create a
71
- `styles.css` file next to our `index.html` file and include it with a `<link>`
72
- tag.
73
-
74
- ```css
75
- h1 {
76
- color: hotpink;
77
- font-family: cursive;
78
- }
79
- ```
80
-
81
- ```html
82
- <!DOCTYPE html>
83
- <html lang="en">
84
- <head>
85
- <meta charset="utf-8" />
86
- <title>My First Parcel App</title>
87
- <link rel="stylesheet" href="./styles.css" />
88
- </head>
89
- <body>
90
- <h1>Hello, World!</h1>
91
- </body>
92
- </html>
93
- ```
94
-
95
- If we want parcel to update our changes in the browser without refreshing the page,
96
- we need to add at least a dummy javascript file e.g. `app.js` next to our `index.html`.
97
- This file allows parcel to inject all the necessary code to show your changes.
98
- This file will later contain your javascript application.
99
-
100
- ```javascript
101
- console.log("Hello World");
102
- ```
103
-
104
- ```html
105
- <!DOCTYPE html>
106
- <html lang="en">
107
- <head>
108
- <meta charset="utf-8" />
109
- <title>My First Parcel App</title>
110
- <link rel="stylesheet" href="./styles.css" />
111
- <script src="./app.js"></script>
112
- </head>
113
- <body>
114
- <h1>Hello, World!</h1>
115
- </body>
116
- </html>
117
- ```
28
+ * [Building a webapp with Parcel](https://parceljs.org/getting-started/webapp/)
29
+ * [Building a library with Parcel](https://parceljs.org/getting-started/library/)
30
+ * [Migrating from Parcel v1](https://parceljs.org/getting-started/migration/)
118
31
 
119
32
  ## Documentation
120
33
 
121
- <!-- START doctoc generated TOC please keep comment here to allow auto update -->
122
- <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
123
-
124
-
125
- - [Introduction](#introduction)
126
- - [Parcel CLI](#parcel-cli)
127
- - [CLI Args & Flags](#cli-args--flags)
128
- - [`parcel serve`](#parcel-serve)
129
- - [`parcel watch`](#parcel-watch)
130
- - [`parcel build`](#parcel-build)
131
- - [`[...entries]`](#entries)
132
- - [`--target [name]`](#--target-name)
133
- - [`--open, -o [browser]`](#--open--o-browser)
134
- - [`--host <host>`](#--host-host)
135
- - [`--port <port>, -p`](#--port-port--p)
136
- - [`--https`](#--https)
137
- - [`--cert <path>`](#--cert-path)
138
- - [`--key <path>`](#--key-path)
139
- - [`--dist-dir <dir>`](#--dist-dir-dir)
140
- - [`--cache-dir <dir>`, `--no-cache`](#--cache-dir-dir---no-cache)
141
- - [`--hot`, `--no-hot`](#--hot---no-hot)
142
- - [`--hot-host <hostname>`](#--hot-host-hostname)
143
- - [`--hot-port <port>`](#--hot-port-port)
144
- - [`--[no-]source-maps`](#--no-source-maps)
145
- - [`--autoinstall [npm/yarn], --no-autoinstall`](#--autoinstall-npmyarn---no-autoinstall)
146
- - [`--log-level <level>`](#--log-level-level)
147
- - [`--version, -v, -V`](#--version--v--v)
148
- - [`--help, -h`](#--help--h)
149
- - [Parcel Config](#parcel-config)
150
- - [Configuring external tools](#configuring-external-tools)
151
- - [Configuring Parcel](#configuring-parcel)
152
- - [`package.json`](#packagejson)
153
- - [`package.json#name`](#packagejsonname)
154
- - [`package.json#version`](#packagejsonversion)
155
- - [`package.json#main`](#packagejsonmain)
156
- - [`package.json#module`](#packagejsonmodule)
157
- - [`package.json#browser`](#packagejsonbrowser)
158
- - [`package.json#source`](#packagejsonsource)
159
- - [`package.json#browserslist`](#packagejsonbrowserslist)
160
- - [`package.json#engines`](#packagejsonengines)
161
- - [`package.json#targets`](#packagejsontargets)
162
- - [`package.json#alias`](#packagejsonalias)
163
- - [`.parcelrc`](#parcelrc)
164
- - [Glob maps in `.parcelrc`](#glob-maps-in-parcelrc)
165
- - [`.parcelrc#extends`](#parcelrcextends)
166
- - [`.parcelrc#resolvers`](#parcelrcresolvers)
167
- - [`.parcelrc#transformers`](#parcelrctransformers)
168
- - [`.parcelrc#bundler`](#parcelrcbundler)
169
- - [`.parcelrc#namers`](#parcelrcnamers)
170
- - [`.parcelrc#runtimes`](#parcelrcruntimes)
171
- - [`.parcelrc#packagers`](#parcelrcpackagers)
172
- - [`.parcelrc#optimizers`](#parcelrcoptimizers)
173
- - [`.parcelrc#reporters`](#parcelrcreporters)
174
- - [`.parcelrc#validators`](#parcelrcvalidators)
175
- - [Parcel Architecture](#parcel-architecture)
176
- - [Phases of Parcel](#phases-of-parcel)
177
- - [Asset Graph](#asset-graph)
178
- - [Bundles](#bundles)
179
- - [Sources](#sources)
180
- - [Targets](#targets)
181
- - [Target Configuration](#target-configuration)
182
- - [Environments](#environments)
183
- - [Caching](#caching)
184
- - [Asset Resolution](#asset-resolution)
185
- - [Local Paths](#local-paths)
186
- - [Package Paths](#package-paths)
187
- - [URLs](#urls)
188
- - [Tilde Paths](#tilde-paths)
189
- - [Aliases](#aliases)
190
- - [Plugins](#plugins)
191
- - [Resolvers](#resolvers)
192
- - [Transformers](#transformers)
193
- - [Bundlers](#bundlers)
194
- - [Namers](#namers)
195
- - [Runtimes](#runtimes)
196
- - [Packagers](#packagers)
197
- - [Optimizers](#optimizers)
198
- - [Reporters](#reporters)
199
- - [Validators](#validators)
200
- - [Creating Plugins](#creating-plugins)
201
- - [Naming](#naming)
202
- - [Versioning](#versioning)
203
- - [Engines](#engines)
204
- - [Plugin APIs](#plugin-apis)
205
- - [Resolvers](#resolvers-1)
206
- - [Transformers](#transformers-1)
207
- - [Bundler](#bundler)
208
- - [Namers](#namers-1)
209
- - [Runtimes](#runtimes-1)
210
- - [Packagers](#packagers-1)
211
- - [Optimizers](#optimizers-1)
212
- - [Reporters](#reporters-1)
213
- - [Validators](#validators-1)
214
-
215
- <!-- END doctoc generated TOC please keep comment here to allow auto update -->
216
-
217
- ## Introduction
218
-
219
- Parcel is a compiler for all your code, regardless of the language or toolchain.
220
-
221
- Parcel takes all of your files and dependencies, transforms them, and merges
222
- them together into a smaller set of output files that can be used to run your
223
- code.
224
-
225
- Parcel supports many different languages and file types out of the box, from
226
- web technologies like HTML, CSS, and JavaScript, to lower level languages like
227
- Rust, and anything that compiles to WebAssembly (WASM), to assets like images,
228
- fonts, videos, and more.
229
-
230
- Parcel makes your code portable. You can build your code for different
231
- environments, for the web for your server, or for an app. You can even build
232
- multiple targets at once and have them live update as you make changes.
233
-
234
- Parcel is fast and predictable. It compiles all of your files in isolation in
235
- parallel inside workers, caching all of them as it goes along. Caches are
236
- stable across machines and are only affected by the files and configs within
237
- your project (unless you want to pass specific environment variables).
238
-
239
- ## Parcel CLI
240
-
241
- The Parcel CLI is built into the main `parcel` package. While you can install
242
- it globally and run it, it is much better to install it locally into your
243
- project as a dev dependency.
244
-
245
- ```sh
246
- yarn add --dev parcel@next
247
- ```
248
-
249
- You should also add some "scripts" to your `package.json` to run it easier.
250
-
251
- ```json
252
- {
253
- "name": "my-project",
254
- "scripts": {
255
- "build": "parcel build index.html",
256
- "start": "parcel serve index.html"
257
- },
258
- "devDependencies": {
259
- "parcel": "latest"
260
- }
261
- }
262
- ```
263
-
264
- Now you can run `yarn build` to bundle your project for production and
265
- `yarn start` to dev on your project.
266
-
267
- ### CLI Args & Flags
268
-
269
- Usage:
270
-
271
- ```sh
272
- $ parcel [command] [...entries] [...flags]
273
- ```
274
-
275
- #### `parcel serve`
276
-
277
- Serve assets on a local server.
278
-
279
- #### `parcel watch`
280
-
281
- Watch and rebuild code on file changes.
282
-
283
- #### `parcel build`
284
-
285
- Build code once, in production mode.
286
-
287
- #### `[...entries]`
288
-
289
- Entry files to start bundling, these will be preserved as entry points in the
290
- output. Defaults to `package.json#source`, falling back to `src/index.*` or
291
- `index.*`. See [#Sources](#sources).
292
-
293
- #### `--target [name]`
294
-
295
- Specifies a specific target to build. If unspecified, Parcel builds all
296
- targets specified in package.json. See [#Targets](#targets).
297
-
298
- #### `--open, -o [browser]`
299
-
300
- Open your local server in a browser. You can optionally pass the name of the
301
- browser you want to open, otherwise it will use your default browser.
302
-
303
- #### `--host <host>`
304
-
305
- Configure the host to serve assets on. The default is to listen on all interfaces.
306
-
307
- #### `--port <port>, -p`
308
-
309
- Configure the port to serve assets on. Alternatively you can use the `$PORT`
310
- environment variable.
311
-
312
- #### `--https`
313
-
314
- This will generate a local certificate (which will be untrusted by your
315
- browser, you'll need to approve it) and serve your assets over `https://`
316
-
317
- ##### `--cert <path>`
318
-
319
- Specify the filepath to your SSL certificate when using `--https`.
320
-
321
- ##### `--key <path>`
322
-
323
- Specify the filepath to your SSL key when using `--https`.
324
-
325
- #### `--dist-dir <dir>`
326
-
327
- Configure the directory where compiled assets are output. Default is `./dist`.
328
-
329
- #### `--cache-dir <dir>`, `--no-cache`
330
-
331
- Configure the cache directory with `--cache <dir>` or disable it altogether
332
- with `--no-cache`.
333
-
334
- #### `--hot`, `--no-hot`
335
-
336
- Turn hot reloading on or off.
337
-
338
- ##### `--hot-host <hostname>`
339
-
340
- Configure the hot reloading hostname.
341
-
342
- ##### `--hot-port <port>`
343
-
344
- Configure the hot reloading port.
345
-
346
- #### `--[no-]source-maps`
347
-
348
- Turn source maps on or off. Source maps are turned on by default.
349
-
350
- #### `--autoinstall [npm/yarn], --no-autoinstall`
351
-
352
- When enabled, whenever Parcel discovers a dependency that isn't installed it
353
- will attempt to install it with either npm or Yarn (defaults to npm unless a
354
- `yarn.lock` exists).
355
-
356
- #### `--log-level <level>`
357
-
358
- Set the log level, either either "none", "error", "warn", "info", or "verbose".
359
- The default is "info".
360
-
361
- #### `--version, -v, -V`
362
-
363
- Return the current version of Parcel.
364
-
365
- #### `--help, -h`
366
-
367
- Get help with the CLI.
368
-
369
- ## Parcel Config
370
-
371
- Parcel has always and will always work out of the box for many projects with
372
- zero configuration. It should always be extremely simple to get started. But if
373
- you do want more control, we give you the tools to do so.
374
-
375
- ### Configuring external tools
376
-
377
- A huge part of what Parcel does is run other tools over your code. Instead of
378
- pulling all that configuration into Parcel, we make use of their own
379
- configuration systems. So if you're using Babel, you should just use `.babelrc`
380
- files to configure it.
381
-
382
- When we do need to introduce config, we create tool specific config files in
383
- order to do so.
384
-
385
- ### Configuring Parcel
386
-
387
- When you do need to configure Parcel, it will be in one of 3 places.
388
-
389
- - If you need to configure the CLI, it will be a CLI flag
390
- - If you need to configure your package, it will be in the `package.json`
391
- - If you need to configure something with your files or the Parcel asset
392
- pipeline, it will be in `.parcelrc`
393
-
394
- ### `package.json`
395
-
396
- [todo]
397
-
398
- ```json
399
- {
400
- "name": "foo",
401
- "main": "dist/main/index.js",
402
- "module": "dist/module/index.js",
403
- "browser": "dist/browser/index.js",
404
- "browserslist": ["> 1%", "not dead"],
405
- "engines": {
406
- "node": ">=4.x"
407
- },
408
- "source": "src/index.js",
409
- "targets": {
410
- "main": {
411
- "engines": {
412
- "node": ">=4.x"
413
- }
414
- },
415
- "module": {
416
- "engines": {
417
- "node": ">=8.x"
418
- }
419
- },
420
- "browser": {
421
- "engines": {
422
- "browsers": ["> 1%", "not dead"]
423
- }
424
- }
425
- },
426
- "alias": {
427
- "react": "preact-compat",
428
- "react-dom": "preact-compat"
429
- }
430
- }
431
- ```
432
-
433
- #### `package.json#name`
434
-
435
- **(Required)** The name of the package is always required in order to be
436
- considered a valid `package.json`.
437
-
438
- ```json
439
- {
440
- "name": "my-package"
441
- }
442
- ```
443
-
444
- #### `package.json#version`
445
-
446
- **(Required)** All packages inside `node_modules` must have a `package.json#version`.
447
-
448
- ```json
449
- {
450
- "version": "1.0.0"
451
- }
452
- ```
453
-
454
- #### `package.json#main`
455
-
456
- This is the "main" target's entry point for the package, by default in library mode (doesn't bundle dependencies).
457
-
458
- ```json
459
- {
460
- "main": "dist/main/index.js"
461
- }
462
- ```
463
-
464
- See [Targets](#targets)
465
-
466
- #### `package.json#module`
467
-
468
- This is the "module" target's entry point for the package, by default in library mode (doesn't bundle dependencies).
469
-
470
- ```json
471
- {
472
- "module": "dist/module/index.js"
473
- }
474
- ```
475
-
476
- See [Targets](#targets)
477
-
478
- #### `package.json#browser`
479
-
480
- This is the "browser" target's entry point for the package, by default in library mode (doesn't bundle dependencies).
481
-
482
- ```json
483
- {
484
- "browser": "dist/browser/index.js"
485
- }
486
- ```
487
-
488
- See [Targets](#targets)
489
-
490
- #### `package.json#source`
491
-
492
- Specify the entry points for your source code which gets mapped to your
493
- targets.
494
-
495
- ```json
496
- {
497
- "source": "src/index.js",
498
- "source": ["src/index.js", "src/index.html"]
499
- }
500
- ```
501
-
502
- See [Sources](#sources)
503
-
504
- #### `package.json#browserslist`
505
-
506
- As specified by Browserslist, this field is for specifying which transformers
507
- should be applied to browser bundles.
508
-
509
- ```json
510
- {
511
- "browserslist": ["> 0.2%", "not dead"]
512
- }
513
- ```
514
-
515
- See [Environments](#environments)
516
-
517
- #### `package.json#engines`
518
-
519
- Specify what versions of what engines you want to support.
520
-
521
- ```json
522
- {
523
- "engines": {
524
- "node": ">=4.x",
525
- "electron": ">=2.x"
526
- }
527
- }
528
- ```
529
-
530
- See [Environments](#environments)
531
-
532
- #### `package.json#targets`
533
-
534
- Configuration for individual targets.
535
-
536
- ```json
537
- {
538
- "targets": {
539
- "main": {
540
- "engines": {
541
- "node": ">=4.x",
542
- "electron": ">=2.x"
543
- },
544
- },
545
- "browser": {
546
- "engines": {
547
- "browsers": ["> 1%", "not dead"]
548
- }
549
- }
550
- }
551
- }
552
- ```
553
-
554
- See [Targets](#targets)
555
-
556
- #### `package.json#alias`
557
-
558
- Aliases asset names/paths to other assets.
559
-
560
- ```json
561
- {
562
- "alias": {
563
- "react": "preact-compat",
564
- "react-dom": "preact-compat"
565
- }
566
- }
567
- ```
568
-
569
- See [Aliases](#aliases)
570
-
571
- ### `.parcelrc`
572
-
573
- Your `.parcelrc` file will likely contain just a few fields (if you have one at
574
- all), but here's an example of a `.parcelrc` file that contains every field:
575
-
576
- ```json
577
- {
578
- "extends": ["@parcel/config-default"],
579
- "resolvers": ["@parcel/resolver-default"],
580
- "transformers": {
581
- "*.vue": ["@parcel/transformer-vue"],
582
- "*.scss": ["@parcel/transformer-sass"],
583
- "*.js": ["@parcel/transformer-babel"],
584
- "*.css": ["@parcel/transformer-postcss"],
585
- "*.html": ["@parcel/transformer-posthtml"]
586
- },
587
- "bundler": "@parcel/bundler-default",
588
- "namers": ["@parcel/namer-default"],
589
- "runtimes": ["@parcel/runtime-js", "@parcel/runtime-browser-hmr"],
590
- "packagers": {
591
- "*.js": "@parcel/packager-js",
592
- "*.css": "@parcel/packager-css",
593
- "*.html": "@parcel/packager-html",
594
- "*.wasm": "@parcel/packager-wasm",
595
- "*.raw": "@parcel/packager-raw"
596
- },
597
- "optimizers": {
598
- "*.js": ["@parcel/optimizer-uglify"],
599
- "*.css": ["@parcel/optimizer-cssnano"],
600
- "*.html": ["@parcel/optimizer-htmlnano"],
601
- "*.{png,jpg,jpeg,svg,...}": ["@parcel/optimizer-imagemin"]
602
- },
603
- "reporters": ["@parcel/reporter-cli"]
604
- }
605
- ```
606
-
607
- #### Glob maps in `.parcelrc`
608
-
609
- Many config properties like `transformers` or `packagers` use objects as maps of
610
- globs to package names. While objects in JSON are technically unordered, Parcel
611
- does use the order to give globs priority when a file name is being tested
612
- against them.
613
-
614
- ```json
615
- {
616
- "transformers": {
617
- "icons/*.svg": ["highest-priority"],
618
- "*.svg": ["lowest-priority"]
619
- }
620
- }
621
- ```
622
-
623
- Here if we are trying to find a transform for the file `icons/home.svg`, we'll
624
- work our way down the globs until we find a match, which would be
625
- `icons/*.svg`, we never reach `*.svg`.
626
-
627
- #### `.parcelrc#extends`
628
-
629
- `extends` can either be a string or an array of strings that specify base
630
- configs to extend. That base configuration can be the path to another
631
- `.parcelrc` file or the name of a Parcel config package.
632
-
633
- ```json
634
- {
635
- "extends": "@parcel/config-default",
636
- "extends": "../.parcelrc",
637
- "extends": ["@parcel/config-default", "@company/parcel-config"]
638
- }
639
- ```
640
-
641
- When extending a config, Parcel does a shallow merge of the two configs.
642
-
643
- #### `.parcelrc#resolvers`
644
-
645
- `resolvers` is an array of strings that specifies the name of a Parcel resolver
646
- package.
647
-
648
- ```json
649
- {
650
- "resolvers": ["@parcel/resolver-default"]
651
- }
652
- ```
653
-
654
- See [Resolvers](#resolvers)
655
-
656
- #### `.parcelrc#transformers`
657
-
658
- `transformers` is an object map of globs to arrays of Parcel transform packages.
659
-
660
- ```json
661
- {
662
- "transformers": {
663
- "*.js": ["@parcel/transformer-babel"]
664
- }
665
- }
666
- ```
667
-
668
- See [Transformers](#transformers)
669
-
670
- #### `.parcelrc#bundler`
671
-
672
- `bundler` is a string that specifies the name of a Parcel bundler package.
673
-
674
- ```json
675
- {
676
- "bundler": "@parcel/bundler-default"
677
- }
678
- ```
679
-
680
- See [Bundlers](#bundlers)
681
-
682
- #### `.parcelrc#namers`
683
-
684
- `namers` is an array of Parcel namer packages.
685
-
686
- ```json
687
- {
688
- "namers": ["@parcel/namer-default"]
689
- }
690
- ```
691
-
692
- See [Namers](#namers)
693
-
694
- #### `.parcelrc#runtimes`
695
-
696
- `runtimes` is an array of Parcel runtime packages.
697
-
698
- ```json
699
- {
700
- "runtimes": ["@parcel/runtime-js", "@parcel/runtime-browser-hmr"],
701
- }
702
- ```
703
-
704
- See [Runtimes](#runtimes)
705
-
706
- #### `.parcelrc#packagers`
707
-
708
- `packagers` is an object map of globs to Parcel packager packages.
709
-
710
- ```json
711
- {
712
- "packagers": {
713
- "*.js": ["@parcel/packager-js"]
714
- }
715
- }
716
- ```
717
-
718
- See [Packagers](#packagers)
719
-
720
- #### `.parcelrc#optimizers`
721
-
722
- `optimizers` is an object map of globs to arrays of Parcel optimizer packages.
723
-
724
- ```json
725
- {
726
- "optimizers": {
727
- "*.js": ["@parcel/optimizer-uglify"]
728
- }
729
- }
730
- ```
731
-
732
- See [Optimizers](#optimizers)
733
-
734
- #### `.parcelrc#reporters`
735
-
736
- `reporters` is an array of Parcel reporter packages.
737
-
738
- ```json
739
- {
740
- "reporters": ["@parcel/reporter-detailed"]
741
- }
742
- ```
743
-
744
- See [Reporters](#reporters).
745
-
746
- #### `.parcelrc#validators`
747
-
748
- `validators` is an object map of globs to arrays of Parcel validator packages.
749
-
750
- ```json
751
-
752
- "validators": {
753
- "*.ts": ["@parcel/validator-typescript"]
754
- }
755
- }
756
- ```
757
-
758
- See [Validators](#validators).
759
-
760
- ## Parcel Architecture
761
-
762
- Even if you aren't doing anything that complex, if you are going to use Parcel
763
- a lot it makes sense to take some time and understand how it works.
764
-
765
- ### Phases of Parcel
766
-
767
- At a high level Parcel runs through several phases:
768
-
769
- - Resolving
770
- - Transforming
771
- - Bundling
772
- - Packaging
773
- - Optimizing
774
- - (Validating)
775
-
776
- The **resolving** and **transforming** phases work together in parallel to
777
- build a graph of all your assets.
778
-
779
- This asset graph gets translated into bundles in the **bundling** phase.
780
-
781
- Then the **packaging** phase takes the assets in the calculated bundles and
782
- merges them together into files each containing an entire bundle.
783
-
784
- Finally, in the **optimizing** phase, Parcel takes these bundles files and runs
785
- them through optimizing transforms.
786
-
787
- ### Asset Graph
788
-
789
- During the resolving and transforming phases, Parcel discovers all the assets
790
- in your app or program. Every asset can have its own dependencies on other
791
- assets which Parcel will pull in.
792
-
793
- The data structure that represents all of these assets and their dependencies
794
- on one another is known as "The Asset Graph".
795
-
796
- | Asset Name | Dependencies |
797
- | ------------ | ------------------- |
798
- | `index.html` | `app.css`, `app.js` |
799
- | `app.css` | N/A |
800
- | `app.js` | `navbar.js` |
801
- | `navbar.js` | etc. |
802
-
803
- ### Bundles
804
-
805
- Once Parcel has built the entire Asset Graph, it begins turning it into
806
- "bundles". These bundles are groupings of assets that get placed together in a
807
- single file.
808
-
809
- Bundles will (generally) contain only assets in the same language:
810
-
811
- | Bundle Name | Assets |
812
- | ------------ | --------------------------- |
813
- | `index.html` | `index.html` |
814
- | `app.css` | `app.css` |
815
- | `app.js` | `app.js`, `navbar.js`, etc. |
816
-
817
- Some assets are considered "entry" points into your app, and will stay as
818
- separate bundles. For example, if your `index.html` file links to an
819
- `about.html` file, they won't be merged together.
820
-
821
- | Bundle Name | Assets | Entry URL |
822
- | ------------ | ------------ | --------- |
823
- | `index.html` | `index.html` | `/` |
824
- | `about.html` | `about.html` | `/about` |
825
-
826
- ### Sources
827
-
828
- "Sources" are the files that contain the source code to your app before being
829
- compiled by Parcel.
830
-
831
- Parcel discovers these sources by following their dependencies on one another
832
- starting at your "entries".
833
-
834
- These entries will be one of:
835
-
836
- 1. `$ parcel <...entries>`
837
- 2. `~/package.json#source`
838
- 3. `./src/index.*`
839
- 4. `./index.*`
840
-
841
- From there, everything those assets depend on will be considered a "source" in
842
- Parcel.
843
-
844
- ### Targets
845
-
846
- When Parcel runs, it can build your asset graph in multiple different ways
847
- simultaneously. These are called "targets".
848
-
849
- For example, you could have a "modern" target that _targets_ newer browsers
850
- and a "legacy" target for older browsers.
851
-
852
- Sources get mapped to targets,
853
-
854
- #### Target Configuration
855
-
856
- In the most explicit form, targets are configured via the
857
- `package.json#targets` field.
858
-
859
- ```js
860
- {
861
- "app": "dist/browser/index.js",
862
- "appModern": "dist/browserModern/index.js",
863
- "targets": {
864
- "app": { /* target env */ },
865
- "appModern": { /* target env */ }
866
- }
867
- }
868
- ```
869
-
870
- Each target has a name which corresponds to a top-level `package.json` field
871
- such as `package.json#main` or `package.json#browser` which specify the primary
872
- entry point for that target.
873
-
874
- Inside each of those targets contains the target's environment configuration:
875
-
876
- | Option | Possible values | Description |
877
- | -------------------- | --------------- | ----------- |
878
- | `context` | `'node' \| 'browser' \| 'web-worker' \| 'electron-main' \| 'electron-renderer'` | Where the bundle should run |
879
- | `includeNodeModules` | `boolean \| [String]` | Whether to bundle all/none/some `node_module` dependency |
880
- | `outputFormat` | `'global' \| 'esmodule' \| 'commonjs'` | Which type of imports/exports should be emitted|
881
- | `publicUrl` | `string` | The public url of the bundle at runtime |
882
- | `isLibrary` | `boolean` | Library as in 'npm library' |
883
- | `sourceMap` | `boolean \| {inlineSources?: boolean, sourceRoot?: string, inline?: boolean}` | Enable/disable sourcemap and set options
884
- | `engines` | Engines | Same as `package.json#engines` |
885
-
886
-
887
- However, a lot of the normal configuration you might want will already have
888
- defaults provided for you:
889
-
890
- ```cs
891
- targets = {
892
- main: {
893
- engines: {
894
- node: value("package.json#engines.node"),
895
- browsers: unless exists("package.json#browser") then value("package.json#browserlist")
896
- },
897
- isLibrary: true
898
- },
899
- module: {
900
- engines: {
901
- node: value("package.json#engines.node"),
902
- browsers: unless exists("package.json#browser") then value("package.json#browserlist")
903
- },
904
- isLibrary: true
905
- },
906
- browser: {
907
- engines: {
908
- browsers: value("package.json#browserslist")
909
- },
910
- isLibrary: true
911
- },
912
- ...value("package.json#targets"),
913
- }
914
- ```
915
-
916
- ### Environments
917
-
918
- Environments tell Parcel how to transform and bundle each asset. They tell
919
- Parcel if an asset is going to be run in a browser or in NodeJS/Electron.
920
-
921
- They also tell Parcel's transform plugins how they should run. They tell
922
- [Babel](http://babeljs.io/docs/en/babel-preset-env#targetsbrowsers) or
923
- [Autoprefixer](https://github.com/postcss/autoprefixer#browsers) what browsers
924
- your asset is targetting.
925
-
926
- You can configure environments through your targets.
927
-
928
- ```json
929
- {
930
- "targets": {
931
- "main": {
932
- "engines": {
933
- "node": ">=4.x",
934
- "electron": ">=2.x",
935
- "browsers": ["> 1%", "not dead"]
936
- }
937
- }
938
- }
939
- }
940
- ```
941
-
942
- When one asset depends on another, the environment is inherited from its
943
- parent. But how you depend on the asset can change some properties of that
944
- environment.
945
-
946
- For example:
947
-
948
- ```js
949
- navigator.serviceWorker.register('./service-worker.js');
950
- ```
951
-
952
- ```js
953
- let childEnvironment = {...parentEnvironment, browserContext: 'service-worker'};
954
- ```
955
-
956
- ### Caching
957
-
958
- Parcel will create a `/.parcel-cache` directory. It will be filled with
959
- directories with two letters, which are the start of a hash which is finished
960
- by the names of the JSON files inside.
961
-
962
- ```
963
- /.parcel-cache
964
- /00/
965
- 213debd8ddd45819b79a3a974ed487.json
966
- 40ae9b581afc53841307a4b3c2463d.json
967
- 63a9dd58fc1e8f8bb819759ea9793c.json
968
- ...
969
- /01/
970
- /../
971
- /zy/
972
- /zz/
973
- ```
974
-
975
- It follows this weird structure in order to avoid too many files being created
976
- in a single directory, which degrades file system performance.
977
-
978
- ## Asset Resolution
979
-
980
- Parcel follows the Node module resolution algorithm with a few additions.
981
-
982
- ### Local Paths
983
-
984
- ```
985
- ./path/to/file
986
- ./path/to/file.js
987
- ```
988
-
989
- These follow the [Node module resolution algorithm](https://nodejs.org/api/modules.html#modules_all_together).
990
-
991
- ### Package Paths
992
-
993
- ```
994
- preact
995
- lodash/cloneDeep
996
- @sindresorhus/is
997
- ```
998
-
999
- These follow the [Node module resolution algorithm](https://nodejs.org/api/modules.html#modules_all_together).
1000
-
1001
- ### URLs
1002
-
1003
- ```
1004
- https://unpkg.com/preact@8.2.9/dist/preact.min.js
1005
- ```
1006
-
1007
- Parcel by default will ignore URL dependencies, other resolver plugins may
1008
- choose to do something with them.
1009
-
1010
- ### Tilde Paths
1011
-
1012
- ```
1013
- ~/src/file.js
1014
- ```
1015
-
1016
- Only when used outside of `node_modules` directories, the `~` is replaced by an
1017
- absolute path to the closest package root:
1018
-
1019
- ```sh
1020
- /path/to/app #(/package.json)
1021
- ```
1022
-
1023
- To form a path that looks like:
1024
-
1025
- ```
1026
- /path/to/app/src/file.js
1027
- ```
1028
-
1029
- Then it follows the [Node module resolution algorithm](https://nodejs.org/api/modules.html#modules_all_together).
1030
-
1031
- ### Aliases
1032
-
1033
- Aliases come in two forms:
1034
-
1035
- 1. Package Aliases: `react -> preact`
1036
- 2. File/Directory Aliases: `utils` -> `./src/utils`
1037
-
1038
- ```json
1039
- {
1040
- "name": "my-project",
1041
- "alias": {
1042
- "react": "preact-compat",
1043
- "react-dom": "preact-compat",
1044
- "utils": "./src/utils",
1045
- "components": "./src/components"
1046
- }
1047
- }
1048
- ```
1049
-
1050
- There are a couple of rules:
1051
-
1052
- 1. Aliases will only be respected when specified outside of `node_modules`.
1053
- 2. Aliases specified outside of `node_modules` will affect assets inside of `node_modules`.
1054
- 3. Aliases cannot build off of other aliases.
1055
- 4. Only one alias will be applied at a time.
1056
- 5. Aliases must be valid npm package names.
1057
-
1058
- ## Plugins
1059
-
1060
- ### Resolvers
1061
-
1062
- When one asset depends on another through an asset specifier, the resolver is
1063
- responsible for determining what asset is being requested.
1064
-
1065
- See [Asset Resolution](#asset-resolution) for more details.
1066
-
1067
- ```json
1068
- {
1069
- "resolvers": ["@parcel/resolver-v1"]
1070
- }
1071
- ```
1072
-
1073
- **Official Resolvers:**
1074
-
1075
- - `@parcel/resolver-v1`
1076
-
1077
- ### Transformers
1078
-
1079
- transformers _transform_ single assets as they are discovered and added to the
1080
- asset graph. They mostly call out to different compilers and preprocessors.
1081
-
1082
- ```json
1083
- {
1084
- "transformers": {
1085
- "*.js": ["@parcel/transformer-babel"]
1086
- }
1087
- }
1088
- ```
1089
-
1090
- **Official Transformers:**
1091
-
1092
- - `@parcel/transformer-babel`
1093
- - `@parcel/transformer-coffeescript`
1094
- - `@parcel/transformer-glsl`
1095
- - `@parcel/transformer-graphql`
1096
- - `@parcel/transformer-json`
1097
- - `@parcel/transformer-json5`
1098
- - `@parcel/transformer-less`
1099
- - `@parcel/transformer-posthtml`
1100
- - `@parcel/transformer-postcss`
1101
- - `@parcel/transformer-pug`
1102
- - `@parcel/transformer-raw`
1103
- - `@parcel/transformer-reason`
1104
- - `@parcel/transformer-rust`
1105
- - `@parcel/transformer-stylus`
1106
- - `@parcel/transformer-toml`
1107
- - `@parcel/transformer-typescript`
1108
- - `@parcel/transformer-vue`
1109
- - `@parcel/transformer-wasm`
1110
- - `@parcel/transformer-webmanifest`
1111
- - `@parcel/transformer-yaml`
1112
- - `@parcel/transformer-elm`
1113
- - ...
1114
-
1115
- ### Bundlers
1116
-
1117
- Bundlers accept the entire asset graph and turn it into sets of bundles.
1118
-
1119
- ```json
1120
- {
1121
- "bundler": "@parcel/bundler-default"
1122
- }
1123
- ```
1124
-
1125
- **Official Bundlers:**
1126
-
1127
- - `@parcel/bundler-default`
1128
-
1129
- ### Namers
1130
-
1131
- Namers accept a bundle and return a filename for that bundle.
1132
-
1133
- ```json
1134
- {
1135
- "namers": ["@parcel/namer-default"]
1136
- }
1137
- ```
1138
-
1139
- **Official Namers:**
1140
-
1141
- - `@parcel/namer-default`
1142
-
1143
- ### Runtimes
1144
-
1145
- Runtimes get called after the bundler phase and generate an asset which gets
1146
- included in the final bundle.
1147
-
1148
- ```json
1149
- {
1150
- "runtimes": ["@parcel/runtime-js", "@parcel/runtime-browser-hmr"]
1151
- }
1152
- ```
1153
-
1154
- **Official Runtimes:**
1155
-
1156
- - `@parcel/runtime-js`
1157
- - `@parcel/runtime-hmr`
1158
-
1159
- ### Packagers
1160
-
1161
- Packagers determine how to merge different asset types into a single bundle.
1162
-
1163
- ```json
1164
- {
1165
- "packagers": {
1166
- "*.css": "@parcel/packager-css"
1167
- }
1168
- }
1169
- ```
1170
-
1171
- **Official Packagers:**
1172
-
1173
- - `@parcel/packager-html`
1174
- - `@parcel/packager-js`
1175
- - `@parcel/packager-css`
1176
- - `@parcel/packager-wasm`
1177
- - `@parcel/packager-raw`
1178
-
1179
- ### Optimizers
1180
-
1181
- Optimizers are similar to transformers, but they accept a bundle instead
1182
- of a single asset.
1183
-
1184
- ```json
1185
- {
1186
- "optimizers": {
1187
- "*.js": ["@parcel/optimizer-terser"],
1188
- "*.css": ["@parcel/optimizer-csso"]
1189
- }
1190
- }
1191
- ```
1192
-
1193
- **Official Optimizers:**
1194
-
1195
- - `@parcel/packager-terser`
1196
- - `@parcel/packager-csso`
1197
- - [todo]
1198
-
1199
- ### Reporters
1200
-
1201
- Reporters receive events as they happen and can either use the Parcel logger to
1202
- output to stdout/stderr or they can return assets to be generated on the file
1203
- system.
1204
-
1205
- ```json
1206
- {
1207
- "reporters": ["@parcel/reporter-cli", "@parcel/reporter-dev-server"]
1208
- }
1209
- ```
1210
-
1211
- **Official Reporters:**
1212
-
1213
- - `@parcel/reporter-cli`
1214
- - `@parcel/reporter-dev-server`
1215
- - [todo]
1216
-
1217
- ### Validators
1218
-
1219
- Validators emit errors for source code after a build is completed.
1220
- For example, type checking and linting.
1221
-
1222
- ```json
1223
- {
1224
- "validators": {
1225
- "*.ts": ["@parcel/validator-typescript"]
1226
- }
1227
- }
1228
- ```
1229
-
1230
- **Official Validators:**
1231
-
1232
- - `@parcel/validator-typescript`
1233
- - `@parcel/validator-eslint`
1234
- - [todo]
1235
-
1236
- ## Creating Plugins
1237
-
1238
- ### Naming
1239
-
1240
- All plugins must follow a naming system:
1241
-
1242
- | | Official package | Community packages | Private company/scoped team packages |
1243
- | ---------- | -------------------------- | ------------------------- | ------------------------------------ |
1244
- | Configs | `@parcel/config-{name}` | `parcel-config-{name}` | `@scope/parcel-config[-{name}]` |
1245
- | Resolvers | `@parcel/resolver-{name}` | `parcel-resolver-{name}` | `@scope/parcel-resolver[-{name}]` |
1246
- | Transformers | `@parcel/transformer-{name}` | `parcel-transformer-{name}` | `@scope/parcel-transformer[-{name}]` |
1247
- | Bundlers | `@parcel/bundler-{name}` | `parcel-bundler-{name}` | `@scope/parcel-bundler[-{name}]` |
1248
- | Namers | `@parcel/namer-{name}` | `parcel-namer-{name}` | `@scope/parcel-namer[-{name}]` |
1249
- | Runtimes | `@parcel/runtime-{name}` | `parcel-runtime-{name}` | `@scope/parcel-runtime[-{name}]` |
1250
- | Packagers | `@parcel/packager-{name}` | `parcel-packager-{name}` | `@scope/parcel-packager[-{name}]` |
1251
- | Optimizers | `@parcel/optimizer-{name}` | `parcel-optimizer-{name}` | `@scope/parcel-optimizer[-{name}]` |
1252
- | Reporters | `@parcel/reporter-{name}` | `parcel-reporter-{name}` | `@scope/parcel-reporter[-{name}]` |
1253
- | Validators | `@parcel/validator-{name}` | `parcel-validator-{name}`| `@scope/parcel-validator[-{name}]` |
1254
-
1255
- The `{name}` must be descriptive and directly related to the purpose of the
1256
- package. Someone should be able to have an idea of what the package does simply
1257
- by reading the name in a `.parcelrc` or `package.json#devDependencies`.
1258
-
1259
- ```
1260
- parcel-transformer-posthtml
1261
- parcel-packager-wasm
1262
- parcel-reporter-graph-visualizer
1263
- ```
1264
-
1265
- If your plugin adds support for a specific tool, please use the name of the
1266
- tool.
1267
-
1268
- ```
1269
- parcel-transformer-es6 (bad)
1270
- parcel-transformer-babel (good)
1271
- ```
1272
-
1273
- If your plugin is a reimplementation of something that exists, try naming it
1274
- something that explains why it is a separate:
1275
-
1276
- ```
1277
- parcel-transformer-better-typescript (bad)
1278
- parcel-transformer-typescript-server (good)
1279
- ```
1280
-
1281
- We ask that community members work together and when forks happen to try and
1282
- resolve them. If someone made a better version of your plugin, please consider
1283
- giving the better package name over, have them make a major version bump, and
1284
- redirect people to the new tool.
1285
-
1286
- ### Versioning
1287
-
1288
- You must follow semantic versioning (to the best of your ability). No, it's not
1289
- the perfect system, but it's the best one we have and people do depend on it.
1290
-
1291
- If plugin authors intentionally don't follow semantic versioning, Parcel may
1292
- start warning users that they should be locking down the version number for
1293
- your plugin.
1294
-
1295
- > Warning: The plugin "parcel-transform-typescript" does not follow semantic
1296
- > versioning. You should lock the version range down so your code does not
1297
- > break when they make changes. Please upvote this issue to encourage them to
1298
- > follow semver: https://github.com/user/parcel-transform-typescript/issues/43
1299
-
1300
- ### Engines
1301
-
1302
- You must specify a `package.json#engines.parcel` field with the version range
1303
- of Parcel that your plugin supports:
1304
-
1305
- ```json
1306
- {
1307
- "name": "parcel-transform-imagemin",
1308
- "engines": {
1309
- "parcel": "2.x"
1310
- }
1311
- }
1312
- ```
1313
-
1314
- If you do not specify this field, Parcel will output a warning:
1315
-
1316
- ```
1317
- Warning: The plugin "parcel-transform-typescript" needs to specify a `package.json#engines.parcel` field with the supported Parcel version range.
1318
- ```
1319
-
1320
- If you do specify the parcel engine field and the user is using an incompatible
1321
- version of Parcel, they will see an error:
1322
-
1323
- ```
1324
- Error: The plugin "parcel-transform-typescript" is not compatible with the
1325
- current version of Parcel. Requires "2.x" but the current version is "3.1.4"
1326
- ```
1327
-
1328
- Parcel uses node-semver to match version ranges.
1329
-
1330
- ## Plugin APIs
1331
-
1332
- There are several different types of plugins. They all look very similar, but
1333
- are kept separate so we can have strict contracts one what each one is allowed
1334
- to do.
1335
-
1336
- There are some rules that should be followed across every type of plugin:
1337
-
1338
- - **Stateless** — Avoid any kind of state, it will likely be the source of bugs
1339
- for your users. For example, the same transform may exist in multiple
1340
- separate workers which are not allowed to communicate with one another, state
1341
- will not work as expected.
1342
- - **Pure** — Given the same input, a plugin must produce the same output, and
1343
- you must not have any observable side effects, or implicit dependencies.
1344
- Otherwise Parcel's caching will break and your users will be sad. You should
1345
- never have to tell users to delete their caches.
1346
-
1347
- The plugin APIs all follow a common shape:
1348
-
1349
- ```js
1350
- import {NameOfPluginType} from '@parcel/plugin';
1351
-
1352
- export default new NameOfPluginType({
1353
- async methodName(opts: JSONObject): Promise<JSONObject> {
1354
- return result;
1355
- }
1356
- });
1357
- ```
1358
-
1359
- They are made up of modules with well-known named exports of async functions
1360
- that:
1361
-
1362
- - Accept a strictly validated JSON-serializable `opts` object.
1363
- - Return a strictly validated JSON-serializable `vals` object.
1364
-
1365
- If something you need is not being passed through `opts`, please come talk to
1366
- the Parcel team about it. Avoid trying to get information yourself from other
1367
- sources, especially from the file system.
1368
-
1369
- ### Resolvers
1370
-
1371
- Resolvers get called with an asset request (consisting of a source file path
1372
- and the specifier of what is being requested) which it then attempts to
1373
- resolve. If the resolver isn't sure how to handle a request, it can also return
1374
- `null` and pass it to the next resolver in the chain.
1375
-
1376
- ```js
1377
- import {Resolver} from '@parcel/plugin';
1378
-
1379
- export default new Resolver({
1380
- async resolve({dependency}) {
1381
- // ...
1382
- return {filePath} || null;
1383
- }
1384
- });
1385
- ```
1386
-
1387
- ### Transformers
1388
-
1389
- Transformers _transform_ single assets as they are discovered and added to the
1390
- asset graph. They mostly call out to different compilers and preprocessors.
1391
-
1392
- ```js
1393
- import {Transform} from '@parcel/plugin';
1394
-
1395
- export default new Transform({
1396
- async parse({asset}) {
1397
- // ...
1398
- return ast;
1399
- },
1400
-
1401
- async transform({asset}) {
1402
- // ...
1403
- return [assets];
1404
- },
1405
-
1406
- async generate({asset}) {
1407
- // ...
1408
- return {code, map};
1409
- }
1410
- });
1411
- ```
1412
-
1413
- ### Bundler
1414
-
1415
- Bundlers accept the entire asset graph and modify it to add bundle nodes that group the assets
1416
- into output bundles.
1417
-
1418
- ```js
1419
- import {Bundler} from '@parcel/plugin';
1420
-
1421
- export default new Bundler({
1422
- async bundle({graph}) {
1423
- // ...
1424
- },
1425
-
1426
- async optimize({graph}) {
1427
- // ...
1428
- }
1429
- });
1430
- ```
1431
-
1432
- ### Namers
1433
-
1434
- Namers accept a bundle and output a filename for that bundle.
1435
-
1436
- ```js
1437
- import {Namer} from '@parcel/plugin';
1438
-
1439
- export default new Namer({
1440
- async name({bundle, bundleGraph}) {
1441
- // ...
1442
- return name;
1443
- }
1444
- });
1445
- ```
1446
-
1447
- ### Runtimes
1448
-
1449
- Runtimes accept a bundle and return assets to be inserted into that bundle.
1450
-
1451
- ```js
1452
- import {Runtime} from '@parcel/runtime';
1453
-
1454
- export default new Runtime({
1455
- async apply({bundle, bundleGraph}) {
1456
- // ...
1457
- return assets;
1458
- }
1459
- });
1460
- ```
1461
-
1462
- ### Packagers
1463
-
1464
- Packagers determine how to merge different asset types into a single bundle.
1465
-
1466
- ```js
1467
- import {Packager} from '@parcel/plugin';
1468
-
1469
- export default new Packager({
1470
- async package({bundle}) {
1471
- // ...
1472
- return {contents, map};
1473
- },
1474
- });
1475
- ```
1476
-
1477
- ### Optimizers
1478
-
1479
- Optimizers are similar to transformers, but they accept a bundle instead
1480
- of a single asset.
1481
-
1482
- ```js
1483
- import {Optimizer} from '@parcel/plugin';
1484
-
1485
- export default new Optimizer({
1486
- async optimize({bundle, contents, map}) {
1487
- // ...
1488
- return {contents, map};
1489
- }
1490
- });
1491
- ```
1492
-
1493
- ### Reporters
1494
-
1495
- Reporters receive events as they happen and can output to stdout/stderr,
1496
- or perform other actions.
1497
-
1498
- ```js
1499
- import {Reporter} from '@parcel/plugin';
34
+ Read the docs at https://parceljs.org/docs/.
1500
35
 
1501
- export default new Reporter({
1502
- async report({ event: { type, ... } }) {
1503
- // ...
1504
- }
1505
- });
1506
- ```
36
+ ## Community
1507
37
 
1508
- ### Validators
38
+ - ❓ Ask questions on [GitHub Discussions](https://github.com/parcel-bundler/parcel/discussions).
39
+ - 💬 Join the community on [Discord](https://discord.gg/XSCzqGRuvr).
40
+ - 📣 Stay up to date on new features and announcements on [Twitter](https://twitter.com/parceljs).
1509
41
 
1510
- Validators receive an asset, and can throw errors if that asset is invalid
1511
- in some way, e.g. type errors or linting errors.
42
+ ## Contributors
1512
43
 
1513
- ```js
1514
- import {Validator} from '@parcel/plugin';
44
+ This project exists thanks to all the people who contribute. [[Contribute]](CONTRIBUTING.md).
45
+ <a href="https://github.com/parcel-bundler/parcel/graphs/contributors"><img src="https://opencollective.com/parcel/contributors.svg?width=890" title="contributors" alt="contributors" /></a>
1515
46
 
1516
- export default new Validator({
1517
- async validate({asset}) {
1518
- // ...
1519
- throw error;
1520
- }
1521
- });
1522
- ```
1523
- Some validators (such as `@parcel/validator-typescript`) may wish to maintain a project-wide cache for efficiency. For these cases, it is appropriate to use a different interface where parcel hands _all_ changed files to the validator at the same time:
47
+ ## Backers
1524
48
 
1525
- ```js
1526
- import {Validator} from '@parcel/plugin';
49
+ Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/parcel#backer)]
1527
50
 
1528
- export default new Validator({
1529
- async validateAll({assets}) {
1530
- // ...
1531
- throw error;
1532
- }
1533
- });
1534
- ```
51
+ <a href="https://opencollective.com/parcel#backers" target="_blank"><img src="https://opencollective.com/parcel/backers.svg?width=890"></a>
1535
52
 
1536
- If your plugin implements `validateAll`, Parcel will make sure to always invoke this method on the same thread (so that your cache state is accessible).
53
+ ## Sponsors
1537
54
 
1538
- ## License
55
+ Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/parcel#sponsor)]
1539
56
 
1540
- This project is licensed under the MIT License - see the [LICENSE.md](https://github.com/parcel-bundler/parcel/blob/v2/LICENSE) file for details
57
+ <a href="https://opencollective.com/parcel/sponsor/0/website" target="_blank"><img src="https://opencollective.com/parcel/sponsor/0/avatar.svg"></a>
58
+ <a href="https://opencollective.com/parcel/sponsor/1/website" target="_blank"><img src="https://opencollective.com/parcel/sponsor/1/avatar.svg"></a>
59
+ <a href="https://opencollective.com/parcel/sponsor/2/website" target="_blank"><img src="https://opencollective.com/parcel/sponsor/2/avatar.svg"></a>
60
+ <a href="https://opencollective.com/parcel/sponsor/3/website" target="_blank"><img src="https://opencollective.com/parcel/sponsor/3/avatar.svg"></a>
61
+ <a href="https://opencollective.com/parcel/sponsor/4/website" target="_blank"><img src="https://opencollective.com/parcel/sponsor/4/avatar.svg"></a>
62
+ <a href="https://opencollective.com/parcel/sponsor/5/website" target="_blank"><img src="https://opencollective.com/parcel/sponsor/5/avatar.svg"></a>
63
+ <a href="https://opencollective.com/parcel/sponsor/6/website" target="_blank"><img src="https://opencollective.com/parcel/sponsor/6/avatar.svg"></a>
64
+ <a href="https://opencollective.com/parcel/sponsor/7/website" target="_blank"><img src="https://opencollective.com/parcel/sponsor/7/avatar.svg"></a>
65
+ <a href="https://opencollective.com/parcel/sponsor/8/website" target="_blank"><img src="https://opencollective.com/parcel/sponsor/8/avatar.svg"></a>
66
+ <a href="https://opencollective.com/parcel/sponsor/9/website" target="_blank"><img src="https://opencollective.com/parcel/sponsor/9/avatar.svg"></a>