Smart software development


Long-term caching with Webpack

I am going to show you simple way to cache public files. Using this configuration bellow, we are instructing our server and browser to cache the file for as long as possible.

var webpack = require('webpack');
var path = require('path');

module.exports = {
    entry: {
        app: './src/app.js'
    output: {
        path: path.resolve(__dirname, './build'),
        filename: '[name].[chunkhash].js' 
        // chunkhash is only going to change if file is changed

    // clean directory from old builds using CleanWebpack plugin
    plugins: [
        new CleanWebpackPlugin(['build'],
            root: __dirname,
            verbose: true,
            dry: false,