【问题标题】:How to add appcache plugin?如何添加appcache插件?
【发布时间】:2018-06-21 06:31:45
【问题描述】:

我刚刚使用preact create default helloworld 创建了一个简单的应用程序,现在我需要向它添加一个manifest.appcache。该怎么做?

我尝试过的:

我找到了一个叫appcache-webpack-plugin 的东西,并用npm i appcache-webpack-plugin 安装了它。现在我大概require()吧?但是如何,在哪里?

https://github.com/lettertwo/appcache-webpack-plugin

也在寻找一种 Webpack 配置,因为我读到 preact 使用 Webpack,但项目目录中没有任何配置。

【问题讨论】:

    标签: webpack preact


    【解决方案1】:

    创建一个文件src/template.html 并将其复制并粘贴到其中: https://github.com/developit/preact-cli/blob/master/src/resources/template.html

    然后将您的清单属性添加到<html>

    您可能需要修改您的 package.json 脚本以传递 --template src/template.html

    【讨论】:

      【解决方案2】:

      我将此preact.config.js 添加到我的项目中。

      var AppCachePlugin = require('appcache-webpack-plugin');
      
      var manifest = new AppCachePlugin({
          cache: ['*'],
          network: ['/login'],
          fallback: [],
          output: 'manifest.appcache'
      })
      
      export default function (config, env, helpers) {
          console.log('AppCachePlugin loaded')
          var fs = require('fs')
          config.plugins.push(manifest)
      }
      

      虽然我仍然不知道如何修改 index.html 以包含<html manifest=manifest.appcache>

      【讨论】:

        猜你喜欢
        • 2012-02-17
        • 2014-11-09
        • 1970-01-01
        • 2015-03-08
        • 1970-01-01
        • 1970-01-01
        • 2018-07-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多