diff --git a/plugins/pwa/plugin-pwa/src/node/prepareConfigFile.ts b/plugins/pwa/plugin-pwa/src/node/prepareConfigFile.ts index a1852b4a93..c4741502c4 100644 --- a/plugins/pwa/plugin-pwa/src/node/prepareConfigFile.ts +++ b/plugins/pwa/plugin-pwa/src/node/prepareConfigFile.ts @@ -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) @@ -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: [ diff --git a/plugins/pwa/plugin-pwa/src/node/pwaPlugin.ts b/plugins/pwa/plugin-pwa/src/node/pwaPlugin.ts index 235ab63ffb..4cf60877af 100644 --- a/plugins/pwa/plugin-pwa/src/node/pwaPlugin.ts +++ b/plugins/pwa/plugin-pwa/src/node/pwaPlugin.ts @@ -2,7 +2,6 @@ import { addViteOptimizeDepsExclude, addViteSsrNoExternal, customizeDevServer, - getLocaleConfig, } from '@vuepress/helper' import type { PluginFunction } from 'vuepress/core' import { generateManifest } from './generateManifest.js' @@ -10,7 +9,6 @@ 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' @@ -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',