Deploying Parcel Apps to Netlify and Vercel Quiz Quiz

Explore key concepts for deploying Parcel-built applications to leading static hosting platforms with this focused quiz, covering build configurations, environment setup, asset handling, and deployment strategies. Ideal for those seeking to streamline web project deployments with optimized Parcel workflows.

  1. Selecting the Build Output Directory

    When deploying a Parcel app, which directory should you specify as the publish directory to ensure only built static files are served?

    1. src
    2. config
    3. dist
    4. node_modules

    Explanation: The 'dist' directory contains the output of the Parcel build process and should be published to serve only the optimized static files. The 'src' directory holds your source code, not build output. 'node_modules' contains dependencies and should never be served as is. 'config' likely holds configuration files, which are not meant to be public-facing. Using the wrong directory may expose unnecessary files or break your deployment.

  2. Setting the Build Command

    Which build command should you set in your deployment settings for a typical Parcel project using the default configuration?

    1. npm run dev
    2. node server.js
    3. npm install
    4. parcel build

    Explanation: 'parcel build' triggers Parcel to bundle and optimize your app for production deployment. 'npm install' only installs dependencies and does not build the project. 'npm run dev' starts a development server, which isn't suitable for production hosting. 'node server.js' is used for starting backend servers, not for building static assets. Setting the correct build command ensures only optimized output is generated.

  3. Handling Clean URLs for Single Page Applications

    To ensure a single page app built with Parcel serves index.html for all routes (for example, navigating to /about), which file should you include in the root of your published directory?

    1. robots.txt
    2. _redirects
    3. .env
    4. .parcelrc

    Explanation: Including an '_redirects' file allows the hosting platform to route all requests to index.html, which is essential for clean URL support in single page apps. 'robots.txt' is for search engine crawlers, not routing. '.parcelrc' is a build configuration file unrelated to routing. '.env' files store environment variables, not routing rules. The '_redirects' file ensures your app's navigation works as intended.

  4. Environment Variable Configuration During Deployment

    If your Parcel app uses environment variables for API keys or secrets, where is the safest place to set these during deployment?

    1. In README.md
    2. In the platform’s environment variable settings
    3. Inside index.html
    4. Hardcoded in the JavaScript source

    Explanation: Environment variables should be set in the platform's deployment settings for security and flexibility; this keeps them out of your codebase. Placing them in 'index.html' or hardcoding in your JavaScript exposes sensitive data to the public. Documenting variables in 'README.md' is informative but does not actually set them for the build process. Secure handling of environment variables protects your app and users.

  5. Dealing with Static Asset Paths

    If your images and assets are not appearing after deployment of a Parcel app, which configuration issue is most likely the cause?

    1. Version mismatch in package.json
    2. Uncommitted changes in .gitignore
    3. Incorrect public URL configuration
    4. Syntax error in style.css

    Explanation: An incorrect public URL setting can cause the app to generate asset paths that do not match their deployed location, leading to missing files. A syntax error in 'style.css' may affect styles but won't usually break asset loading. A version mismatch in 'package.json' can cause build issues, but not typically broken asset paths. Uncommitted changes in '.gitignore' affect version control, not deployment output. Always verify public URL settings for proper static asset delivery.