Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i ignore bundling of images? #1379

Closed
nrgwsth opened this issue May 17, 2018 · 11 comments
Closed

How can i ignore bundling of images? #1379

nrgwsth opened this issue May 17, 2018 · 11 comments

Comments

@nrgwsth
Copy link

nrgwsth commented May 17, 2018

Is there any way in parcel to ignore bundling of certain assets. I am running parcel on my html file and i only want to bundle my js files. Is there any way to achieve this?

@DeMoorJasper
Copy link
Member

You can use multiple entrypoints to only bundle javascript.
There currently is no way to ignore certain files.
Duplicate of #144, #1186, #357 and #1087

@derolf
Copy link

derolf commented May 24, 2018

All the referenced tickets contain some sort of workaround or special semantics to avoid having a configuration.

I think we are in a catch22 here — what is the lesser evil: special semantics, workarounds, or a configuration?

@sgf
Copy link

sgf commented Aug 16, 2018

@DeMoorJasper

how Exclude some Modules such like Vue.js,i hope the parcel do not pack Vue in the Single Js output file.

@DeMoorJasper
Copy link
Member

@sgf not sure if I understand, Vue is part of the app right?

Open up a new issue with examples and a more detailed description

@sgf
Copy link

sgf commented Aug 21, 2018

@DeMoorJasper
yes but some time ppl need use CDN.
and i found the parcel Parse some dependencies is incorrect

my problem is same like #144

@npulidom
Copy link

@nrgwsth, if you are using stylus, I resolved using embedurl instead of url or src directives in your stylus files. Parcel will ignore that directive and stylus will replace that directive for url, keeping the relative path.

.my-class
    background embedurl('../images/icons/action/upload.svg') no-repeat

@revelt
Copy link

revelt commented Jul 8, 2020

I think this ticket was closed prematurely and should be reopened. #144 is about node_modules and ignoring React.

If it helps, let me describe the problem again.

Imagine a static website project (Eleventy) using Parcel to process .pcss files. That's PostCSS — it does need to be processed. However, images used there, as in background-image: url("images/image.png") — don't. That's because Eleventy is set up to copy all static assets directly to dist/images/ and Parcel messes up the paths. And image optimisation is done manually, in PS.

As a temporary measure, I have to use absolute paths and hardcode http://localhost, then use another script to run during prod builds and rename that into real domain url...

If this challenge is somehow solved already (I saw vague comments on #144 alluding it's solved on Parcel v2), then documentation needs to address this — this ticket is a great way to track documentation tasks like that.

Personally, I'd solve this by adding a glob whitelist on asset paths. Parcel would still try to resolve as usual, but it would skip user-supplied glob paths. For example, in package.json, user would add parcel: { ignore: { "*/images/*" and all paths in .pcss that Parcel tries to resolve would get skipped. It's easy to make a program to skip operations, isn't it?

@hash-bang
Copy link

This is a blocking issue for us moving to Parcel too.

To give a really easy example assume the following HTML:

<img src="/assets/logo.svg"/>

Our web server handles the serving of everything from the /assets directory (properly cached and 304 handled). We don't want those resources bundling into Parcel but there is no way I can find of excluding them.

Having a glob list of excluding files as suggested by @revelt would be great.

@nikrowell
Copy link

nikrowell commented May 9, 2021

There currently is no way to ignore certain files.

@revelt @hash-bang I know this is an old discussion, but adding the following to the top of Asset.addURLDependencyseemed to achieve to goal of ignoring certain files. Perhaps there is a way to do this through a plugin if someone is interested.

if (url.endsWith('.svg')) {
  return url;
}

Edit: Basic plugin created - parcel-plugin-ignore-assets - I'm sure this overlooks a lot of use cases, but met my needs while using still using Parcel 1.x

@hash-bang
Copy link

@nikrowell, oh wow. Thanks for that.

@VladimirMikulic
Copy link

I've made a plugin that excludes assets from bundling in Parcel 2.
Check it out https://www.npmjs.com/package/parcel-resolver-ignore

  1. npm i parcel-resolver-ignore -D
  2. .parcelrc
{
  "extends": "@parcel/config-default",
  "resolvers": ["parcel-resolver-ignore", "..."]
}
  1. package.json
{
  "parcelIgnore": [
    "assets\/*.*"
  ]
}

It's good to go!
Let me all know what you think!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants