🔧
Intermediate
5 min readBuild Tools & Bundlers
Webpack, Vite, npm, and modern build tools
Build Tools & Bundlers Interview Questions
Master modern build tools and package managers for frontend development.
1. npm & Package Management
# Install dependencies
npm install
npm install package-name
npm install --save-dev jest
# Scripts
npm run build
npm run test
npm run dev
# Package.json scripts
{
"scripts": {
"dev": "vite",
"build": "vite build",
"test": "jest"
},
"dependencies": {},
"devDependencies": {}
}
# Semantic versioning
^1.2.3 // 1.x.x (minor updates)
~1.2.3 // 1.2.x (patch updates)
1.2.3 // Exact version
2. Webpack Configuration
// webpack.config.js
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].[contenthash].js'
},
module: {
rules: [
{
test: /\.jsx?$/,
use: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html'
})
],
optimization: {
splitChunks: {
chunks: 'all'
}
}
};
3. Vite Configuration
// vite.config.js
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
export default defineConfig({
plugins: [react()],
build: {
outDir: 'dist',
sourcemap: true
},
server: {
port: 3000
}
});
Key Takeaways:
- Webpack bundles and transforms code
- Vite offers faster dev server with ESM
- Use npm scripts for common tasks
- Understand semantic versioning
- Configure loaders for different file types