service-worker - 在 nuxtjs 应用程序中禁用服务人员或工作箱

标签 service-worker progressive-web-apps nuxt.js

我正在尝试使用 nuxt generate 命令生成一个 nuxt 应用程序。我想通过打开 dist 文件夹中的 index.html 文件来使用它。除了我加载了一些静态 Assets 的一页之外,一切正常。我收到以下错误:

DOMException: Failed to construct 'Worker': Script at 'file:///Users/web-app/dist/_nuxt/a694c9435aa306bfdc85.worker.js' cannot be accessed from origin 'null'. at new e.exports (file:///Users/web-app/dist/_nuxt/ddebbd7698f3519f1f2a.js:2:387818) at Object.253 (file:///Users/web-app/dist/_nuxt/ddebbd7698f3519f1f2a.js:2:41913) at c (file:///Users/web-app/dist/_nuxt/849a5edcbb351f009715.js:1:534) at Module.318 (file:///Users/web-app/dist/_nuxt/58dff71a539121ee82b0.js:1:7082) at c (file:///Users/web-app/dist/_nuxt/849a5edcbb351f009715.js:1:534)

这是我的 nuxt.config.js 文件:


export default {
  mode: 'spa',
  /*
  ** Headers of the page
  */
  head: {
    title: process.env.npm_package_name || '',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: process.env.npm_package_description || '' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },
  /*
  ** Customize the progress-bar color
  */
  loading: { color: '#fff' },
  /*
  ** Global CSS
  */
  css: [
    '~/assets/css/tailwind.css',
    '~/assets/css/all.css'
  ],
  /*
  ** Plugins to load before mounting the App
  */
  plugins: [
  ],
  /*
  ** Nuxt.js modules
  */
  modules: [
    // Doc: https://axios.nuxtjs.org/usage
    '@nuxtjs/axios',
    '@nuxtjs/proxy',
    '@nuxtjs/toast'
  ],
  /*
  ** Axios module configuration
  ** See https://axios.nuxtjs.org/options
  */
  axios: {
  },
  /*
  ** Build configuration
  */
  build: {
    postcss: {
      plugins: {
        tailwindcss: './tailwind.config.js'
      }
    },
    /*
    ** You can extend webpack config here
    */

    extend(config, { isDev, isClient }) {
      if (!isDev) {
        // relative links, please.
        config.output.publicPath = "./_nuxt/";
      }
      return config;
    }
  },

  router: {
    mode: "hash"
  }
}

我想知道是否有任何方法可以禁用我的应用中的服务人员。

最佳答案

您可以disable nuxt.config.js 中的 workbox 子模块。

modules: [
  ['@nuxtjs/pwa', { workbox: false }],
],

关于service-worker - 在 nuxtjs 应用程序中禁用服务人员或工作箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57822378/

相关文章:

json - 尝试通过 Vue Axios 加载 json

javascript - 使用 service worker 更新 dom

javascript - 检测前端 Service Worker 激活

javascript - 尝试在注册服务 worker 之前运行获取功能。

Facebook JS SDK 渐进式网络应用程序问题

javascript - Progressive Web App : offline cache does not work on Android, 它适用于 Chrome 开发工具

vue.js - 我在 Nuxt 2.14.0 中运行的是什么版本的 Vue?

javascript - V-for 和 v-if,只复制父元素

javascript - chrome 通知退订事件

offline - 服务人员打额外电话