Babel Flashcards

1
Q

What is babel?

A

It is a transpiler used to transpile Javascript.

This can be JSX to Vue/React’s Javascript (React.createElement for example)

ES6 to ES5

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

Presets vs plugins

A

Presets include a grouping of plugins.

Plugins can be to for example transpile JSX to React/Vue Javascript (React.createElement for example)

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

How to use babel?

A

Install the @babel/core, @babel/cli and then presets or plugins that you want to use and add to .babelrc

Now it can be used in conjunction with Webpack, gulp, rollup or other bundlers.

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

What is tree shaking?

A

When es6 imports are done, all the functions from a file are included in bundle even if only one function is used. Webpack and other bundlers can be set up to remove the unused functions which are called dead code.

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

Explain babel, bundlers, module aliases, typescript, eslint, prettier, husky and lint-staged setup.

A

Babel does javascript transpiling based on plugins and presets as well as import aliases, setup using the babel-plugin-module-resolver plugin setup in babelrc file. For example JSX to React.createElement and ES6 to ES5.

Bundlers like webpack OR vite run babel to do transpilation.

Creact React App and others abstract the bundler from you.

Typescript and its bundler can also do the ES6 and JSX transpilation for you without using babel. Setup import aliases, JSX transpilation etc in tsconfig file.

Eslint –init creates eslint config file
Eslint.config.js with default settings. Plugins extend the functionality from only Javascript to react hooks for example of you install and configure it. Add plugin in plugins property and add the standard settings via extends property. Prettier plugin can be installed to lint files with prettier. Add files and folders to ingores property if needed.

Prettier, list files to ignore in .prettierignore and add prettier setup to prettierrc.js file.

Husky runs lint-staged during precommit. Lint-staged fixes files with eslint and prettier when possible and prevents commit when eslint fails.

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