WebPack 4 Flashcards
What is webpack?
Webpack is a build tool that allows us to take all of our assets and turn them into a production-ready bundle.
What are all of our files considered in webpack?
Modules.
What are top three benefits of working with webpack?
- Require assets, load when needed
- Code splitting – load only the code that the page requires, minimise initial loading time.
- Transformations – React/ES6 to vanilla JS, Sass/Less to CSS, etc.
What’s new in webpack 4?
Give 4 answers.
- No more support for Node.js 4
- Up to 98% faster
- Dev and production mode
- Support for WebAssembly
What’s the difference between dev and production mode?
In production mode, the build size is prioritised.
In dev mode, the speed of the build is optimised.
How do you run webpack in watch mode?
By using the -w flag.
What’s the default config for webpack?
webpack.config.js
How do you specify a custom config file for webpack?
By using the –config flag.
What do webpack loaders help us with?
Give 3 answers.
- Perform transformations on files
- Help load files and images
- Deal with dialects
How do you specify the starting file of your project in the webpack config?
By using the ‘entry’ key inside module.exports
How do you specify the output file for your project in the webpack config?
By using the ‘output’ key inside module.exports to specify an object with two keys: ‘filename’ and ‘path’. ‘filename’ is the name of the file wherease the ‘path’ is where to put this file, which you can specify by using path.resolve and passing it two parameters: __dirname and the name of the folder you want to be created at the root of the project for bundling.
How do you specify what loaders to use and how in webpack config?
By using the ‘module’ key inside module.exports object and assigning it an object with the key ‘rules’, which is an array containing objects. In each object, you create a ‘test’ key to specify the filter for which files to use the loader for and ‘use’ to specify which loaders to use. Use is an array of objects that each has a key of ‘loader’, specifying the name of the loader. You can also use the ‘exclude’ key in rule objects to specify what file/folders to exclude. For example, commonly, you exclude node_modules from the babel-loader.
What webpack loaders can you use to load .css files?
style-loader and css-loader
What webpack loader can you use to load images?
url-loader
What does code splitting do?
It breaks up your code into different bundles. This can be done using multiple entrypoints.