-
-
Notifications
You must be signed in to change notification settings - Fork 200
Description
Hello,
Sorry if it is not the right place for this recommandation.
We are trying Webpack Encore and wanted to avoid having double "." in the output filename when using versioning assets and let the manifest file out of the web (or public) folder.
First, here is how we could resolve this issues currently as it may come in handy for others :
const Encore = require('@symfony/webpack-encore');
const ManifestPlugin = require('@symfony/webpack-encore/lib/webpack/webpack-manifest-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
Encore
// (...) Your Encoreconfiguration
// export the final configuration
let config = Encore.getWebpackConfig();
// JavaScript output file format
config.output.filename = '[name]-[chunkhash].js';
// Assets (fonts and images) output file format
for (let i = 0; i < config.module.rules.length; i++) {
let rule = config.module.rules[i];
if ('options' in rule && 'name' in rule.options) {
rule.options.name = rule.options.name.replace('.[hash]', '-[hash]');
}
}
// WebPack plugins configuration override
for (let i = 0; i < config.plugins.length; i++) {
let plugin = config.plugins[i];
// Custom manifest path
if (plugin instanceof ManifestPlugin) {
plugin.opts.fileName = "../../data/manifest.json";
}
// StyleSheets output file format
if (plugin instanceof ExtractTextPlugin) {
plugin.filename = '[name]-[contenthash].css';
}
}
I think it would be really nice to be able to configure this as an Encore.setVersioningFileFormat() that would take an object with extension as key to configure the default formats :
Encore
// (...) Your Encoreconfiguration
.setVersioningFileFormat({
js: '[name]-[chunkhash].js',
css: '[name]-[contenthash].css',
rules_suffix: '-[hash]',
)
That object could be preset with current static values and implemented as :
@symfony/webpack-encore/lib/config-generator.js
// Currently
${this.webpackConfig.useVersioning ? '.[hash]' : ''}
// Could be
${this.webpackConfig.useVersioning ? this.webpackConfig.versioningFormats.rules_suffix : ''}
...
// Currently
filename: this.webpackConfig.useVersioning ? '[name].[chunkhash].js' : '[name].js',
// Could be
filename: this.webpackConfig.useVersioning ? this.webpackConfig.versioningFormats.js: '[name].js',
@symfony/webpack-encore/lib/plugins/extract-text.js
// Currently
filename: webpackConfig.useVersioning ? '[name].[contenthash].css' : '[name].css',
// Could be
filename: webpackConfig.useVersioning ? webpackConfig.versioningFormats.css: : '[name].css',
Thanks for the work it was really nice to play with.
If there is a better place to submit this recommandation please let me now.