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-get-files-plugin

v1.0.3

Published

Webpack plugin for extracting output assets filenames into a separate JSON file according to the Entrypoints specified in the webpack configuration.

Downloads

13

Readme

webpack-get-files-plugin

version of the webpack-get-files-plugin

Webpack plugin for extracting output assets filenames into a separate JSON file according to the Entrypoints specified in the webpack configuration.

The main purpose of writing this plugin is that I had a project structure where I was working with NodeJS, Express, Pug (view engine) and webpack. So basically, webpack was building my assets with names having random content hashes like index.d53b3te33yi3y.js and it was difficult for me to inject those assets into my views e.g. index.pug. That's why I came up with webpack-get-files-plugin that extracts the filenames of the output assets into a GetFiles.json file and I can easily inject them into my views.

Installation

npm install webpack-get-files-plugin --save-dev

Usage

The Webpack Configuartion:

const path = require('path');

// Requiring webpack-get-files-plugin
const GetFilesPlugin = require('webpack-get-files-plugin');

const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

module.exports = {
	mode: 'production',
	entry: {
		home: path.join(__dirname, 'src', 'home.js'),
	},
	output: {
		path: path.join(__dirname, 'dist'),
		filename: 'js/[name].[contentHash].js',
	},
	plugins: [
		// Using the webpack-get-files-plugin
		new GetFilesPlugin(),

		new CleanWebpackPlugin(),
		new MiniCssExtractPlugin({
			filename: 'css/[name].[contentHash].css',
		}),
	],
	module: {
		rules: [
			{
				test: /\.css$/,
				use: [MiniCssExtractPlugin.loader, 'css-loader'],
			},
			{
				test: /\.(png|jpg|svg|gif|jpeg)/,
				use: {
					loader: 'file-loader',
					options: {
						name: 'images/[name].[contentHash].[ext]',
					},
				},
			},
		],
	},
};

After running the webpack build process, this plugin will emit a file named GetFiles.json in the root directory of your project.

Structure of GetFiles.json

{
	"entrypoints": ["home"],
	"files": {
		"home": {
			"filenames": [
			    "css/home.c43adcd817b4eaa62b97.css",
			    "js/home.5e994fb65e62d205d1c5.js",
			    "{\"name\": \"webpack-logo.png\"}??gffm??images/webpack-logo.3b7bf087cbac835e6f7d4b7dc9711e72.png"
			],
			"assets": {
				"css": ["css/home.c43adcd817b4eaa62b97.css"],
				"js": ["js/home.5e994fb65e62d205d1c5.js"],
				"images": {
					"webpack-logo.png":  "images/webpack-logo.3b7bf087cbac835e6f7d4b7dc9711e72.png",
					"github.svg":  "images/github.16a9304e38fd8167989291ab92544e14.svg"
				}
			}
		}
	}
}

Demo Project

I have created a demo project in demo-webpack-get-files-plugin directory to help you better understand how this plugin works. This demo project does not contain example of working with NodeJS, Express and Pug.

For that I have a separate boilerplate project where I have used this plugin. @mhm13dev/node-express-webpack-pug

To See How This Plugin Works in Action:

Clone this repo:

git clone https://github.com/mhm13dev/webpack-get-files-plugin.git

Change into repo's directory

cd webpack-get-files-plugin

Change into demo project directory

cd demo-webpack-get-files-plugin

Install the dependencies

npm install

Run the webpack build process

npm run webpack

Then have a look at the dist directory and GetFiles.json file inside demo-webpack-get-files-plugin directory.