[WEBPACK] 12+. Webpack : webpack-dev-server

https://www.youtube.com/watch?v=zK9ek82u_Lg&list=PLJ5qtRQovuEOqsMokakP9ue-y_jXhmCwJ&index=13

C:\Users\Administrator\Desktop\demo\webpack.config.js

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
  entry: {
    app: './src/index.js',
  },
  plugins: [
    new HtmlWebpackPlugin({
      title: 'Output Management',
      template: 'src/index.html',
      filename: 'index.html'
    })
  ],
  optimization: {
    splitChunks: {
      name: 'common'
    }
  },
  devServer: {
    contentBase: path.join(__dirname, 'dist'),
    compress: true,
    port: 9000,
    open: true
  },
  output: {
    filename: '[name].[chunkhash].js',
    path: path.resolve(__dirname, 'dist')
  }
};

C:\Users\Administrator\Desktop\demo\package.json

{
  "name": "demo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "clearn": "rimraf dist",
    "build": "npm run clearn && webpack",
    "server": "webpack-dev-server"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "html-webpack-plugin": "^4.5.0",
    "rimraf": "^3.0.2",
    "webpack": "^4.44.2",
    "webpack-cli": "^3.3.12",
    "webpack-dev-server": "^3.11.0"
  }
}

C:\Users\Administrator\Desktop\demo\src\index.js

console.log('bbbbbbbbaaaaaaaaadddddd');

C:\Users\Administrator\Desktop\demo\src\index.html

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>
<body>
	<div id="root">
		<p>Lorem ipsum dolor, sit amet.</p>
	</div>
</body>
</html>

Last updated

Navigation

Lionel

@Copyright 2023