Skip to content

created toggle with process.env.VUE_APP_ALLOW_LOCAL_SW to allow local… #3329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { register } from 'register-service-worker'

if (process.env.NODE_ENV === 'production') {
if (process.env.NODE_ENV === 'production' || process.env.VUE_APP_ALLOW_LOCAL_SW === 'true') {
register(`${process.env.BASE_URL}service-worker.js`, {
ready () {
console.log(
Expand Down
14 changes: 9 additions & 5 deletions packages/@vue/cli-plugin-pwa/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ module.exports = (api, options) => {
.after('html')

// generate /service-worker.js in production mode
if (process.env.NODE_ENV === 'production') {
// or when local service worker development is allowed
if (process.env.NODE_ENV === 'production' || process.env.VUE_APP_ALLOW_LOCAL_SW === 'true') {
// Default to GenerateSW mode, though InjectManifest also might be used.
const workboxPluginMode = userOptions.workboxPluginMode || 'GenerateSW'
const workboxWebpackModule = require('workbox-webpack-plugin')
Expand Down Expand Up @@ -52,8 +53,11 @@ module.exports = (api, options) => {
})

// install dev server middleware for resetting service worker during dev
const createNoopServiceWorkerMiddleware = require('./lib/noopServiceWorkerMiddleware')
api.configureDevServer(app => {
app.use(createNoopServiceWorkerMiddleware())
})
// when local service worker development is not allowed (default)
if(process.env.VUE_APP_ALLOW_LOCAL_SW !== 'true') {
const createNoopServiceWorkerMiddleware = require('./lib/noopServiceWorkerMiddleware')
api.configureDevServer(app => {
app.use(createNoopServiceWorkerMiddleware())
})
}
}