Snippets

Realhub Systems Webpack Consistent Manifest Hashes

Created by Accounts Realhub
// Note: You must restart bin/webpack-dev-server for changes to take effect

/* eslint global-require: 0 */

const webpack = require('webpack')
const merge = require('webpack-merge')
const CompressionPlugin = require('compression-webpack-plugin')
const sharedConfig = require('./shared.js')

module.exports = merge(sharedConfig, {
  output: { filename: '[name]-[chunkhash].js' },
  devtool: 'source-map',
  stats: 'normal',

  plugins: [
    // Code above removed for example
    
    // Add HashedModuleIdsPlugin
    // This plugin will cause hashes to be based on the relative path of the module
    new webpack.HashedModuleIdsPlugin({
      hashDigestLength: 20
    })
  ]
})
// Note: You must restart bin/webpack-dev-server for changes to take effect

// Additional imports remove for example
const WebpackChunkHash = require('webpack-chunk-hash')

module.exports = {
  // Code above removed for example

  plugins: [
    new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))),
    new WebpackChunkHash({ algorithm: 'md5' }),
    new ExtractTextPlugin(env.NODE_ENV === 'production' ? '[name]-[chunkhash].css' : '[name].css'),
    new ManifestPlugin({
      publicPath: output.publicPath,
      writeToFileEmit: true
    })
  ],
  
  // Code below removed for example
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.