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

[tsdx-config] Rollup Image Plugin #386

Closed
vongohren opened this issue Dec 20, 2019 · 10 comments
Closed

[tsdx-config] Rollup Image Plugin #386

vongohren opened this issue Dec 20, 2019 · 10 comments
Labels
scope: integration Related to an integration, not necessarily to core (but could influence core) solution: duplicate This issue or pull request already exists

Comments

@vongohren
Copy link

Current Behavior

I just wanted to add image plugin: https://github.com/rollup/plugins/tree/master/packages/image

const image = require('@rollup/plugin-image');

module.exports = {
  // This function will run for each entry/format/env combination
  rollup(config, options) {
    config.plugins.push(image(),);
    return config; // always return a config.
  },
};

Just like explained in the docs for customization: https://github.com/jaredpalmer/tsdx#rollup
The image is quite simple
But this happens:

Error: Unexpected character '�' (Note that you need plugins to import files that are not JavaScript)

at /location/assets/images/logo_brandmark.png:1:0

1: �PNG
   ^

Expected behavior

That it works and the image becomes base64 imported.

Suggested solution(s)

Not really sure

Additional context

Should be straight forward since we tap into the rollup config.

Your environment

Software Version(s)
TSDX 0.12.0
TypeScript 3.7.3
Browser N/A
npm/Yarn 1.15.2
Node 10.15.1
Operating System MacOS
@swyxio
Copy link
Collaborator

swyxio commented Dec 21, 2019

interesting. can you trace this error please? we are probably using an incompatible plugin somewhere higher up.

@vongohren
Copy link
Author

@sw-yx what is the best way of tracing it?

@swyxio
Copy link
Collaborator

swyxio commented Dec 21, 2019

go into rollup's code, add a breakpoint or debugger statement somewhere, step through until you get the error? im not an expert but that's how i do it. its surprisingly powerful.

https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_attaching-to-nodejs

@vongohren
Copy link
Author

Screenshot 2019-12-21 at 20 25 09

@sw-yx I think I just dont know what too look for 😄 Im using ndb to get a debugging window and stepping through, the picture is when I got the error, not sure what to look for there? Tried stepping back in the callstack without becoming any smarter.

Got any other good suggestions? If not its just to add this plugin into a demo repo, and import a png to test out 😸

@vongohren
Copy link
Author

It seems like there is a conncetion with this issue: #278 And there is a workaround there

@ambroseus ambroseus mentioned this issue Dec 22, 2019
@swyxio
Copy link
Collaborator

swyxio commented Dec 22, 2019

ok.. does that work for you?

@vongohren
Copy link
Author

I have not tried yet :D Got a differnt problem to tackle first :P

@vongohren
Copy link
Author

@sw-yx it worked.

I did this, so using a different lib than the suggested from his comment.

const images = require('@rollup/plugin-image');

module.exports = {
  rollup(config, options) {
    config.plugins = [
      images({ incude: ['**/*.png', '**/*.jpg'] }),
      ...config.plugins,
    ]

    return config
  },
}

@vongohren
Copy link
Author

Closing based on these cases: #278 & #379

@swyxio
Copy link
Collaborator

swyxio commented Dec 23, 2019

great.

@agilgur5 agilgur5 added the solution: duplicate This issue or pull request already exists label Mar 9, 2020
@agilgur5 agilgur5 added the scope: integration Related to an integration, not necessarily to core (but could influence core) label Mar 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: integration Related to an integration, not necessarily to core (but could influence core) solution: duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants