Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

127
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda