Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Commit

Permalink
Explicit choice to ignore extract manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
jouni-kantola committed Apr 19, 2017
1 parent 4e8c442 commit 593dfff
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ const inlineChunkManifestConfig = {
manifestVariable: 'webpackManifest', // webpackManifest is default
chunkManifestVariable: 'webpackChunkManifest', // webpackChunkManifest is default; use in html-webpack-plugin template
dropAsset: true, // false is default; use to skip output of the chunk manifest asset (removes manifest.json)
manifestPlugins: [/* override default chunk manifest plugin(s) */]
manifestPlugins: [/* override default chunk manifest plugin(s) */],
extractManifest: false // true is default. When set to false, manifestPlugins (incl default) is not applied
};

new InlineChunkManifestHtmlWebpackPlugin(inlineChunkManifestConfig)
Expand Down
15 changes: 14 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ class InlineChunkManifestHtmlWebpackPlugin {
options.chunkManifestVariable || "webpackChunkManifest";
this.dropAsset = options.dropAsset || false;

if (
options.extractManifest != null &&
typeof options.extractManifest !== "boolean"
) {
throw new TypeError("Extract manifest must be boolean");
}

this.extractManifest = options.extractManifest != null
? options.extractManifest
: true;

const manifestPlugins = options.manifestPlugins;

if (manifestPlugins && !Array.isArray(manifestPlugins)) {
Expand Down Expand Up @@ -89,7 +100,9 @@ class InlineChunkManifestHtmlWebpackPlugin {
}

applyDependencyPlugins(compiler) {
this.plugins.forEach(plugin => plugin.apply.call(plugin, compiler));
if (this.extractManifest) {
this.plugins.forEach(plugin => plugin.apply.call(plugin, compiler));
}
}
}

Expand Down
24 changes: 24 additions & 0 deletions test/plugin-init-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@ test("override drop asset", t => {
t.is(plugin.dropAsset, true);
});

test("extract manifest as boolean", t => {
const error = t.throws(() => {
const plugin = new InlineChunkManifestHtmlWebpackPlugin({
extractManifest: 1
});
}, TypeError);

t.is(error.message, "Extract manifest must be boolean");
});

test("default extract manifest", t => {
const plugin = new InlineChunkManifestHtmlWebpackPlugin();

t.is(plugin.extractManifest, true);
});

test("disable plugins", t => {
const plugin = new InlineChunkManifestHtmlWebpackPlugin({
extractManifest: false
});

t.is(plugin.extractManifest, false);
});

test("override manifest filename", t => {
const plugin = new InlineChunkManifestHtmlWebpackPlugin({
filename: "another.file"
Expand Down

0 comments on commit 593dfff

Please sign in to comment.