ES6 modules, webpack & npm Flashcards

1
Q

What does npm stand for?

A

node package manager

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does npm give you access to?

A

Gigantic repository of plugins, libraries and tools

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Few examples of how you can use npm

A
  1. adapt pacakges of code for your apps
  2. download standalone tools
  3. share code with any npm user
  4. run packages without downloading using npx
  5. manage multiple versions of code and code dependencies
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are npm unscoped packages? Syntax for installing it?

A

Packages, that are always public. It means they can be searched for, downloaded and installed by anyone

npm install <package></package>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the requirement of installing scoped public packages? Syntax?

A

As long as the scope name is referenced, it can be downloaded by anyone.

npm install @scope/package-name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does package.json file do? (3)

A
  1. Lists the packages your project depends on
  2. Specifies versions of a package that your project can use
  3. Makes your build reproducible, therefore it’s easier to share it with other
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What kind of fields package.json must contain?

A

Name and Version fields. Author is not mandatory

{
“name”: “my-awesome-package”,
“version”: “1.0.0”,
“author”: “Your Name email@example.com
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which command creates package.json?

A

npm init

more info: https://docs.npmjs.com/creating-a-package-json-file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are ‘devDependencies’ and ‘Dependencies’? Where are they located and how are they created?

A

They are two properties which are added to package.json when a package is installed as development (devDependency) or production dependency.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

When are devDependencies being used?

A

During the development stage, they are not needed on the production side. So it would be wiser to use –save-dev with those packages

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

When do you add a dependency into the ‘dependencies’ property? Knowing that devDependency is also an option

A

When this dependency is used both in development and production phase. So it would be wise to use –save with those packages

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is Webpack used for?

A

For bundling modules

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How many components does ES6 modules have? What are they?

A

2
import and export

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is export declaration used to?

A

To export values from a JavaScript module

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

In order to use “import” or “export” declaration in source file, what the file must be interpreted as?

A

The file must be interpreted as module

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you interpret the file as a module in HTML?

A

In the

 tag you must put type="module"
17
Q

What are the four forms of import declarations? With syntax.

A
  1. Named import.
    Ex: import { export1, export2 } from “module-name”;
  2. Default import.
    Ex: import defaultExport from “module-name”;
  3. Namespace import.
    Ex: import * as name from “module-name”;
  4. Side effect import.
    Ex: import “module-name”;
18
Q

If you want to export several functions which method should you use? Syntax?

A

Named export.

const functionOne = () => ‘ONE’;
const functionTwo = () => ‘TWO’;

export {
functionOne,
functionTwo
};

19
Q

What is package.json?

A

Package.json file is the heart of any Node project which holds various metadata relevant to it. Package.json file is used to give information to npm that allows it to identify the project as well as handle the project’s dependencies.

20
Q

Explain what the concepts “entry” and “output” mean as relates to webpack.

A

Usually files are put into “src” and “dist” folders. In “src” (source directory) there are files which are going to be bundled up by Webpack (when it runs it’s going through all the files, looking for “import”, then compiles all of the code we need to run our site into a single file inside of the dist folder).

Our entry file, then is the main application file that links (either directly or indirectly) to all of the other modules in our project. In this example, it is /src/index.js. The output file is the compiled version - dist/main.js

21
Q

When is export default used?

A

Only when there is one export to be made from a particular file