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

copy loader #2255

Closed
arcanis opened this issue May 18, 2022 · 2 comments · Fixed by #2320
Closed

copy loader #2255

arcanis opened this issue May 18, 2022 · 2 comments · Fixed by #2320

Comments

@arcanis
Copy link

arcanis commented May 18, 2022

Let's say I have an image I reference via import:

import img from './my-img.png';

The file loader currently copies my-img.png into the output folder, and includes its path in the bundle as a string:

const img_default = './my-img-KWEBOZZ6.png';

I'd instead need a copy loader that would copy the file (like the file loader does) but, instead of turning it into a string, preserves it as an import statement:

import img from './my-img-KWEBOZZ6.png';

The reason for that is that I'm post-processing my Esbuild through Webpack to address the lack of CJS bundle splitting (it's roughly 2x slower, but still vastly better than pure Webpack builds); if the imports aren't preserved, Webpack won't know about the asset and the final output will be missing it.

@mixtur
Copy link

mixtur commented Sep 21, 2023

I know that this is not exactly the right place to ask, but is it possible to achieve the same behavior in Webpack itself?

@mixtur
Copy link

mixtur commented Sep 30, 2023

I didn't find the exact solution, but in our project we have a Lerna-based monorepo. So we moved assets to a separate package and then on production made the assets package external. (There are still some issues with WebWorkers though)

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

Successfully merging a pull request may close this issue.

2 participants