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

v0.5.2

Published

Concatenate and transform files using Webpack

Downloads

26,915

Readme

webpack-concat-files-plugin

Concatenate and transform files using Webpack

NPM

Installation

Install the plugin with npm:

$ npm install webpack-concat-files-plugin --save-dev

Basic Usage

The example below concatenates all JavaScript files found within a hypothetical scripts/polyfills directory, and outputs the bundled file to dist/polyfills.min.js.

const WebpackConcatPlugin = require('webpack-concat-files-plugin');

const webpackConfig = {
  entry: 'index.js',
  output: {
    path: 'dist',
    filename: 'index_bundle.js',
  },
  plugins: [
    new WebpackConcatPlugin({
      bundles: [
        {
          dest: './dist/polyfills.min.js',
          src: './scripts/polyfills/**/*.js',
        },
      ],
    }),
  ],
};

Transformations

The contents of concatenated files can be modified (e.g., using minifiers and transpilers) and used in the concatenated output. These modifications are called transformations.

Each bundle can specify a transforms property, which can contain a before callback and an after callback. The before callback is called on each file before it is concatenated, and the after callback is called after concatenation has occurred.

The example below demonstrates how Terser could be used to minify the output of a concatenated bundle.

const terser = require('terser');
const WebpackConcatPlugin = require('webpack-concat-files-plugin');

const webpackConfig = {
  // ...
  plugins: [
    new WebpackConcatPlugin({
      bundles: [
        {
          src: './scripts/polyfills/**/*.js',
          dest: './dist/polyfills.min.js',
          transforms: {
            after: async (code) => {
              const minifiedCode = await terser.minify(code);
              return minifiedCode.code;
            },
          },
        },
      ],
    }),
  ],
};

Options

The options object can contain the following properties:

  • bundles: (Array) List of bundle objects
  • separator: (String) Separator inserted between concatenated content (Optional, default '\n')
  • allowWatch: (Boolean) Determines whether bundles should be watched and automatically concatenated when using Webpack's watch mode (Optional, default true)
  • allowOptimization: (Boolean) Determines whether Webpack should optimize concatenated bundles according to its optimization configuration. Webpack 5 only. (Optional, default false)

Bundles

Each object specified in the bundles array can contain the following properties:

  • bundle.src: (String or Array) Glob string or array of glob strings describing files to concatenate.
  • bundle.dest: (String) Output path for concatenated file.
  • bundle.transforms: (Object) Object describing transformations of concatenated files. (Optional)
  • bundle.encoding: (String) Encoding to use when reading files. (Optional, default 'utf8')

Transforms

The object specified for each transforms bundle property can contain any of the following properties:

  • transform.before(content, filepath): (Callback) Function to apply changes to file contents before concatenation. Accepts two string parameters: the contents of the file being concatenated, and the path to the source file being concatenated. The string returned by this function is used for the concatenated output. (Optional)
  • transform.after(content): (Callback) Function to apply changes to file contents after concatenation. Accepts a single string parameter containing the contents of the concatenated files, and the string returned by this function is used as the final concatenation output. (Optional)

Deprecated Options

The following options have been deprecated and will be removed in a future release:

  • bundle.source: (String or Array) Replaced with bundle.src. See documentation above.
  • bundle.destination: (String) Replaced with bundle.dest. See documentation above.

Compatibility

webpack-concat-files-plugin is compatible with Webpack 4 and Webpack 5:

| Webpack 4 | Webpack 5 | | ------------------- | ---------------- | | 4.40.x or greater | 5.x or greater |

Contributors

Special thanks to everybody who's contributed to this project!

| @davidwarrington | @Iszacsuri | @jarrettgreen | @wagoid |-|-|-|-|