private-loader

This is a webpack loader that handle private variables in js

Usage no npm install needed!

<script type="module">
  import privateLoader from 'https://cdn.skypack.dev/private-loader';
</script>

README

npm license

Private Loader

This is a webpack loader that handle private variables in js

Install

From NPM:

npm install --save-dev private-loader

From GitHub:

cd path/to/node_modules
git clone https://github.com/SergiiSharpov/private-loader.git

Usage

webpack.config.js

module.exports = {
    module: {
        rules: [{
            test: /\.js$/,
            use: [ '...', 'private-loader' ],
            exclude: path.resolve(__dirname, 'node_modules')
        }]
    }
}

Example

class Test {
    constructor() {
        this.__hello = "World";
        this.qwerty = 5;
    }

    __test() {
        return this.__hello;
    }

    get example() {
        return this.__test();
    }
}

let object = new Test();

console.log(object.__hello);// Undefined
console.log(object.example);// World
console.log(object.__test());// TypeError: object.__test is not a function
console.log(object.qwerty);// 5