parcel 2.0.0-beta.2 → 2.0.0-nightly.1000

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 -1519
  2. package/lib/cli.js +46 -41
  3. package/package.json +13 -13
  4. package/src/bin.js +4 -1
  5. package/src/cli.js +39 -21
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,1542 +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
+ - ⚡️ **Lighting 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": {
590
- "browser": ["@parcel/runtime-js", "@parcel/runtime-browser-hmr"],
591
- "node": ["@parcel/runtime-js"]
592
- },
593
- "packagers": {
594
- "*.js": "@parcel/packager-js",
595
- "*.css": "@parcel/packager-css",
596
- "*.html": "@parcel/packager-html",
597
- "*.wasm": "@parcel/packager-wasm",
598
- "*.raw": "@parcel/packager-raw"
599
- },
600
- "optimizers": {
601
- "*.js": ["@parcel/optimizer-uglify"],
602
- "*.css": ["@parcel/optimizer-cssnano"],
603
- "*.html": ["@parcel/optimizer-htmlnano"],
604
- "*.{png,jpg,jpeg,svg,...}": ["@parcel/optimizer-imagemin"]
605
- },
606
- "reporters": ["@parcel/reporter-cli"]
607
- }
608
- ```
609
-
610
- #### Glob maps in `.parcelrc`
611
-
612
- Many config properties like `transformers` or `packagers` use objects as maps of
613
- globs to package names. While objects in JSON are technically unordered, Parcel
614
- does use the order to give globs priority when a file name is being tested
615
- against them.
616
-
617
- ```json
618
- {
619
- "transformers": {
620
- "icons/*.svg": ["highest-priority"],
621
- "*.svg": ["lowest-priority"]
622
- }
623
- }
624
- ```
625
-
626
- Here if we are trying to find a transform for the file `icons/home.svg`, we'll
627
- work our way down the globs until we find a match, which would be
628
- `icons/*.svg`, we never reach `*.svg`.
629
-
630
- #### `.parcelrc#extends`
631
-
632
- `extends` can either be a string or an array of strings that specify base
633
- configs to extend. That base configuration can be the path to another
634
- `.parcelrc` file or the name of a Parcel config package.
635
-
636
- ```json
637
- {
638
- "extends": "@parcel/config-default",
639
- "extends": "../.parcelrc",
640
- "extends": ["@parcel/config-default", "@company/parcel-config"]
641
- }
642
- ```
643
-
644
- When extending a config, Parcel does a shallow merge of the two configs.
645
-
646
- #### `.parcelrc#resolvers`
647
-
648
- `resolvers` is an array of strings that specifies the name of a Parcel resolver
649
- package.
650
-
651
- ```json
652
- {
653
- "resolvers": ["@parcel/resolver-default"]
654
- }
655
- ```
656
-
657
- See [Resolvers](#resolvers)
658
-
659
- #### `.parcelrc#transformers`
660
-
661
- `transformers` is an object map of globs to arrays of Parcel transform packages.
662
-
663
- ```json
664
- {
665
- "transformers": {
666
- "*.js": ["@parcel/transformer-babel"]
667
- }
668
- }
669
- ```
670
-
671
- See [Transformers](#transformers)
672
-
673
- #### `.parcelrc#bundler`
674
-
675
- `bundler` is a string that specifies the name of a Parcel bundler package.
676
-
677
- ```json
678
- {
679
- "bundler": "@parcel/bundler-default"
680
- }
681
- ```
682
-
683
- See [Bundlers](#bundlers)
684
-
685
- #### `.parcelrc#namers`
686
-
687
- `namers` is an array of Parcel namer packages.
688
-
689
- ```json
690
- {
691
- "namers": ["@parcel/namer-default"]
692
- }
693
- ```
694
-
695
- See [Namers](#namers)
696
-
697
- #### `.parcelrc#runtimes`
698
-
699
- `runtimes` is an object map of environments to arrays of Parcel runtime packages.
700
-
701
- ```json
702
- {
703
- "runtimes": {
704
- "browser": ["@parcel/runtime-js", "@parcel/runtime-browser-hmr"],
705
- "node": ["@parcel/runtime-js"]
706
- }
707
- }
708
- ```
709
-
710
- See [Runtimes](#runtimes)
711
-
712
- #### `.parcelrc#packagers`
713
-
714
- `packagers` is an object map of globs to Parcel packager packages.
715
-
716
- ```json
717
- {
718
- "packagers": {
719
- "*.js": ["@parcel/packager-js"]
720
- }
721
- }
722
- ```
723
-
724
- See [Packagers](#packagers)
725
-
726
- #### `.parcelrc#optimizers`
727
-
728
- `optimizers` is an object map of globs to arrays of Parcel optimizer packages.
729
-
730
- ```json
731
- {
732
- "optimizers": {
733
- "*.js": ["@parcel/optimizer-uglify"]
734
- }
735
- }
736
- ```
737
-
738
- See [Optimizers](#optimizers)
739
-
740
- #### `.parcelrc#reporters`
741
-
742
- `reporters` is an array of Parcel reporter packages.
743
-
744
- ```json
745
- {
746
- "reporters": ["@parcel/reporter-detailed"]
747
- }
748
- ```
749
-
750
- See [Reporters](#reporters).
751
-
752
- #### `.parcelrc#validators`
753
-
754
- `validators` is an object map of globs to arrays of Parcel validator packages.
755
-
756
- ```json
757
-
758
- "validators": {
759
- "*.ts": ["@parcel/validator-typescript"]
760
- }
761
- }
762
- ```
763
-
764
- See [Validators](#validators).
765
-
766
- ## Parcel Architecture
767
-
768
- Even if you aren't doing anything that complex, if you are going to use Parcel
769
- a lot it makes sense to take some time and understand how it works.
770
-
771
- ### Phases of Parcel
772
-
773
- At a high level Parcel runs through several phases:
774
-
775
- - Resolving
776
- - Transforming
777
- - Bundling
778
- - Packaging
779
- - Optimizing
780
- - (Validating)
781
-
782
- The **resolving** and **transforming** phases work together in parallel to
783
- build a graph of all your assets.
784
-
785
- This asset graph gets translated into bundles in the **bundling** phase.
786
-
787
- Then the **packaging** phase takes the assets in the calculated bundles and
788
- merges them together into files each containing an entire bundle.
789
-
790
- Finally, in the **optimizing** phase, Parcel takes these bundles files and runs
791
- them through optimizing transforms.
792
-
793
- ### Asset Graph
794
-
795
- During the resolving and transforming phases, Parcel discovers all the assets
796
- in your app or program. Every asset can have its own dependencies on other
797
- assets which Parcel will pull in.
798
-
799
- The data structure that represents all of these assets and their dependencies
800
- on one another is known as "The Asset Graph".
801
-
802
- | Asset Name | Dependencies |
803
- | ------------ | ------------------- |
804
- | `index.html` | `app.css`, `app.js` |
805
- | `app.css` | N/A |
806
- | `app.js` | `navbar.js` |
807
- | `navbar.js` | etc. |
808
-
809
- ### Bundles
810
-
811
- Once Parcel has built the entire Asset Graph, it begins turning it into
812
- "bundles". These bundles are groupings of assets that get placed together in a
813
- single file.
814
-
815
- Bundles will (generally) contain only assets in the same language:
816
-
817
- | Bundle Name | Assets |
818
- | ------------ | --------------------------- |
819
- | `index.html` | `index.html` |
820
- | `app.css` | `app.css` |
821
- | `app.js` | `app.js`, `navbar.js`, etc. |
822
-
823
- Some assets are considered "entry" points into your app, and will stay as
824
- separate bundles. For example, if your `index.html` file links to an
825
- `about.html` file, they won't be merged together.
826
-
827
- | Bundle Name | Assets | Entry URL |
828
- | ------------ | ------------ | --------- |
829
- | `index.html` | `index.html` | `/` |
830
- | `about.html` | `about.html` | `/about` |
831
-
832
- ### Sources
833
-
834
- "Sources" are the files that contain the source code to your app before being
835
- compiled by Parcel.
836
-
837
- Parcel discovers these sources by following their dependencies on one another
838
- starting at your "entries".
839
-
840
- These entries will be one of:
841
-
842
- 1. `$ parcel <...entries>`
843
- 2. `~/package.json#source`
844
- 3. `./src/index.*`
845
- 4. `./index.*`
846
-
847
- From there, everything those assets depend on will be considered a "source" in
848
- Parcel.
849
-
850
- ### Targets
851
-
852
- When Parcel runs, it can build your asset graph in multiple different ways
853
- simultaneously. These are called "targets".
854
-
855
- For example, you could have a "modern" target that _targets_ newer browsers
856
- and a "legacy" target for older browsers.
857
-
858
- Sources get mapped to targets,
859
-
860
- #### Target Configuration
861
-
862
- In the most explicit form, targets are configured via the
863
- `package.json#targets` field.
864
-
865
- ```js
866
- {
867
- "app": "dist/browser/index.js",
868
- "appModern": "dist/browserModern/index.js",
869
- "targets": {
870
- "app": { /* target env */ },
871
- "appModern": { /* target env */ }
872
- }
873
- }
874
- ```
875
-
876
- Each target has a name which corresponds to a top-level `package.json` field
877
- such as `package.json#main` or `package.json#browser` which specify the primary
878
- entry point for that target.
879
-
880
- Inside each of those targets contains the target's environment configuration:
881
-
882
- | Option | Possible values | Description |
883
- | -------------------- | --------------- | ----------- |
884
- | `context` | `'node' \| 'browser' \| 'web-worker' \| 'electron-main' \| 'electron-renderer'` | Where the bundle should run |
885
- | `includeNodeModules` | `boolean \| [String]` | Whether to bundle all/none/some `node_module` dependency |
886
- | `outputFormat` | `'global' \| 'esmodule' \| 'commonjs'` | Which type of imports/exports should be emitted|
887
- | `publicUrl` | `string` | The public url of the bundle at runtime |
888
- | `isLibrary` | `boolean` | Library as in 'npm library' |
889
- | `sourceMap` | `boolean \| {inlineSources?: boolean, sourceRoot?: string, inline?: boolean}` | Enable/disable sourcemap and set options
890
- | `engines` | Engines | Same as `package.json#engines` |
891
-
892
-
893
- However, a lot of the normal configuration you might want will already have
894
- defaults provided for you:
895
-
896
- ```cs
897
- targets = {
898
- main: {
899
- engines: {
900
- node: value("package.json#engines.node"),
901
- browsers: unless exists("package.json#browser") then value("package.json#browserlist")
902
- },
903
- isLibrary: true
904
- },
905
- module: {
906
- engines: {
907
- node: value("package.json#engines.node"),
908
- browsers: unless exists("package.json#browser") then value("package.json#browserlist")
909
- },
910
- isLibrary: true
911
- },
912
- browser: {
913
- engines: {
914
- browsers: value("package.json#browserslist")
915
- },
916
- isLibrary: true
917
- },
918
- ...value("package.json#targets"),
919
- }
920
- ```
921
-
922
- ### Environments
923
-
924
- Environments tell Parcel how to transform and bundle each asset. They tell
925
- Parcel if an asset is going to be run in a browser or in NodeJS/Electron.
926
-
927
- They also tell Parcel's transform plugins how they should run. They tell
928
- [Babel](http://babeljs.io/docs/en/babel-preset-env#targetsbrowsers) or
929
- [Autoprefixer](https://github.com/postcss/autoprefixer#browsers) what browsers
930
- your asset is targetting.
931
-
932
- You can configure environments through your targets.
933
-
934
- ```json
935
- {
936
- "targets": {
937
- "main": {
938
- "engines": {
939
- "node": ">=4.x",
940
- "electron": ">=2.x",
941
- "browsers": ["> 1%", "not dead"]
942
- }
943
- }
944
- }
945
- }
946
- ```
947
-
948
- When one asset depends on another, the environment is inherited from its
949
- parent. But how you depend on the asset can change some properties of that
950
- environment.
951
-
952
- For example:
953
-
954
- ```js
955
- navigator.serviceWorker.register('./service-worker.js');
956
- ```
957
-
958
- ```js
959
- let childEnvironment = {...parentEnvironment, browserContext: 'service-worker'};
960
- ```
961
-
962
- ### Caching
963
-
964
- Parcel will create a `/.parcel-cache` directory. It will be filled with
965
- directories with two letters, which are the start of a hash which is finished
966
- by the names of the JSON files inside.
967
-
968
- ```
969
- /.parcel-cache
970
- /00/
971
- 213debd8ddd45819b79a3a974ed487.json
972
- 40ae9b581afc53841307a4b3c2463d.json
973
- 63a9dd58fc1e8f8bb819759ea9793c.json
974
- ...
975
- /01/
976
- /../
977
- /zy/
978
- /zz/
979
- ```
980
-
981
- It follows this weird structure in order to avoid too many files being created
982
- in a single directory, which degrades file system performance.
983
-
984
- ## Asset Resolution
985
-
986
- Parcel follows the Node module resolution algorithm with a few additions.
987
-
988
- ### Local Paths
989
-
990
- ```
991
- ./path/to/file
992
- ./path/to/file.js
993
- ```
994
-
995
- These follow the [Node module resolution algorithm](https://nodejs.org/api/modules.html#modules_all_together).
996
-
997
- ### Package Paths
998
-
999
- ```
1000
- preact
1001
- lodash/cloneDeep
1002
- @sindresorhus/is
1003
- ```
1004
-
1005
- These follow the [Node module resolution algorithm](https://nodejs.org/api/modules.html#modules_all_together).
1006
-
1007
- ### URLs
1008
-
1009
- ```
1010
- https://unpkg.com/preact@8.2.9/dist/preact.min.js
1011
- ```
1012
-
1013
- Parcel by default will ignore URL dependencies, other resolver plugins may
1014
- choose to do something with them.
1015
-
1016
- ### Tilde Paths
1017
-
1018
- ```
1019
- ~/src/file.js
1020
- ```
1021
-
1022
- Only when used outside of `node_modules` directories, the `~` is replaced by an
1023
- absolute path to the closest package root:
1024
-
1025
- ```sh
1026
- /path/to/app #(/package.json)
1027
- ```
1028
-
1029
- To form a path that looks like:
1030
-
1031
- ```
1032
- /path/to/app/src/file.js
1033
- ```
1034
-
1035
- Then it follows the [Node module resolution algorithm](https://nodejs.org/api/modules.html#modules_all_together).
1036
-
1037
- ### Aliases
1038
-
1039
- Aliases come in two forms:
1040
-
1041
- 1. Package Aliases: `react -> preact`
1042
- 2. File/Directory Aliases: `utils` -> `./src/utils`
1043
-
1044
- ```json
1045
- {
1046
- "name": "my-project",
1047
- "alias": {
1048
- "react": "preact-compat",
1049
- "react-dom": "preact-compat",
1050
- "utils": "./src/utils",
1051
- "components": "./src/components"
1052
- }
1053
- }
1054
- ```
1055
-
1056
- There are a couple of rules:
1057
-
1058
- 1. Aliases will only be respected when specified outside of `node_modules`.
1059
- 2. Aliases specified outside of `node_modules` will affect assets inside of `node_modules`.
1060
- 3. Aliases cannot build off of other aliases.
1061
- 4. Only one alias will be applied at a time.
1062
- 5. Aliases must be valid npm package names.
1063
-
1064
- ## Plugins
1065
-
1066
- ### Resolvers
1067
-
1068
- When one asset depends on another through an asset specifier, the resolver is
1069
- responsible for determining what asset is being requested.
1070
-
1071
- See [Asset Resolution](#asset-resolution) for more details.
1072
-
1073
- ```json
1074
- {
1075
- "resolvers": ["@parcel/resolver-v1"]
1076
- }
1077
- ```
1078
-
1079
- **Official Resolvers:**
1080
-
1081
- - `@parcel/resolver-v1`
1082
-
1083
- ### Transformers
1084
-
1085
- transformers _transform_ single assets as they are discovered and added to the
1086
- asset graph. They mostly call out to different compilers and preprocessors.
1087
-
1088
- ```json
1089
- {
1090
- "transformers": {
1091
- "*.js": ["@parcel/transformer-babel"]
1092
- }
1093
- }
1094
- ```
1095
-
1096
- **Official Transformers:**
1097
-
1098
- - `@parcel/transformer-babel`
1099
- - `@parcel/transformer-coffeescript`
1100
- - `@parcel/transformer-glsl`
1101
- - `@parcel/transformer-graphql`
1102
- - `@parcel/transformer-json`
1103
- - `@parcel/transformer-json5`
1104
- - `@parcel/transformer-less`
1105
- - `@parcel/transformer-posthtml`
1106
- - `@parcel/transformer-postcss`
1107
- - `@parcel/transformer-pug`
1108
- - `@parcel/transformer-raw`
1109
- - `@parcel/transformer-reason`
1110
- - `@parcel/transformer-rust`
1111
- - `@parcel/transformer-stylus`
1112
- - `@parcel/transformer-toml`
1113
- - `@parcel/transformer-typescript`
1114
- - `@parcel/transformer-vue`
1115
- - `@parcel/transformer-wasm`
1116
- - `@parcel/transformer-webmanifest`
1117
- - `@parcel/transformer-yaml`
1118
- - `@parcel/transformer-elm`
1119
- - ...
1120
-
1121
- ### Bundlers
1122
-
1123
- Bundlers accept the entire asset graph and turn it into sets of bundles.
1124
-
1125
- ```json
1126
- {
1127
- "bundler": "@parcel/bundler-default"
1128
- }
1129
- ```
1130
-
1131
- **Official Bundlers:**
1132
-
1133
- - `@parcel/bundler-default`
1134
-
1135
- ### Namers
1136
-
1137
- Namers accept a bundle and return a filename for that bundle.
1138
-
1139
- ```json
1140
- {
1141
- "namers": ["@parcel/namer-default"]
1142
- }
1143
- ```
1144
-
1145
- **Official Namers:**
1146
-
1147
- - `@parcel/namer-default`
1148
-
1149
- ### Runtimes
1150
-
1151
- Runtimes get called after the bundler phase and generate an asset which gets
1152
- included in the final bundle.
1153
-
1154
- ```json
1155
- {
1156
- "runtimes": {
1157
- "browser": ["@parcel/runtime-js", "@parcel/runtime-browser-hmr"],
1158
- "node": ["@parcel/runtime-js"]
1159
- }
1160
- }
1161
- ```
1162
-
1163
- **Official Runtimes:**
1164
-
1165
- - `@parcel/runtime-js`
1166
- - `@parcel/runtime-hmr`
1167
-
1168
- ### Packagers
1169
-
1170
- Packagers determine how to merge different asset types into a single bundle.
1171
-
1172
- ```json
1173
- {
1174
- "packagers": {
1175
- "*.css": "@parcel/packager-css"
1176
- }
1177
- }
1178
- ```
1179
-
1180
- **Official Packagers:**
1181
-
1182
- - `@parcel/packager-html`
1183
- - `@parcel/packager-js`
1184
- - `@parcel/packager-css`
1185
- - `@parcel/packager-wasm`
1186
- - `@parcel/packager-raw`
1187
-
1188
- ### Optimizers
1189
-
1190
- Optimizers are similar to transformers, but they accept a bundle instead
1191
- of a single asset.
1192
-
1193
- ```json
1194
- {
1195
- "optimizers": {
1196
- "*.js": ["@parcel/optimizer-terser"],
1197
- "*.css": ["@parcel/optimizer-csso"]
1198
- }
1199
- }
1200
- ```
1201
-
1202
- **Official Optimizers:**
1203
-
1204
- - `@parcel/packager-terser`
1205
- - `@parcel/packager-csso`
1206
- - [todo]
1207
-
1208
- ### Reporters
1209
-
1210
- Reporters receive events as they happen and can either use the Parcel logger to
1211
- output to stdout/stderr or they can return assets to be generated on the file
1212
- system.
1213
-
1214
- ```json
1215
- {
1216
- "reporters": ["@parcel/reporter-cli", "@parcel/reporter-dev-server"]
1217
- }
1218
- ```
1219
-
1220
- **Official Reporters:**
1221
-
1222
- - `@parcel/reporter-cli`
1223
- - `@parcel/reporter-dev-server`
1224
- - [todo]
1225
-
1226
- ### Validators
1227
-
1228
- Validators emit errors for source code after a build is completed.
1229
- For example, type checking and linting.
1230
-
1231
- ```json
1232
- {
1233
- "validators": {
1234
- "*.ts": ["@parcel/validator-typescript"]
1235
- }
1236
- }
1237
- ```
1238
-
1239
- **Official Validators:**
1240
-
1241
- - `@parcel/validator-typescript`
1242
- - `@parcel/validator-eslint`
1243
- - [todo]
1244
-
1245
- ## Creating Plugins
1246
-
1247
- ### Naming
1248
-
1249
- All plugins must follow a naming system:
1250
-
1251
- | | Official package | Community packages | Private company/scoped team packages |
1252
- | ---------- | -------------------------- | ------------------------- | ------------------------------------ |
1253
- | Configs | `@parcel/config-{name}` | `parcel-config-{name}` | `@scope/parcel-config[-{name}]` |
1254
- | Resolvers | `@parcel/resolver-{name}` | `parcel-resolver-{name}` | `@scope/parcel-resolver[-{name}]` |
1255
- | Transformers | `@parcel/transformer-{name}` | `parcel-transformer-{name}` | `@scope/parcel-transformer[-{name}]` |
1256
- | Bundlers | `@parcel/bundler-{name}` | `parcel-bundler-{name}` | `@scope/parcel-bundler[-{name}]` |
1257
- | Namers | `@parcel/namer-{name}` | `parcel-namer-{name}` | `@scope/parcel-namer[-{name}]` |
1258
- | Runtimes | `@parcel/runtime-{name}` | `parcel-runtime-{name}` | `@scope/parcel-runtime[-{name}]` |
1259
- | Packagers | `@parcel/packager-{name}` | `parcel-packager-{name}` | `@scope/parcel-packager[-{name}]` |
1260
- | Optimizers | `@parcel/optimizer-{name}` | `parcel-optimizer-{name}` | `@scope/parcel-optimizer[-{name}]` |
1261
- | Reporters | `@parcel/reporter-{name}` | `parcel-reporter-{name}` | `@scope/parcel-reporter[-{name}]` |
1262
- | Validators | `@parcel/validator-{name}` | `parcel-validator-{name}`| `@scope/parcel-validator[-{name}]` |
1263
-
1264
- The `{name}` must be descriptive and directly related to the purpose of the
1265
- package. Someone should be able to have an idea of what the package does simply
1266
- by reading the name in a `.parcelrc` or `package.json#devDependencies`.
1267
-
1268
- ```
1269
- parcel-transformer-posthtml
1270
- parcel-packager-wasm
1271
- parcel-reporter-graph-visualizer
1272
- ```
1273
-
1274
- If your plugin adds support for a specific tool, please use the name of the
1275
- tool.
1276
-
1277
- ```
1278
- parcel-transformer-es6 (bad)
1279
- parcel-transformer-babel (good)
1280
- ```
1281
-
1282
- If your plugin is a reimplementation of something that exists, try naming it
1283
- something that explains why it is a separate:
1284
-
1285
- ```
1286
- parcel-transformer-better-typescript (bad)
1287
- parcel-transformer-typescript-server (good)
1288
- ```
1289
-
1290
- We ask that community members work together and when forks happen to try and
1291
- resolve them. If someone made a better version of your plugin, please consider
1292
- giving the better package name over, have them make a major version bump, and
1293
- redirect people to the new tool.
1294
-
1295
- ### Versioning
1296
-
1297
- You must follow semantic versioning (to the best of your ability). No, it's not
1298
- the perfect system, but it's the best one we have and people do depend on it.
1299
-
1300
- If plugin authors intentionally don't follow semantic versioning, Parcel may
1301
- start warning users that they should be locking down the version number for
1302
- your plugin.
1303
-
1304
- > Warning: The plugin "parcel-transform-typescript" does not follow semantic
1305
- > versioning. You should lock the version range down so your code does not
1306
- > break when they make changes. Please upvote this issue to encourage them to
1307
- > follow semver: https://github.com/user/parcel-transform-typescript/issues/43
1308
-
1309
- ### Engines
1310
-
1311
- You must specify a `package.json#engines.parcel` field with the version range
1312
- of Parcel that your plugin supports:
1313
-
1314
- ```json
1315
- {
1316
- "name": "parcel-transform-imagemin",
1317
- "engines": {
1318
- "parcel": "2.x"
1319
- }
1320
- }
1321
- ```
1322
-
1323
- If you do not specify this field, Parcel will output a warning:
1324
-
1325
- ```
1326
- Warning: The plugin "parcel-transform-typescript" needs to specify a `package.json#engines.parcel` field with the supported Parcel version range.
1327
- ```
1328
-
1329
- If you do specify the parcel engine field and the user is using an incompatible
1330
- version of Parcel, they will see an error:
1331
-
1332
- ```
1333
- Error: The plugin "parcel-transform-typescript" is not compatible with the
1334
- current version of Parcel. Requires "2.x" but the current version is "3.1.4"
1335
- ```
1336
-
1337
- Parcel uses node-semver to match version ranges.
1338
-
1339
- ## Plugin APIs
1340
-
1341
- There are several different types of plugins. They all look very similar, but
1342
- are kept separate so we can have strict contracts one what each one is allowed
1343
- to do.
1344
-
1345
- There are some rules that should be followed across every type of plugin:
1346
-
1347
- - **Stateless** — Avoid any kind of state, it will likely be the source of bugs
1348
- for your users. For example, the same transform may exist in multiple
1349
- separate workers which are not allowed to communicate with one another, state
1350
- will not work as expected.
1351
- - **Pure** — Given the same input, a plugin must produce the same output, and
1352
- you must not have any observable side effects, or implicit dependencies.
1353
- Otherwise Parcel's caching will break and your users will be sad. You should
1354
- never have to tell users to delete their caches.
1355
-
1356
- The plugin APIs all follow a common shape:
1357
-
1358
- ```js
1359
- import {NameOfPluginType} from '@parcel/plugin';
1360
-
1361
- export default new NameOfPluginType({
1362
- async methodName(opts: JSONObject): Promise<JSONObject> {
1363
- return result;
1364
- }
1365
- });
1366
- ```
1367
-
1368
- They are made up of modules with well-known named exports of async functions
1369
- that:
1370
-
1371
- - Accept a strictly validated JSON-serializable `opts` object.
1372
- - Return a strictly validated JSON-serializable `vals` object.
1373
-
1374
- If something you need is not being passed through `opts`, please come talk to
1375
- the Parcel team about it. Avoid trying to get information yourself from other
1376
- sources, especially from the file system.
1377
-
1378
- ### Resolvers
1379
-
1380
- Resolvers get called with an asset request (consisting of a source file path
1381
- and the specifier of what is being requested) which it then attempts to
1382
- resolve. If the resolver isn't sure how to handle a request, it can also return
1383
- `null` and pass it to the next resolver in the chain.
1384
-
1385
- ```js
1386
- import {Resolver} from '@parcel/plugin';
1387
-
1388
- export default new Resolver({
1389
- async resolve({dependency}) {
1390
- // ...
1391
- return {filePath} || null;
1392
- }
1393
- });
1394
- ```
1395
-
1396
- ### Transformers
1397
-
1398
- Transformers _transform_ single assets as they are discovered and added to the
1399
- asset graph. They mostly call out to different compilers and preprocessors.
1400
-
1401
- ```js
1402
- import {Transform} from '@parcel/plugin';
1403
-
1404
- export default new Transform({
1405
- async parse({asset}) {
1406
- // ...
1407
- return ast;
1408
- },
1409
-
1410
- async transform({asset}) {
1411
- // ...
1412
- return [assets];
1413
- },
1414
-
1415
- async generate({asset}) {
1416
- // ...
1417
- return {code, map};
1418
- }
1419
- });
1420
- ```
1421
-
1422
- ### Bundler
1423
-
1424
- Bundlers accept the entire asset graph and modify it to add bundle nodes that group the assets
1425
- into output bundles.
1426
-
1427
- ```js
1428
- import {Bundler} from '@parcel/plugin';
1429
-
1430
- export default new Bundler({
1431
- async bundle({graph}) {
1432
- // ...
1433
- },
1434
-
1435
- async optimize({graph}) {
1436
- // ...
1437
- }
1438
- });
1439
- ```
1440
-
1441
- ### Namers
1442
-
1443
- Namers accept a bundle and output a filename for that bundle.
1444
-
1445
- ```js
1446
- import {Namer} from '@parcel/plugin';
1447
-
1448
- export default new Namer({
1449
- async name({bundle, bundleGraph}) {
1450
- // ...
1451
- return name;
1452
- }
1453
- });
1454
- ```
1455
-
1456
- ### Runtimes
1457
-
1458
- Runtimes accept a bundle and return assets to be inserted into that bundle.
1459
-
1460
- ```js
1461
- import {Runtime} from '@parcel/runtime';
1462
-
1463
- export default new Runtime({
1464
- async apply({bundle, bundleGraph}) {
1465
- // ...
1466
- return assets;
1467
- }
1468
- });
1469
- ```
1470
-
1471
- ### Packagers
1472
-
1473
- Packagers determine how to merge different asset types into a single bundle.
1474
-
1475
- ```js
1476
- import {Packager} from '@parcel/plugin';
1477
-
1478
- export default new Packager({
1479
- async package({bundle}) {
1480
- // ...
1481
- return {contents, map};
1482
- },
1483
- });
1484
- ```
1485
-
1486
- ### Optimizers
1487
-
1488
- Optimizers are similar to transformers, but they accept a bundle instead
1489
- of a single asset.
1490
-
1491
- ```js
1492
- import {Optimizer} from '@parcel/plugin';
1493
-
1494
- export default new Optimizer({
1495
- async optimize({bundle, contents, map}) {
1496
- // ...
1497
- return {contents, map};
1498
- }
1499
- });
1500
- ```
1501
-
1502
- ### Reporters
1503
-
1504
- Reporters receive events as they happen and can output to stdout/stderr,
1505
- or perform other actions.
1506
-
1507
- ```js
1508
- import {Reporter} from '@parcel/plugin';
34
+ Read the docs at https://parceljs.org/docs/.
1509
35
 
1510
- export default new Reporter({
1511
- async report({ event: { type, ... } }) {
1512
- // ...
1513
- }
1514
- });
1515
- ```
36
+ ## Community
1516
37
 
1517
- ### 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).
1518
41
 
1519
- Validators receive an asset, and can throw errors if that asset is invalid
1520
- in some way, e.g. type errors or linting errors.
42
+ ## Contributors
1521
43
 
1522
- ```js
1523
- 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>
1524
46
 
1525
- export default new Validator({
1526
- async validate({asset}) {
1527
- // ...
1528
- throw error;
1529
- }
1530
- });
1531
- ```
1532
- 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
1533
48
 
1534
- ```js
1535
- import {Validator} from '@parcel/plugin';
49
+ Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/parcel#backer)]
1536
50
 
1537
- export default new Validator({
1538
- async validateAll({assets}) {
1539
- // ...
1540
- throw error;
1541
- }
1542
- });
1543
- ```
51
+ <a href="https://opencollective.com/parcel#backers" target="_blank"><img src="https://opencollective.com/parcel/backers.svg?width=890"></a>
1544
52
 
1545
- 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
1546
54
 
1547
- ## 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)]
1548
56
 
1549
- 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>