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 = {
102102 return this ;
103103 } ,
104104
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+
105124 /**
106125 * Adds a JavaScript file that should be webpacked:
107126 *
Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ class WebpackConfig {
6363 this . useImagesLoader = true ;
6464 this . useFontsLoader = true ;
6565 this . configuredFilenames = { } ;
66+ this . manifestPluginOptionsCallback = function ( ) { } ;
6667 }
6768
6869 getContext ( ) {
@@ -117,6 +118,14 @@ class WebpackConfig {
117118 this . manifestKeyPrefix = manifestKeyPrefix ;
118119 }
119120
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+
120129 /**
121130 * Returns the value that should be used as the publicPath,
122131 * 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) {
2424 manifestPrefix = webpackConfig . publicPath . replace ( / ^ \/ / , '' ) ;
2525 }
2626
27- plugins . push ( new ManifestPlugin ( {
27+ const manifestPluginOptions = {
2828 basePath : manifestPrefix ,
2929 // guarantee the value uses the public path (or CDN public path)
3030 publicPath : webpackConfig . getRealPublicPath ( ) ,
3131 // always write a manifest.json file, even with webpack-dev-server
3232 writeToFileEmit : true ,
33- } ) ) ;
33+ } ;
34+
35+ webpackConfig . manifestPluginOptionsCallback . apply (
36+ manifestPluginOptions ,
37+ [ manifestPluginOptions ]
38+ ) ;
39+
40+ plugins . push ( new ManifestPlugin ( manifestPluginOptions ) ) ;
3441} ;
Original file line number Diff line number Diff line change @@ -163,6 +163,26 @@ describe('WebpackConfig object', () => {
163163 } ) ;
164164 } ) ;
165165
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+
166186 describe ( 'addEntry' , ( ) => {
167187 it ( 'Calling with a duplicate name throws an error' , ( ) => {
168188 const config = createConfig ( ) ;
You can’t perform that action at this time.
0 commit comments