npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

preprocessing-loader

v0.0.4

Published

A simple webpack loader to pre-process some part of code in compile time in order to speed up the runtime

Downloads

21

Readme

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