Giter VIP home page Giter VIP logo

parcel-resolver-ignore's Introduction

parcel-resolver-ignore

Version License: MIT Twitter: VladoDev

๐ŸŒ€ Parcel plugin that allows you to ignore assets/import syntax from bundling.

๐Ÿ“ฆ Installation

# Installs the plugin and saves it as a development dependency
npm i parcel-resolver-ignore -D

๐Ÿ”Œ Configuration

We need to create .parcelrc configuration file and add the plugin to resolvers like this:

Syntax "..." instructs Parcel to apply the plugin on top of existing resolvers

{
  "extends": "@parcel/config-default",
  "resolvers": ["parcel-resolver-ignore", "..."]
}

โ˜๏ธ Usage

Sometimes, some of our files are not available at build time or we simply don't want Parcel to process them. Or maybe we use special templating syntax for importing files that Parcel doesn't recognize and throws an error.

This is where parcel-resolver-ignore comes into play. You can find example use-cases below.

โ„น๏ธ NOTE: Examples below are HTML files, but the plugin works with EVERY file (i.e. CSS).

  1. Excluding files from processing

package.json

{
  // An array of Regex patterns
  "parcelIgnore": ["jquery.min.js", "privacy-policy.html", "images/*.*"]
}

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <h1>My Title</h1>
    <!-- This won't throw build error -->
    <a href="./privacy-policy.html">File not available at build time.</a>

    <!-- These won't be processed by Parcel -->
    <img src="./images/my-image.png" alt="my PNG image" />
    <img src="./images/my-image.jpg" alt="my JPG image" />
    <script src="jquery.min.js"></script>
  </body>
</html>
  1. Ignoring special syntax (i.e. from templating engines)

package.json

{
  // An array of Regex patterns
  "parcelIgnore": ["{{*.*}}"]
}

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <h1>My Title</h1>
    <!-- This won't throw build error -->
    <script src="{{scriptSrc}}"></script>
  </body>
</html>
  1. Ignoring files based on NODE_ENV value : "development" (parcel serve) or "production" (parcel build) or custom.

package.json

{
  // An object containing dev and/or prod files to ignore
  "parcelIgnore": {
    "development": ["privacy-policy.html", "images/*.*"],
    "production": ["jquery.min.js", "images/*.*"],
    "test": ["jquery.min.js"]
  }
}

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <h1>My Title</h1>
    <!-- This won't throw build error -->
    <a href="./privacy-policy.html">File not available at build time.</a>

    <!-- These won't be processed by Parcel -->
    <img src="./images/my-image.png" alt="my PNG image" />
    <img src="./images/my-image.jpg" alt="my JPG image" />
    <script src="jquery.min.js"></script>
  </body>
</html>

๐Ÿš€ Build

parcel build src/index.html # Success!

๐Ÿ”ง Troubleshooting

If you ran Parcel just before adding this plugin, it's possible that stale Parcel caches are causing build failures. First, try to delete the caches folder .parcel-cache in your project's root directory.

๐Ÿ‘จ Author

Vladimir Mikulic

๐Ÿค Contributing

Contributions, issues and feature requests are welcome!

๐Ÿ“ License

This project is licensed under MIT license.

๐Ÿ‘จโ€๐Ÿš€ Show your support

Give a โญ๏ธ if this project helped you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.