Giter Club home page Giter Club logo

static-resource-hash-webpack-plugin's Introduction

static-resource-hash-webpack-plugin

基于WebPack HTML/CSS/JS/Image Hash功能。实现逻辑为 当所有文件生成后,通过查找文件引用来更新Hash后的文件名,并生成对应的文件名json文件。不支持动态路径引用。

GitHub地址:https://github.com/li-guang/static-resource-hash-webpack-plugin

使用说明

在WebPack中使用时,要将此模块放置在最后,因为模块的执行是在最终生成的文件中进行的。

解析时,如果是CSS文件,引用文件以点开始或者非斜杠开头,则路径以CSS文件所在目录为基目录。如果其它文件,则以destRoot目录为基目录。

依赖crypto及glob

第一步,引用模块:

var StaticResHashPlugin = require('static-resource-hash-webpack-plugin')

第二步,加入到webpack plugins中:

new StaticResHashPlugin({
  log: true,
  hashLength: 8,
  destRoot: 'dist',
  publicPath: "your.host",
  outputFile: 'rename.json',
  hashFiles: ['/img/**/*', '/components/**/*.html', '/fonts/**/*', '/*.js', '/404.html', '/css/*.css' ],
  hostFiles: ['/**/*.js', '/**/*.html', '/css/*.css'],
  delay: 0
})
  • log 默认值为false,不输出Log信息
  • hashLength Hash值的长度,默认为8位,一般无需指定
  • destRoot 执行此Hash操作的目录,应该为输出目录
  • hashFiles 执行Hash操作的文件,即需要对哪些文件进行Hash重命名操作
  • hostFiles 在哪些文件里面查找文件引用,并执行替换
  • delay 此操作的执行延时(毫秒),默认不使用延时,即delay=0。如果出现提示某某文件不存在时,可以使用100ms的延时解决此问题。
  • publicPath 公共路径,一般是静态资源的host
  • outputFile 输出对应文件名json的文件

static-resource-hash-webpack-plugin's People

Contributors

li-guang avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.