最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Webpack中的文件指紋的實現(xiàn)

 更新時間:2023年01月09日 10:12:52   作者:aiguangyuan  
本文主要介紹了Webpack中的文件指紋的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

1. 什么是文件指紋?

文件指紋就是打包后輸出的文件名的后綴,主要用來對修改后的文件做版本區(qū)分。

2. 文件指紋有哪幾種?

1. Hash:和整個項目的構建相關,只要項目文件有修改,整個項目構建的 hash 值就會更改,一般用于圖片設置;

2. Chunkhash:與 webpack 打包的 chunk 有關,不同的 entry 會生成不同的 chunkhash 值,一般用于設置JS文件;

3. Contenthash:根據(jù)文件內(nèi)容來定義 hash ,文件內(nèi)容不變,則 contenthash 不變,一般用于設置CSS文件;

3. JS的文件指紋設置;

'use strict';
 
const path = require('path');
 
module.exports = {
    entry: {
        index: './src/index.js',
        search: './src/search.js'
    },
    output: {
        path: path.join(__dirname, 'dist'),
        // 設置chunkhash,長度為8位
        filename: '[name]_[chunkhash:8].js'
    }
};

4. CSS的文件指紋設置;

'use strict';
 
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
 
module.exports = {
    
    entry: {
        index: './src/index.js',
        search: './src/search.js'
    },
 
    output: {
        path: path.join(__dirname, 'dist'),
        filename: '[name]_[chunkhash:8].js'
    },
 
    plugins: [
        new MiniCssExtractPlugin({
            // 設置CSS為contenthash,長度為8位
            filename: '[name]_[contenthash:8].css'
        })
    ]
};

5. 圖片的文件指紋設置;

圖片文件的指紋設置使用file-loader,常用的占位符的含義如下:

圖片的文件指紋設置如下:

'use strict';
 
const path = require('path');
// npm i mini-css-extract-plugin -D
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
 
module.exports = {
    entry: {
        index: './src/index.js',
        search: './src/search.js'
    },
    output: {
        path: path.join(__dirname, 'dist'),
        // 設置JS的文件指紋為chunkhash,長度為8位
        filename: '[name]_[chunkhash:8].js'
    },
    mode: 'production',
    module: {
        rules: [
            {
                test: /.js$/,
                use: 'babel-loader'
            },
            {
                test: /.css$/,
                use: [
                    // 去掉style-loader,將CSS單獨提取一個文件
                    MiniCssExtractPlugin.loader,
                    'css-loader'
                ]
            },
            {
                test: /.less$/,
                use: [
                    // 去掉style-loader,將CSS單獨提取一個文件
                    MiniCssExtractPlugin.loader,
                    'css-loader',
                    'less-loader'
                ]
            },
            {
                test: /.(png|jpg|gif|jpeg)$/,
                use: [
                    {
                        loader: 'file-loader',
                        options: {
                            // 設置的圖片指紋為hash,長度為8位
                            name: '[name]_[hash:8].[ext]'
                        }
                    }
                ]
            },
            {
                test: /.(woff|woff2|eot|ttf|otf)$/,
                use: [
                    {
                        loader: 'file-loader',
                        options: {
                            // 設置字體的指紋為hash,長度為8位
                            name: '[name]_[hash:8][ext]'
                        }
                    }
                ]
            }
        ]
    },
    plugins: [
        // 將CSS提取出來一個文件
        new MiniCssExtractPlugin({
            filename: '[name]_[contenthash:8].css'
        })
    ]
};

到此這篇關于Webpack中的文件指紋的實現(xiàn)的文章就介紹到這了,更多相關Webpack 文件指紋內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:

相關文章

最新評論

姜堰市| 泗洪县| 苗栗市| 建德市| 晴隆县| 兴仁县| 磐石市| 韶山市| 昌黎县| 舟曲县| 兴和县| 绥化市| 丰原市| 阜新| 福建省| 河北区| 牙克石市| 徐水县| 湘阴县| 大埔县| 平昌县| 上饶县| 北票市| 达孜县| 湄潭县| 依安县| 五峰| 黑龙江省| 萝北县| 墨竹工卡县| 九江县| 开江县| 靖边县| 松江区| 龙岩市| 寿宁县| 甘洛县| 鞍山市| 开平市| 达拉特旗| 会同县|