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

107
Views
Webpack no carga los archivos JavaScript

Estoy tratando de hacer una aplicación simple donde uso Webpack y babel. A continuación, puede encontrar el código que he escrito ... Desafortunadamente, al iniciar npm run start desde la consola del navegador no me da ningún error y el archivo (index.js) no funciona;

paquete.json:

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

Ese es el código HTML:

 <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Canvas</title> </head> <body> <div id="root" ></div> <script type="text/js" src="../src/index.js" ></script> </body> </html>

Babel:

 { "presets": [ [ "@babel/preset-env", { "targets": { "edge": "17", "firefox": "60", "chrome": "67", "safari": "11.1" } } ] ] }

paquete web:

 // Plugins const HtmlWebpackPlugin = require('html-webpack-plugin'); const path = require('path'); module.exports = { // Main mode: 'development', devtool:'inline-source-map', entry: './src/index.js', output:{ path: path.resolve(__dirname,'./dist'), filename: 'main.bundle.js', clean:true, }, // Loaders module: { rules: [ { test: /\.js$/, exclude: /node_modules/, use: { loader: 'babel-loader', options: { "presets":['@babel/preset-env']} } }, { test:/\.css$/, use:['style-loader','css-loader'], } ]}, // HTML plugins:[new HtmlWebpackPlugin({ filename:'main.bundle.html', template:path.join(__dirname,'public','index.html'), })], // Development Server devServer:{ hot:true, open:true, port:8080, compress:true, liveReload:true, } };

índice.js:

 alert('hello world!'); console.log('hello world!')
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe eliminar la etiqueta del script ( <script type="text/js" src="../src/index.js" ></script> ) en su index.html ya que HTMLWebpackPlugin es responsable de inyectarlo en su archivo HTML . Al agruparlo con Webpack, también lo está renombrando en main.bundle.js (en su configuración de salida).

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!