Skip to content

Feature configure manifest options #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

Seikyo
Copy link

@Seikyo Seikyo commented Aug 17, 2017

This PR adds configureManifestPlugin() as discussed in #125

Example:

Encore.configureManifestPlugin({
    fileName: '../../var/assets/manifest.json'
})

These options will override any default option.

index.js Outdated
* })
*
* @param {Object} options
* @returns {publicApi}
Copy link
Collaborator

Choose a reason for hiding this comment

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

@returns {exports}

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,
}));
};
let manifestConfig = Object.assign(defaultConfig, webpackConfig.manifestPluginOptions);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a minor remark here, Object.assign modifies its first argument, so in this case defaultConfig (which doesn't really makes sense since it won't be the default config anymore after that).

You probably could either do:

const defaultConfig = { /* ... */ };
const manifestConfig = Object.assign({}, defaultConfig, webpackConfig.manifestPluginOptions);

Or only use a single variable (which looks a bit less clear in my opinion):

const manifestConfig = Object.assign({}, { /* ... */ }, webpackConfig.manifestPluginOptions);

Copy link
Collaborator

@Lyrkan Lyrkan left a comment

Choose a reason for hiding this comment

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

More globally: I'm not sure that the configureManifestPlugin() method should take an object as an argument.

For other methods related to loaders/plugins (e.g. enableSassLoader(), configureBabel(), enableForkedTypeScriptTypesChecking(), ...) a callback is used to modify default options.

@Seikyo
Copy link
Author

Seikyo commented Aug 17, 2017

@Lyrkan I tried to look into the other features pull request but honestly I am kind of lost with how this works. Could you tell me if this is more suitable ?

Copy link
Collaborator

@Lyrkan Lyrkan left a comment

Choose a reason for hiding this comment

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

Apart from these two mistakes and maybe another missing test (to check that the callback is really applied/used) that looks good to me :)

@@ -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 :)

this.usePostCssLoader = true;

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).

@Seikyo
Copy link
Author

Seikyo commented Aug 17, 2017

Should be good now, thank you for your help

@weaverryan
Copy link
Member

This is excellent work! Thank you @Seikyo!

@weaverryan weaverryan closed this in 995a742 Sep 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants