Monday, October 16, 2017

Removing the hash from the SPFx bundle file name

Just a quick follow up on this topic Controlling SPFx bundle file name in production builds

It seems the latest drop of SPFx added a new setting that allows you to bypass the hash mechanism and prevent it from being added to your bundle file names.

I have yet to confirm this, but it seems you can add this code to you gulpfile.js:
build.copyAssets.taskConfig = { excludeHashFromFileNames: true, }

And this will stop adding the hash to the file names.

Posted: https://github.com/SharePoint/sp-dev-fx-webparts/issues/246#issuecomment-335946172
By: Franck Cornu
(Thanks!)

I will give it a try and update here if it works. See my other blog post on how to edit the file name and add the version number automatically as well.


Edit: I just verified this is working as of 1.4.0

2 comments:

Tushar said...

For SPFx 1.14 its not working, do you have any idea or alternate solution?

Thanks in advance

Shai Petel said...

Haven't tried in 1.14 yet, but in 1.12.1 this worked for me:

var getTasks = build.rig.getTasks;
getTasks = getTasks.bind(build.rig);
var configureWebPack = build.configureWebpack;
build.rig.getTasks = function () {
var result = getTasks();

configureWebPack.taskConfig.additionalConfiguration = generatedConfig => {
generatedConfig.devtool = generatedConfig.mode === "development" ? "inline-source-map" : undefined;
generatedConfig.output.chunkFilename = "chunk.[name].js";
generatedConfig.output.filename = "[name].js";
// if we want source map in production
// if (generatedConfig && generatedConfig.optimization && generatedConfig.optimization.minimizer)
// generatedConfig.optimization.minimizer[0].options.sourceMap = true;//allow sourcemaps in production build
return generatedConfig;
};
return result;
};