2.1.4 ā€¢ Published 4 years ago

emit-changed-only-webpack-plugin v2.1.4

Weekly downloads
12
License
ISC
Repository
github
Last release
4 years ago

emit-changed-only-webpack-plugin

Webpack production plugin to only emit changed files.

Why?

When your app bundle is overwritten - even when maintaining the same file name - the server might see the file is changed (e.g. by modified date). A client browser will request the file and the server will tell the browser that the file changed. Which results in the browser downloading, interpreting and compiling your JS, every time the app is started.

See https://v8.dev/blog/code-caching-for-devs.

Using this plugin, identical files won't be modified: No new date, no new ETag, so your app will be browser cache friendly. This will grant your web app faster load times and less data usage.

šŸ”„

Usage

Install the plugin

npm i -D emit-changed-only-plugin

Use the plugin

Important! Use the webpack substitute [contenthash] in your filename. This is used to compare file versions.

// webpack.production.js

const EmitChangedOnlyPlugin = require("emit-changed-only-webpack-plugin");

module.exports = {
  // ... webpack config

  output: {
    path: "./dist",
    /**
     * Use a hashed webpack substitute to generate a filename.
     * [contenthash] is recommended because the hash represents file contents.
     */
    filename: "[name].[contenthash].js"
  },
  plugins: [
    new EmitChangedOnlyPlugin({
      exclude: /\.html/i
    })
  ]
};

Settings

You can pass some settings, but this should generally not be necessary.

NameTypeDescriptionDefault
alwaysOverwritestring | RegExpMatches will alway be emittedundefined
excludestring | RegExpThe plugin won't do anything to the matched filenamesundefined
productionbooleanRequire webpack production modetrue
splitChunksbooleanUse chunk splitting (recommended)true
teststring | RegExpApply the plugin to matched filenames/\.js/i

Note

The plugin will attempt to keep your distribution directory clean, by removing outdated, previously built files. So you won't have to - and should not - clear your distribution directory. To keep certain files from being deleted, you can add them to the exclude setting.

2.1.4

4 years ago

2.1.3

4 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.22

5 years ago

1.1.21

5 years ago

1.1.20

5 years ago

1.1.19

5 years ago

1.1.18

5 years ago

1.1.17

5 years ago

1.1.16

5 years ago

1.1.15

5 years ago

1.1.14

5 years ago

1.1.13

5 years ago

1.1.12

5 years ago

1.1.11

5 years ago