-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[v2] - Tree shaking not working correctly with some libraries (react-icons) #7581
Comments
@pzenger I think tree-shaking primarily seems to work for ES6 modules whereas react-icons is using CommonJS: https://cdn.jsdelivr.net/npm/[email protected]/fa/index.js For tree-shaking with Perhaps it's worth checking out webpack's sideEffects flag per this issue |
@cpboyd Hmm interesting, I'll need to dig more into this. |
according to the ongoing discussion over at |
update: I have found a workaround to get // gastby-node.js
exports.onCreateWebpackConfig = () => {
actions.setWebpackConfig({
resolve: {
extensions: ['.mjs', '.js'],
},
module: {
rules: [
{
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto',
},
],
},
})
} // src/pages/index.js
// it is necessary to specify index.mjs or webpack will choose index.js by default.
import { FaBeer } from 'react-icons/fa/index.mjs';
const IndexPage = () => (
<FaBeer/>
)
export default IndexPage tree shaking does work with this method, my bundle size is much smaller than if I use using |
Probably we should add support for .mjs in core. Can anyone think of a reason not to do this? |
Description
Using
react-icons
with a few imported icons, results in the full library being imported. The project (react-icons) seems to be setup correctly and working with other frameworks, so I believe this is an issue with the webpack configuration/defaults.Relevant discussion
react-icons/react-icons#154
Steps to reproduce
import { FaBeer } from 'react-icons/fa'
use <FaBeer /> in a component
npm run build
=> Results in a bloated webapp
The text was updated successfully, but these errors were encountered: