๐ Migration
Some tips for migration from Parcel 1 to Parcel 2
For the most part, you shouldn't have to change much when upgrading to Parcel 2:
ยถ Code Changes
ยถ Importing non-code assets from Javascript
If you want import the url to an image (or a soundfile, etc.) from Javascript, you need to prepend url:
to the module specifier (more details in Plugin Configuration)
Alternatively, you can use a custom .parcelrc
to opt into the old behaviour.
ยถ Typescript
Parcel 1 transpiled TypeScript using tsc
(the official TypeScript compiler). Parcel 2 instead uses Babel (using @babel/preset-env
) by default. This has two notable consequences:
(The TypeScript recipe contains more informations - and limitations - of Parcel's TypeScript handling.)
ยถ @babel/preset-typescript
Isn't inserted Automatically into a Custom .babelrc
.
For most use cases, transpiling using Babel is enough, so Parcel includes @babel/preset-typescript
in its default Babel config for TypeScript assets. You need to specify it manually however if you are using a custom .babelrc
:
ยถ Babel Doesn't Read tsconfig.json
In case Babel doesn't work for you (e.g. because of an advanced tsconfig.json
), you can use tsc
:
ยถ Importing GraphQL
When import GraphQL files (.gql
), imports are still resolved/inlined (using graphql-import-macro
), but you now get the processed GraphQL query as a string instead of an Apollo AST.
ยถ Configuration/CLI
ยถ package.json#main
Many package.json
s (e.g. the one generated by npm init
) contains main: "index.js"
which ignored by most tools (for non-library projects). Parcel 2 will however use that value as the output path (see Configuration#main),
for most web apps, this line should simply be removed.
ยถ --target
This CLI flag is now inferred from your package.json
, one of these three properties is enough (number denotes priority).
ยถ --experimental-scope-hoisting
Parcel 2 has scope hoisting enabled by default; to disable it, add --no-scope-hoist
.
ยถ --bundle-node-modules
To bundle packages from node_modules
when targetting Node.js, you now should specify that in the target configuration:
ยถ --out-dir
To align --out-dir
with the options in package.json#targets
, that option was renamed to --dist-dir
.
ยถ --out-file
This flag, was removed and the path should instead be be specified in package.json
(see Configuration).
ยถ --log-level
The log levels now have names instead of numbers (none
, error
, warn
, info
, verbose
)
ยถ --global
This option has been removed without a replacement (for now).