fansenze / snowpack-plugin-inliner

A plugin for snowpack which transforms files into base64 URIs.
MIT License
1 stars 2 forks source link

Is copying files necessary? #2

Closed canadaduane closed 2 years ago

canadaduane commented 4 years ago

I apologize for all the questions haha. I'm trying to see if snowpack-plugin-inliner will work in our case.

I'm considering using this plugin for CSS. For example, our CSS has relative URLs--relative to each component. I'd like to transform the CSS in a component sub-folder like this:

/* FILE: src/components/button/button.css (Note: icon.png is also in the same folder) */
background-image: url(./icon.png);

into

/* FILE: src/components/button/button.css */
background-image: url(/_dist_/src/components/button/icon.png);

Of course, when icon.png is below a certain size threshold, then it would be inlined as a data: URI.

So my question is, why does snowpack-plugin-inliner copy files at all? I'm new to snowpack, but it seems snowpack copies all files in my components' sub-folders.

For example, if I have files in src/components/* snowpack automatically copies them to build/_dist_/components/* when building, or hosts them on the dev server at _dist_/components/* when in development mode. So, no need to copy?

canadaduane commented 4 years ago

I think I may have a partial answer to my question: It looks like there is a bug in the current version of snowpack that prevents files from being copied when they are binary/buffer type objects: https://github.com/pikapkg/snowpack/pull/1313#issuecomment-708698874

fansenze commented 4 years ago

maybe the cache of snowpack...

enter root of your project, try to use commands:

$ rm -rf ./build
$ npx snowpack dev --reload