Skip to content

Commit

Permalink
feat(plugin-pwa): prevent defining variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Sep 29, 2024
1 parent aed3060 commit ec0d8d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
15 changes: 12 additions & 3 deletions plugins/pwa/plugin-pwa/src/node/prepareConfigFile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { getRealPath } from '@vuepress/helper'
import { getLocaleConfig, getRealPath } from '@vuepress/helper'
import type { App } from 'vuepress/core'
import { getDirname, path } from 'vuepress/utils'
import { pwaLocales } from './locales.js'
import { PLUGIN_NAME } from './logger.js'
import type { PwaPluginOptions } from './options.js'

const __dirname = getDirname(import.meta.url)
Expand Down Expand Up @@ -49,11 +51,18 @@ import { setupPwa, setupViewPoint } from "${path.join(__dirname, '../client/comp
${configImport}
import "${getRealPath('@vuepress/plugin-pwa/styles/vars.css', import.meta.url)}";
const locales = __PWA_LOCALES__;
const locales = ${JSON.stringify(
getLocaleConfig({
app,
name: PLUGIN_NAME,
default: pwaLocales,
config: options.locales,
}),
)};
export default defineClientConfig({
setup: () => {
setupPwa(__SW_PATH__, __SW_FORCE_UPDATE__);
setupPwa(${options.serviceWorkerFilename ?? 'service-worker.js'}, ${options.update === 'force'});
setupViewPoint();
},
rootComponents: [
Expand Down
13 changes: 0 additions & 13 deletions plugins/pwa/plugin-pwa/src/node/pwaPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import {
addViteOptimizeDepsExclude,
addViteSsrNoExternal,
customizeDevServer,
getLocaleConfig,
} from '@vuepress/helper'
import type { PluginFunction } from 'vuepress/core'
import { generateManifest } from './generateManifest.js'
import { generateServiceWorker } from './generateServiceWorker.js'
import { getManifest } from './getManifest.js'
import { appendBase } from './helper.js'
import { injectLinksToHead } from './injectLinksToHead.js'
import { pwaLocales } from './locales.js'
import { PLUGIN_NAME, logger } from './logger.js'
import type { PwaPluginOptions } from './options.js'
import { prepareConfigFile } from './prepareConfigFile.js'
Expand All @@ -34,17 +32,6 @@ export const pwaPlugin =
return {
name: PLUGIN_NAME,

define: () => ({
__PWA_LOCALES__: getLocaleConfig({
app,
name: PLUGIN_NAME,
default: pwaLocales,
config: options.locales,
}),
__SW_FORCE_UPDATE__: options.update === 'force',
__SW_PATH__: options.serviceWorkerFilename || 'service-worker.js',
}),

extendsBundlerOptions: (bundlerOptions: unknown): void => {
addViteOptimizeDepsExclude(bundlerOptions, app, [
'mitt',
Expand Down

0 comments on commit ec0d8d0

Please sign in to comment.