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

143
Views
¿Cómo crear la biblioteca Javascript OOP y compilar un paquete con Webpack?

Intento crear una biblioteca de Javascript con estilo OOP y hacer que se pueda ejecutar con el navegador. Soy un novato en javascript moderno.

Mi código de ejemplo: mylib.js

 function MyLib() { if (!(this instanceof MyLib)) { return new MyLib(options) } this.init(options); return this } MyLib.prototype.init = function (options) { this.debug = options.debug console.log(options) } .... ///

exportar MyLib predeterminado

 index.js import MyLib from './mylib.js';

índice.html

 <script src="dist/mylib.js"></secript> <script> let mylib = new({ debug: true }); </script>

webpack.config.js

 const webpack = require('webpack') const path = require('path') module.exports = { entry: { mylib: './lib/index.js' }, output: { filename: '[name].js', path: path.resolve(__dirname, 'dist'), }, mode: process.env.MINIFY_BUILD ? 'production' : 'development', plugins: [ new webpack.DefinePlugin({ 'procrss.env.NODE_ENV': 'production' }) ], module: { rules: [ { test: /\.js$/, exclude: /node_modules\/(?!(lit-element|lit-html)\/).*/, loader: 'babel-loader' } ] } }

Entonces, después de todo, recibí un mensaje de error como el siguiente

Error de referencia no capturado: MyLib no está definido

Por favor ayúdenme o sugiéranme.

over 4 years ago · Juan Pablo Isaza
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!