π 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 (read more about named pipelines in Plugin Configuration)
Alternatively, you can use a custom .parcelrc
to opt into the old behaviour (add more asset extensions if you use them):
ΒΆ 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 page 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).