Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

125
Vistas
How to create Javascript library OOP and build bundle with Webpack?

I try to create a Javascript library with OOP style and make it can run with the browser. I am a newbie to modern javascript.

My Example Code: 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)
}

.... ///

export default MyLib

index.js

import MyLib from './mylib.js';

index.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'
            }
        ]
    }
}

So after all, I got an error message like below

Uncaught ReferenceError: MyLib is not defined

Please help or suggest to me.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda