首页 > 解决方案 > 在 React 和 webpack 中包含 manifest.js NOT manifest.json

问题描述

我能找到的所有解决方案都在谈论manifest.json。我可能会遇到这个错误,但是在我的 manifest.js 中,我的`manifest.js 中有一些要求,所以我认为它不可能是一个 json 文件。


我尝试在我webpack.config.js的 .

  {
    test: /manifest.js$/,
    use: [
      {
        loader: "file-loader",
        options: {
          name: "ui/[name].[hash].json",
        },
      },
      "extract-loader",
    ],
  },

这是我的manifest.js

const Icon192 = require("../images/icon-192x192.png");
const Icon512 = require("../images/icon-512x512.png")

const manifest = {
  icons: [
    {
      src: Icon192,
      sizes: "192x192",
      type: "image/png",
    },
    {
      src: Icon512,
      sizes: "512x512",
      type: "image/png",
    },
  ],
  name: "My_App",
  short_name: "My_App",
  orientation: "portrait",
  display: "standalone",
  start_url: "/",
  theme_color: "    #228B22",
  background_color: "#ffffff",
  description: "Any Maskable",
  start_url: "https://example.com",
  display: "browser",
  prefer_related_applications: false
};

module.exports = JSON.stringify(manifest, null, 2);

如果我不需要这些要求,并且可以以不同的方式做到这一点,请告诉我

标签: reactjswebpackmanifestmanifest.json

解决方案


推荐阅读