InterviewSolution
| 1. |
What is Webpack? |
|
Answer» Webpack is a tool for bundling javascript files for usage in browsers. Webpack analyses the APPLICATION and generates the bundles by creating a dependency graph that maps each module of the PROJECT required. It enables you to execute the environment that was hosted by Babel. A web pack has the ADVANTAGE of combining numerous modules and packs into a single JavaScript file. It includes a dev server, which aids with code updates and asset management. Write your code: folder_name/index.js import bar from './func.js';func();folder_name/func.js export DEFAULT function func() { // body of the function}Bundle it: Either provide with custom webpack.config.js or without config: const path = require('path');module.exports = { entry: './folder_name/index.js', output: { path: path.resolve(__dirname, 'dict'), filename: 'bundle.js', },};page.HTML <!DOCTYPE html><html> <head> <meta charset="utf-8" /> ... </head> <body> ... <script src="dict/bundle.js"></script> </body></html>You, then, need to run the webpack on the command-line in order to create bundle.js. |
|