【问题标题】:Disable service workers or workbox in nuxtjs app在 nuxtjs 应用程序中禁用服务人员或工作箱
【发布时间】:2019-09-06 12:49:46
【问题描述】:

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

DOMException:无法构造“Worker”:脚本位于 'file:///Users/web-app/dist/_nuxt/a694c9435aa306bfdc85.worker.js' 无法从源“null”访问。 在新的 e.exports (file:///Users/web-app/dist/_nuxt/ddebbd7698f3519f1f2a.js:2:387818) 在 Object.253 (file:///Users/web-app/dist/_nuxt/ddebbd7698f3519f1f2a.js:2:41913) 在 c (file:///Users/web-app/dist/_nuxt/849a5edcbb351f009715.js:1:534) 在 Module.318 (file:///Users/web-app/dist/_nuxt/58dff71a539121ee82b0.js:1:7082) 在 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"
  }
}

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

【问题讨论】:

  • 尝试使用 serve 之类的东西,而不是直接加载文件。 file:// 的原始权限与作为 Web 服务器运行完全不同。
  • @abraham 这是我无法通过调用serve 命令创建http 服务器的情况。用户将双击index.html 文件打开页面。他们无法执行serve 命令。只是想知道是否有任何方法可以删除service worker
  • 尝试禁用autoRegister
  • @abraham 没用。仍然显示相同的错误消息。

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


【解决方案1】:

您可以在nuxt.config.jsdisable workbox 子模块。

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

【讨论】:

  • 我会完全删除 @nuxtjs/pwa 模块。
  • 我尝试删除 pwa,但仍然有很多浏览器尝试请求 sw.js,导致 404 错误。
  • @Devin 然后手动删除您的服务人员。之前已经注册love2dev.com/blog/how-to-uninstall-a-service-worker
  • modules: [ ['@nuxtjs/pwa', { workbox: { enabled: false } }], ], 将禁用和注销服务工作者
猜你喜欢
  • 2018-05-22
  • 2018-07-02
  • 1970-01-01
  • 1970-01-01
  • 2020-05-03
  • 2019-11-08
  • 1970-01-01
  • 1970-01-01
  • 2019-01-15
相关资源
最近更新 更多