parcel 2.0.0-rc.0 → 2.1.1

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