A
A
alex4answ2020-12-11 11:31:16
webpack
alex4answ, 2020-12-11 11:31:16

Why specify the full path to the js file if there is tree shaking?

Good afternoon, I look at the manuals and a lot where this design is used:

import AppBar from '@material-ui/core/AppBar';
import ToolBar from '@material-ui/core/ToolBar';
// тут еще 20 импортов таких же


Why not use instead:
import {
  AppBar, 
  ToolBar,
  // other
} from '@material-ui/core';


If there is tree shaking, why specify such paths?
Lessons and manuals are not so old, then there was already webpack tree skaking

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lookfortheroot, 2020-12-11
@lookfortheroot

Export through brackets - named:

//module.js
function myModule() {...}
export { myModule }

//other.js
import { myModule } from 'module.js'

Export via name - default:
//module.js
function myModule() {...}
export default myModule();

//other.js
import myModuleOtherName from 'module.js' //  для default можно использовать любое имя

Here's the full description: https://learn.javascript.ru/import-export
This has absolutely nothing to do with tree-shaking. If it does not work, the cause must be sought elsewhere.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question