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

webpack-dists-loader

v1.2.8

Published

a simple webpack loader for code-block pre-deal

Downloads

34

Readme

webpack-dists-loader

The [webpack-dists-loader] library exported as Node.js modules.

Installation

Using npm:

$ npm i -g npm
$ npm i webpack-dists-loader --save-dev

Background

In our project, we always need to change code blocks when the environment has been changed. we usually have several way to decide which code blocks we should remain, for example:

1: by using branch structure

if(env === 'development'){
    console.log(a)
} else {
    console.log(b)
}

2:delete code blocks when environment changed (not safe) 3:change the compilation entry (bad)

specially, if you want to import packages, you may coding like this:

if(env === 'development'){
    import(a)
} else {
    import(b)
}

as you can see, they are not the best way to deal with such problems. so we introduce an easy way to solve this: by config a code pretreatment tool to decide which code should remain in specific environment after compilation

In Node.js:

// webpack.config.js

// important! please set the options.env to choose which environment you want to use the loader, and set the process.env.NODE_ENV at the entry file 
process.env.NODE_ENV = 'production'

// like js, but css,html the same way
// debug tag means that if you want to remain the code ONLY IN development
// debug tag means that if you want to remain the code ONLY IN production
// special tag means that if you want to remain the code IN development and preview
module.exports = {
    ...
    module: {
        rules: [{
            test: /\.js$/,
            use:[
                {
                    loader: 'webpack-dists-loader',
                    options: {
                                  debug: {
                                      env: ['development'],
                                      tag: 'debug'
                                  },
                                  online: {
                                      env: ['production'],
                                      tag: 'online',
                                      specials: { // remian in preview
                                          'gear': 'gear'
                                      }
                                  }
                                }
                },
                {
                    loader: 'babel-loader'
                }
            ],
            include: [resolve('src'), resolve('node_modules/webpack-dev-server/client')]
        }]
    }
};

In js,css and html file,use comments and wrap the code with the special tags js file(input)

console.log('abc')

/*<debug>*/ //we only need mock in development
import mockjs from 'mockjs'
/*</debug>*/ 

/*<gear>/ //we need console in development and preview
import eruda from 'eruda'
/*</gear>/

/*<online*/
console.log('I`m online') //only in production should show
/*</online>*/

js file (output) compiled, code blocks that wrapped with the special tags has been removed

// IN development (npm run dev)
import eruda from 'eruda'

// IN production
console.log('I`m online')

// IN preview
import mockjs from 'mockjs'

import eruda from 'eruda'

css file (input)

.a {
    ...
}

.b {
    ...
}

/*<debug>*/
.c {
    ...
}
/*</debug>*/

css file (output)

.a {
    ...
}

.b {
    ...
}

html file (input)

<div class="a"></div>
<div class="b"></div>

<!--debug-->
<div class="c"></div>
<!--/debug-->

html file (output)

<div class="a"></div>
<div class="b"></div>

Notice

if dealing with js file, please use it before other loaders. It`s only supports js,css and html files now.other file types(like vue etc) will be supported in later release.