facebook / create-react-app

Set up a modern web app by running one command.
https://create-react-app.dev
MIT License
102.78k stars 26.87k forks source link

SVG files imported as React components should not end up in build directory #9167

Open dominique-mueller opened 4 years ago

dominique-mueller commented 4 years ago

Intro

SVG files can be imported as React component, and thus inlined into the bundle, using the following syntax:

import { ReactComponent as MySvg } from '../../assets/icons/my-svg.svg'

Actual behaviour

Although inlined, the original SVG files will still be processed (by Webpack?) and end up

Overall, this isn't critical - it only means that unused files end up in the build folder. Nevertheless, it's a very confusing behaviour, developers might assume those files are being used or even that SVGs imported the way described above are not being inlined.

Expected behaviour

The expected behaviour is that inlined resources do not end up in the build folder, resulting in a smaller and clean build folder.

Related

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

dominique-mueller commented 4 years ago

Not stale.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

dominique-mueller commented 4 years ago

Not stale.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

dominique-mueller commented 4 years ago

Not stale.

Soberia commented 3 years ago

Overall, this isn't critical

It's critical when using Service Worker. Because SVG files also included in self.__WB_MANIFEST value which contains URLs to precache. That means browsers will send requests to precache all these SVG files which don't need at all