restyle-loader

Updates style <link>

href value with a hash to trigger a style reload

Loader new home: restyle-loader

安装

  1. npm install --save-dev restyle-loader

用法

文档:使用 loader

示例

webpack.config.js

  1. {
  2. test: /\.css?$/,
  3. use: [
  4. {
  5. loader: "restyle-loader"
  6. },
  7. {
  8. loader: "file-loader",
  9. options: {
  10. name: "[name].css?[hash:8]"
  11. }
  12. }
  13. ]
  14. }

hash 需要启用热模块替换(Hot Module Replacement)

bundle.js

  1. require("./index.css");
  2. // 在这里打包代码...

index.html

  1. <head>
  2. <link rel="stylesheet" type="text/css" href="css/index.css">
  3. </head>

loader 运行后就变成

  1. <head>
  2. <link rel="stylesheet" type="text/css" href="css/index.css?531fdfd0">
  3. </head>

维护人员

restyle-loader - 图1


Daniel Verejan