Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

404
Views
webpack-dev-server no actualiza HTML automáticamente?

Estoy usando webpack-dev-server con webpack v5 y por una razón cuando realicé cambios en mi CSS y js se actualizó a tiempo como se esperaba, pero para los archivos HTML tengo que actualizar mi navegador manualmente para ver la nueva versión cumplida.

 src |-index.html |-index.js

webpack.config.js

 const path = require("path"); const htmlWebpackPlugin = require("html-webpack-plugin"); module.exports = { mode: "development", output: { clean: true, filename: "bundel.js", path: path.resolve(__dirname, "dist"), }, plugins: [ new htmlWebpackPlugin({ filename: "index.html", template: path.resolve(__dirname, "src", "index.html"), }), ], };

mi paquete.json devDependencies

 "devDependencies": { "html-webpack-plugin": "^5.5.0", "webpack": "^5.70.0", "webpack-cli": "^4.9.2", "webpack-dev-server": "^4.7.4" }

Comienzo mi servidor con npx webpack serve --open

Agregué el archivo CSS y sus cargadores CSS relativos para probarlo y lo eliminé después de asegurarme de que funciona y solo HTML es el problema.

puede replicar el problema cuando cambia el contenido de index.html

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Intente usar la opción DevServer para recargar la página y comprimir todo. En lugar de ejecutar npx webpack serve --open run npm run start usando esta configuración de script:

 "scripts": { "start": "webpack-dev-server", "build": "webpack", "test": "echo \"Error: no test specified\" && exit 1" },

E intente usar esta configuración base para su webpack.config.js

 const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = { // Default settings mode:'development', devtool:'inline-source-map', entry:{ main: path.join(__dirname,'src','index.js') }, output:{ filename:'index.js', path: path.resolve(__dirname,'dist'), clean:true, }, // Loaders module:{ // JavaScript rules:[ { test: /\.js$/i, use:{ loader:'babel-loader', options:{ "presets":['@babel/preset-react'] }} }, // Css { test: /\.css$/i, use:['style-loader','css-loader'] } ] }, // Plugins plugins:[ new HtmlWebpackPlugin({ template: path.join(__dirname,'public','index.html') , filename:'index.html' }) ], // DevServer devServer:{ port:8080, open:true, compress:true, hot:true, liveReload:true, } };
about 4 years ago · Juan Pablo Isaza Report

0

El problema es que webpack-dev-server no ve archivos HTML de forma predeterminada

así que encontré dos soluciones para esto:

  • La primera solución es lanzar devServer incorporado agregando watchFiles :
 devServer: { watchFiles: ["src/*.html"], hot: true, },
  • La segunda solución usando un complemento externo llamado browser-sync-webpack-plugin
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!