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

131
Views
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
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!