Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,25 @@ const publicApi = {
return this;
},

/**
* Allows to set ManifestPlugin options and override default options
* List of available options can be found at https://github.com/danethurber/webpack-manifest-plugin
*
* For example:
*
* Encore.configureManifestPlugin(function(options){
* options.fileName: '../../var/assets/manifest.json'
* })
*
* @param {function} manifestPluginOptionsCallback
* @returns {exports}
*/
configureManifestPlugin(manifestPluginOptionsCallback = () => {}) {
webpackConfig.configureManifestPlugin(manifestPluginOptionsCallback);

return this;
},

/**
* Adds a JavaScript file that should be webpacked:
*
Expand Down
11 changes: 11 additions & 0 deletions lib/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class WebpackConfig {
this.useImagesLoader = true;
this.useFontsLoader = true;
this.configuredFilenames = {};
this.manifestPluginOptionsCallback = function() {};
}

getContext() {
Expand Down Expand Up @@ -117,6 +118,16 @@ class WebpackConfig {
this.manifestKeyPrefix = manifestKeyPrefix;
}

configureManifestPlugin(manifestPluginOptionsCallback = () => {}) {
this.usePostCssLoader = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably remove that line :)


if (typeof manifestPluginOptionsCallback !== 'function') {
throw new Error('Argument 1 to enablePostCssLoader() must be a callback function.');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argument 1 to configureManifestPlugin() must be a callback function.

Maybe you could also add a test for that part (in test/WebpackConfig.js).

}

this.manifestPluginOptionsCallback = manifestPluginOptionsCallback;
}

/**
* Returns the value that should be used as the publicPath,
* which can be overridden by enabling the webpackDevServer
Expand Down
11 changes: 9 additions & 2 deletions lib/plugins/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ module.exports = function(plugins, webpackConfig) {
manifestPrefix = webpackConfig.publicPath.replace(/^\//, '');
}

plugins.push(new ManifestPlugin({
const manifestPluginOptions = {
basePath: manifestPrefix,
// guarantee the value uses the public path (or CDN public path)
publicPath: webpackConfig.getRealPublicPath(),
// always write a manifest.json file, even with webpack-dev-server
writeToFileEmit: true,
}));
};

webpackConfig.manifestPluginOptionsCallback.apply(
manifestPluginOptions,
[manifestPluginOptions]
);

plugins.push(new ManifestPlugin(manifestPluginOptions));
};
11 changes: 11 additions & 0 deletions test/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,17 @@ describe('WebpackConfig object', () => {
});
});

describe('configureManifestPlugin', () => {
it('Setting custom options', () => {
const config = createConfig();
const callback = () => {};
config.configureManifestPlugin(callback);

// fileName option overridden
expect(config.manifestPluginOptionsCallback).to.equal(callback);
});
});

describe('addEntry', () => {
it('Calling with a duplicate name throws an error', () => {
const config = createConfig();
Expand Down