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

dynamic-webpack-entries

v1.0.1

Published

A Webpack helper used for adding dynamic entry points on a webkpack configuration

Downloads

400

Readme

dynamic-webpack-entries

The purpose of this package is to handle multiple entry-points on your webpack configuration using glob to handle the file matching.

Table of Contents

  1. Introduction
  2. Install
  3. Usage
  4. Options

Introduction

By default, webpack entry points system is kind of static. This package let's you enhance webpack entry system and handle a whole lot of entry files without having to add them on your webpack configuration.

This is really useful on multi-page applications and multisite proyects where there are hundreds of files to handle.

Install

Install with npm:

npm install --save-dev dynamic-webpack-entries

Usage

Here are some basic usage examples, taking into account the following folder structure

📦src
 ┗ 📂entry-points
 ┃ ┣ 📂siteA
 ┃ ┃ ┣ 📂header
 ┃ ┃ ┃ ┗ 📜header.js
 ┃ ┃ ┗ 📜main.js
 ┃ ┣ 📂siteB
 ┃ ┃ ┣ 📂footer
 ┃ ┃ ┃ ┣ 📂footer-parts
 ┃ ┃ ┃ ┃ ┗ 📜parts.js
 ┃ ┃ ┃ ┗ 📜footer.js
 ┃ ┃ ┗ 📜siteB.js
 ┃ ┣ 📂siteC
 ┃ ┃ ┗ 📂nested
 ┃ ┃ ┃ ┗ 📂folder
 ┃ ┃ ┃ ┃ ┗ 📜nested-file.js
 ┃ ┗ 📜globals.js

Basic examples

Most basic configuration. With default options.

const dynamicEntryPoints = require("dynamic-webpack-entries");

const entries = dynamicEntryPoints({
    entryFolder: `./src/entry-points`,
});

module.exports = {
    entry: entries,
    output: {
      filename: '[name].js' //Our output can be custom. This is the one webpack uses by default.
    }
};

//webpack output folder by default is "dist"

A more customizable example where using glob we can include and ignore specific files or folders.
Check the options allowed by glob on their documentation

const dynamicEntryPoints = require("dynamic-webpack-entries");

const entries = dynamicEntryPoints({
    entryFolder: `./src/entry-points`,
    include: '/**/*.{css,scss,js}',                   
    logEntries: true,                   
      options: { //glob options
        ignore: ['/**/globals.js']
        debug: true,
        ....
      }
});

module.exports = {
    entry: entries,
    output: {
      filename: '[name].js' 
    }
};

dynamicEntryPoints function returns and object based on our file and folder structure. We can manipulate it if we want before passing it into webpack entry property.

//Based on our example structure and including all files.
{
  '/globals': './src/entry-points/globals.js',
  '/siteA/header/header': './src/entry-points/siteA/header/header.js',
  '/siteA/main': './src/entry-points/siteA/main.js',
  '/siteB/footer/footer-parts/parts': './src/entry-points/siteB/footer/footer-parts/parts.js',
  '/siteB/footer/footer': './src/entry-points/siteB/footer/footer.js',
  '/siteB/siteB': './src/entry-points/siteB/siteB.js',
  '/siteC/nested/folder/nested-file': './src/entry-points/siteC/nested/folder/nested-file.js'
}

Options

  • entryFolder Directory in which to start looking for files. Defaults to ${process.cwd()}/src/entry-points;
  • logEntries console.logs our entries on the CLI when compiling with webpack. Pretty useful when debugging and trying combinations with include and ignore options. Defaults to false;
  • include Expects a glob pattern for including files as our entry points. Defaults to '/**/*.*'
  • options This propety matches the ones used by glob. Documented on their package.