This repository was archived by the owner on Jun 8, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +74
-3
lines changed Expand file tree Collapse file tree 5 files changed +74
-3
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,8 @@ const inlineChunkManifestConfig = {
41
41
filename: ' manifest.json' , // manifest.json is default
42
42
manifestVariable: ' webpackManifest' , // webpackManifest is default
43
43
chunkManifestVariable: ' webpackChunkManifest' , // webpackChunkManifest is default; use in html-webpack-plugin template
44
- dropAsset: true // false is default; use to skip output of the chunk manifest asset (removes manifest.json)
44
+ dropAsset: true , // false is default; use to skip output of the chunk manifest asset (removes manifest.json)
45
+ manifestPlugins: [/* override default chunk manifest plugin(s) */ ]
45
46
};
46
47
47
48
new InlineChunkManifestHtmlWebpackPlugin (inlineChunkManifestConfig)
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " inline-chunk-manifest-html-webpack-plugin" ,
3
- "version" : " 1.0 .0" ,
3
+ "version" : " 1.1 .0" ,
4
4
"description" : " Extension plugin for html-webpack-plugin to inline webpack chunk manifest. Default inlines in head tag." ,
5
5
"main" : " ./src/index.js" ,
6
6
"repository" : {
Original file line number Diff line number Diff line change @@ -12,12 +12,24 @@ class InlineChunkManifestHtmlWebpackPlugin {
12
12
options . chunkManifestVariable || "webpackChunkManifest" ;
13
13
this . dropAsset = options . dropAsset || false ;
14
14
15
- this . plugins = [
15
+ const manifestPlugins = options . manifestPlugins ;
16
+
17
+ if ( manifestPlugins && ! Array . isArray ( manifestPlugins ) ) {
18
+ throw new TypeError (
19
+ "Overriden manifest plugin(s) must be specified as array; [new Plugin1(), new Plugin1(), ...]"
20
+ ) ;
21
+ }
22
+
23
+ const defaultManifestPlugins = [
16
24
new ChunkManifestPlugin ( {
17
25
filename : this . manifestFilename ,
18
26
manifestVariable : this . manifestVariable
19
27
} )
20
28
] ;
29
+
30
+ this . plugins = manifestPlugins && manifestPlugins . length
31
+ ? manifestPlugins
32
+ : defaultManifestPlugins ;
21
33
}
22
34
23
35
apply ( compiler ) {
Original file line number Diff line number Diff line change @@ -31,3 +31,28 @@ test.cb("dependency plugins are applied", t => {
31
31
plugin . plugins = [ dependencyPlugin , anotherDependencyPlugin ] ;
32
32
plugin . apply ( fakeCompiler ) ;
33
33
} ) ;
34
+
35
+ test . cb ( "overridden manifest plugins applied" , t => {
36
+ t . plan ( 2 ) ;
37
+
38
+ const fakeCompiler = { plugin : ( ) => { } } ;
39
+
40
+ const dependencyPlugin = {
41
+ apply : compiler => {
42
+ t . is ( compiler , fakeCompiler ) ;
43
+ }
44
+ } ;
45
+
46
+ const anotherDependencyPlugin = {
47
+ apply : compiler => {
48
+ t . is ( compiler , fakeCompiler ) ;
49
+ t . end ( ) ;
50
+ }
51
+ } ;
52
+
53
+ const plugin = new InlineChunkManifestHtmlWebpackPlugin ( {
54
+ manifestPlugins : [ dependencyPlugin , anotherDependencyPlugin ]
55
+ } ) ;
56
+
57
+ plugin . apply ( fakeCompiler ) ;
58
+ } ) ;
Original file line number Diff line number Diff line change @@ -53,3 +53,36 @@ test("override chunk manifest variable", t => {
53
53
54
54
t . is ( plugin . chunkManifestVariable , "another-variable" ) ;
55
55
} ) ;
56
+
57
+ test ( "fallback to default chunk manifest plugin" , t => {
58
+ const plugin = new InlineChunkManifestHtmlWebpackPlugin ( {
59
+ manifestPlugins : [ ]
60
+ } ) ;
61
+
62
+ t . is ( plugin . plugins . length , 1 ) ;
63
+ t . true ( plugin . plugins [ 0 ] instanceof ChunkManifestPlugin ) ;
64
+ } ) ;
65
+
66
+ test ( "ensure overriden plugins handle apply" , t => {
67
+ const manifestPlugin = { override : true , apply : ( ) => { } } ;
68
+ const anotherManifestPlugin = { override : true , apply : ( ) => { } } ;
69
+
70
+ const plugin = new InlineChunkManifestHtmlWebpackPlugin ( {
71
+ manifestPlugins : [ manifestPlugin , anotherManifestPlugin ]
72
+ } ) ;
73
+
74
+ t . deepEqual ( plugin . plugins , [ manifestPlugin , anotherManifestPlugin ] ) ;
75
+ } ) ;
76
+
77
+ test ( "array of plugins required" , t => {
78
+ const error = t . throws ( ( ) => {
79
+ const plugin = new InlineChunkManifestHtmlWebpackPlugin ( {
80
+ manifestPlugins : 1
81
+ } ) ;
82
+ } , TypeError ) ;
83
+
84
+ t . is (
85
+ error . message ,
86
+ "Overriden manifest plugin(s) must be specified as array; [new Plugin1(), new Plugin1(), ...]"
87
+ ) ;
88
+ } ) ;
You can’t perform that action at this time.
0 commit comments