Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialfairest
Full Stack JavaScript Techdegree Graduate 19,303 PointsWhy does a named import increase the Package size?
import React from 'react'; Package size = 8K import React, { Component } from 'react'; Package size = 8.1K
This feels counter intuitive.
3 Answers
Zimri Leijen
11,835 PointsIt seem to me like you import React completely, and in addition you import a module from react.
Try import { Component } from 'react';
fairest
Full Stack JavaScript Techdegree Graduate 19,303 Pointsimport { Component } from 'react';
Breaks the app. I don't see the advantage of using:
import React from 'react';
VS
import React, { Component } from 'react'
If it only saves you typing the React. part but increases your package size, it down't seem worth it.
James Crosslin
Full Stack JavaScript Techdegree Graduate 16,882 Pointstl;dr - development files aren't production files, and their size isn't reflective of the final product.
I think that this is a fundamental misunderstanding of your React dev environment vs your compiled final product. The create-react-app structure only has your dev files, and when it's time to move your product to production, you use
npm build
to compile those build files into a set of productions files. Those production files do not use all of those individual imports in your final build. Instead, the dev environment compiles your javascript, rendered html, and css, minifying and bundling them for you in the most efficient way possible (according to the environment's logic).