zoukankan      html  css  js  c++  java
  • [Webpack 2] Hashing with Webpack for long term caching

    Leveraging the browser cache is an important part of page load performance. A great way to utilize this cache is by versioning your resources. In this lesson, learn how to use Webpack’s hashing feature so you can take advantage of long term caching of your assets.

    Install: 

    npm install -D html-webpack-plugin

    Webpack.config.js

    const {resolve} = require('path')
    const HtmlWebpackPlugin = require('html-webpack-plugin')
    const isTest = process.env.NODE_ENV === "test";
    module.exports = env => {
      return {
        entry: './js/app.js',
        output: {
          filename: 'bundle.[chunkhash].js',
          path: resolve(__dirname, 'dist'),
          pathinfo: true,
        },
        context: resolve(__dirname, 'src'),
        devtool: env.prod ? 'source-map' : 'eval',
        module: {
          loaders: [
            {test: /.js$/, loader: 'babel!eslint', exclude: /node_modules/},
            {test: /.css$/, loader: 'style!css'},
          ],
        },
        plugins:[
          new HtmlWebpackPlugin(
                {
                  template: './index.html'
                }
            )
        ]
      }
    }

    Remove bundle.js in index.html

    Then in the browser you can see the bundle file has hash name. So everytime, you change the source code, it will update automatically

  • 相关阅读:
    程序是怎样跑起来的 第三章
    C#4.5-4.7学习总结
    第二周学习总结
    程序是如何跑起来的 第二章
    第一章读后感
    师生关系读后感
    C#学习总结
    我与计算机
    读《程序怎样跑起来》第一章有感
    读师生关系有感
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5608706.html
Copyright © 2011-2022 走看看