File tree Expand file tree Collapse file tree 4 files changed +57
-2
lines changed Expand file tree Collapse file tree 4 files changed +57
-2
lines changed Original file line number Diff line number Diff line change @@ -102,6 +102,25 @@ const publicApi = {
102
102
return this ;
103
103
} ,
104
104
105
+ /**
106
+ * Allows to set ManifestPlugin options and override default options
107
+ * List of available options can be found at https://github.com/danethurber/webpack-manifest-plugin
108
+ *
109
+ * For example:
110
+ *
111
+ * Encore.configureManifestPlugin(function(options){
112
+ * options.fileName: '../../var/assets/manifest.json'
113
+ * })
114
+ *
115
+ * @param {function } manifestPluginOptionsCallback
116
+ * @returns {exports }
117
+ */
118
+ configureManifestPlugin ( manifestPluginOptionsCallback = ( ) => { } ) {
119
+ webpackConfig . configureManifestPlugin ( manifestPluginOptionsCallback ) ;
120
+
121
+ return this ;
122
+ } ,
123
+
105
124
/**
106
125
* Adds a JavaScript file that should be webpacked:
107
126
*
Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ class WebpackConfig {
63
63
this . useImagesLoader = true ;
64
64
this . useFontsLoader = true ;
65
65
this . configuredFilenames = { } ;
66
+ this . manifestPluginOptionsCallback = function ( ) { } ;
66
67
}
67
68
68
69
getContext ( ) {
@@ -117,6 +118,14 @@ class WebpackConfig {
117
118
this . manifestKeyPrefix = manifestKeyPrefix ;
118
119
}
119
120
121
+ configureManifestPlugin ( manifestPluginOptionsCallback = ( ) => { } ) {
122
+ if ( typeof manifestPluginOptionsCallback !== 'function' ) {
123
+ throw new Error ( 'Argument 1 to configureManifestPlugin() must be a callback function' ) ;
124
+ }
125
+
126
+ this . manifestPluginOptionsCallback = manifestPluginOptionsCallback ;
127
+ }
128
+
120
129
/**
121
130
* Returns the value that should be used as the publicPath,
122
131
* which can be overridden by enabling the webpackDevServer
Original file line number Diff line number Diff line change @@ -24,11 +24,18 @@ module.exports = function(plugins, webpackConfig) {
24
24
manifestPrefix = webpackConfig . publicPath . replace ( / ^ \/ / , '' ) ;
25
25
}
26
26
27
- plugins . push ( new ManifestPlugin ( {
27
+ const manifestPluginOptions = {
28
28
basePath : manifestPrefix ,
29
29
// guarantee the value uses the public path (or CDN public path)
30
30
publicPath : webpackConfig . getRealPublicPath ( ) ,
31
31
// always write a manifest.json file, even with webpack-dev-server
32
32
writeToFileEmit : true ,
33
- } ) ) ;
33
+ } ;
34
+
35
+ webpackConfig . manifestPluginOptionsCallback . apply (
36
+ manifestPluginOptions ,
37
+ [ manifestPluginOptions ]
38
+ ) ;
39
+
40
+ plugins . push ( new ManifestPlugin ( manifestPluginOptions ) ) ;
34
41
} ;
Original file line number Diff line number Diff line change @@ -163,6 +163,26 @@ describe('WebpackConfig object', () => {
163
163
} ) ;
164
164
} ) ;
165
165
166
+ describe ( 'configureManifestPlugin' , ( ) => {
167
+ it ( 'Setting custom options' , ( ) => {
168
+ const config = createConfig ( ) ;
169
+ const callback = ( ) => { } ;
170
+ config . configureManifestPlugin ( callback ) ;
171
+
172
+ // fileName option overridden
173
+ expect ( config . manifestPluginOptionsCallback ) . to . equal ( callback ) ;
174
+ } ) ;
175
+
176
+ it ( 'Setting invalid custom options argument' , ( ) => {
177
+ const config = createConfig ( ) ;
178
+ const callback = 'invalid' ;
179
+
180
+ expect ( ( ) => {
181
+ config . configureManifestPlugin ( callback ) ;
182
+ } ) . to . throw ( 'Argument 1 to configureManifestPlugin() must be a callback function' ) ;
183
+ } ) ;
184
+ } ) ;
185
+
166
186
describe ( 'addEntry' , ( ) => {
167
187
it ( 'Calling with a duplicate name throws an error' , ( ) => {
168
188
const config = createConfig ( ) ;
You can’t perform that action at this time.
0 commit comments