preprocessing-loader

0.0.4 • Public • Published

npm node deps cover size npm Build Status Coverage Status

This is an experimental project and still in development. Use it on your own risk!

preprocessing-loader

Edit webpack-prepossessing-loader

This is a simple loader, it will simply pre process few of the code which wont effect the normal execution of the program in the run time. It will pre process codes like these

const a = 123;
var whatsTheNumber = a;

Now this will convert into the following

const a = 123;
var whatsTheNumber = 123;

Why ? as a is const and its value will not change in the rest of the program, We can simply change all those variables which are assign using a with a's value that is 123

in future release, this line const a = 123 will be removed from the output file as it doesnt have anything to do with the program after compiling using this loader

Another example can be,

const dumyFN = () => {
  return 'demo';
};
 
console.log(dumyFN());

This code will convert into the following

console.log('demo');

Preprocessing few codes like this increases the run time of the program as the program doesn't need to jump from one part to another to get the value of the variable.

As of now, the support for pre processing is very limited with this loader, for example

const obj = {
  prop1: () => {
    return 'value';
  }
};

This can be converted into this

const obj = {
  prop1: 'value'
};

but this loader doesnt support this. Support of this will be added in future. function bodies where the return statements are wrapped with other statements like another function or if-statement or callbacks are not supported by this loader as of now. Support of this will be added in future

Getting Started

To begin, you'll need to install preprocessing-loader:

$ npm install preprocessing-loader --save-dev

Then add the loader to your webpack config. For example:

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /.ext$/,
        use: [
          {
            loader: 'preprocessing-loader',
            options: { ...options }
          }
        ]
      }
    ]
  }
};

And run webpack via your preferred method.

Options

[option]

As of now, no options are available

Examples

webpack.config.js

module.exports = {
  entry: 'index.js',
  output: {
    filename: 'bundle.js'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        use: [
          {
            loader: 'preprocessing-loader'
          }
        ]
      }
    ]
  }
};

index.js

// Source code here...
const v = 5;
const z = 'a';
function hello(x) {
  console.log('hellox', x);
}
const tests = 5 + 2;
const afn = () => {
  return v;
};
const fn = function() {
  return 'fn';
};
var a = v;
let a2 = z;
const fn2 = function() {
  return a2;
};
hello(v);
hello(z);
 
const he = {
  // Not supportable
  what: () => {
    return 'qwe';
  }
};
 
const fntest = he.what(); //  needs to cover this !!!
 
console.log('fntest', fntest);
console.log('tests', tests);
console.log('fn', fn());
console.log('afn', afn());
console.log('fn2', fn2());
hello(afn());
console.log('v', v);

bundle.js

// Bundle code here...
function hello(x) {
  console.log('hellox', x);
}
 
var a = 5;
let a2 = 'a';
 
const fn2 = function() {
  return a2;
};
 
hello(5);
hello('a');
const he = {
  // Not supportable
  what: () => {
    return 'qwe';
  }
};
const fntest = he.what(); //  needs to cover this !!!
 
console.log('fntest', fntest);
console.log('tests', 7);
console.log('fn', 'fn');
console.log('afn', 5);
console.log('fn2', fn2());
hello(5);
console.log('v', 5);

Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.

CONTRIBUTING

License

MIT

Package Sidebar

Install

npm i preprocessing-loader

Weekly Downloads

4

Version

0.0.4

License

MIT

Unpacked Size

19.7 kB

Total Files

10

Last publish

Collaborators

  • anixsaha