@woodsportal/hubspot-kit 1.0.41-dev.1 → 1.0.41-dev.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,22 @@
1
1
  export type ModuleConfigOverlaySide = 'left' | 'right'
2
2
 
3
- const STORAGE_KEY = 'woodsportal:module-config-overlay-side'
3
+ const STORAGE_KEY = 'wp.d.cfg.side'
4
+ const LEGACY_STORAGE_KEY = 'woodsportal:module-config-overlay-side'
4
5
 
5
6
  export function loadModuleConfigOverlaySide(): ModuleConfigOverlaySide {
6
7
  if (typeof window === 'undefined') return 'right'
7
8
  try {
8
- const value = window.localStorage.getItem(STORAGE_KEY)
9
- return value === 'left' ? 'left' : 'right'
9
+ const value =
10
+ window.localStorage.getItem(STORAGE_KEY) ??
11
+ window.localStorage.getItem(LEGACY_STORAGE_KEY)
12
+ if (value === 'left' || value === 'right') {
13
+ if (!window.localStorage.getItem(STORAGE_KEY)) {
14
+ window.localStorage.setItem(STORAGE_KEY, value)
15
+ window.localStorage.removeItem(LEGACY_STORAGE_KEY)
16
+ }
17
+ return value
18
+ }
19
+ return 'right'
10
20
  } catch {
11
21
  return 'right'
12
22
  }
@@ -1,6 +1,7 @@
1
1
  export type ModuleConfigToolbarTheme = 'light' | 'dark'
2
2
 
3
- const STORAGE_KEY = 'woodsportal:module-config-toolbar-theme'
3
+ const STORAGE_KEY = 'wp.d.cfg.theme'
4
+ const LEGACY_STORAGE_KEY = 'woodsportal:module-config-toolbar-theme'
4
5
 
5
6
  export function detectPortalTheme(): ModuleConfigToolbarTheme {
6
7
  if (typeof document === 'undefined') return 'light'
@@ -10,8 +11,16 @@ export function detectPortalTheme(): ModuleConfigToolbarTheme {
10
11
  export function loadModuleConfigToolbarTheme(): ModuleConfigToolbarTheme {
11
12
  if (typeof window === 'undefined') return 'light'
12
13
  try {
13
- const stored = window.localStorage.getItem(STORAGE_KEY)
14
- if (stored === 'dark' || stored === 'light') return stored
14
+ const stored =
15
+ window.localStorage.getItem(STORAGE_KEY) ??
16
+ window.localStorage.getItem(LEGACY_STORAGE_KEY)
17
+ if (stored === 'dark' || stored === 'light') {
18
+ if (!window.localStorage.getItem(STORAGE_KEY)) {
19
+ window.localStorage.setItem(STORAGE_KEY, stored)
20
+ window.localStorage.removeItem(LEGACY_STORAGE_KEY)
21
+ }
22
+ return stored
23
+ }
15
24
  } catch {
16
25
  // ignore
17
26
  }
@@ -8,37 +8,50 @@ import {
8
8
  root,
9
9
  } from '../scripts/vite/portal-build-shared.js'
10
10
 
11
- const vendorGlobals = {
12
- react: 'WoodsPortalVendor.React',
13
- 'react/jsx-runtime': 'WoodsPortalVendor.jsxRuntime',
14
- 'react/jsx-dev-runtime': 'WoodsPortalVendor.jsxDevRuntime',
15
- 'react-dom': 'WoodsPortalVendor.ReactDOM',
16
- 'react-dom/client': 'WoodsPortalVendor.ReactDOMClient',
17
- }
11
+ const buildId = portalBuildId()
18
12
 
19
- export default defineConfig(({ mode }) => ({
20
- plugins: portalPlugins(mode, { codeSplitting: false }),
21
- resolve: portalResolve(mode),
22
- define: portalDefine(mode),
23
- build: {
24
- outDir: resolve(root, 'dist/cdn'),
25
- emptyOutDir: false,
26
- copyPublicDir: false,
27
- cssCodeSplit: false,
28
- lib: {
29
- entry: resolve(root, 'src/cdn/app-entry.ts'),
30
- name: 'WoodsPortalApp',
31
- fileName: () => `app.${portalBuildId()}.js`,
32
- formats: ['iife'],
13
+ /** Longest-match first bare `react` must not swallow `react/jsx-runtime`. */
14
+ const reactShimAliases = [
15
+ { find: 'react/jsx-runtime', replacement: resolve(root, 'src/cdn/shims/react-jsx-runtime.ts') },
16
+ { find: 'react/jsx-dev-runtime', replacement: resolve(root, 'src/cdn/shims/react-jsx-runtime.ts') },
17
+ { find: 'react-dom/client', replacement: resolve(root, 'src/cdn/shims/react-dom-client.ts') },
18
+ { find: 'react-dom', replacement: resolve(root, 'src/cdn/shims/react-dom.ts') },
19
+ { find: 'react', replacement: resolve(root, 'src/cdn/shims/react.ts') },
20
+ ]
21
+
22
+ export default defineConfig(({ mode }) => {
23
+ const baseResolve = portalResolve(mode)
24
+ return {
25
+ // Relative base so dynamic import() resolves lazy chunks from jsDelivr (same dir as app.js), not HubSpot origin.
26
+ base: './',
27
+ // TanStack autoCodeSplitting + ESM CDN entry caused router.init stack overflow on HubSpot.
28
+ // Keep Rollup lazy chunks via React.lazy() / dynamic import(); route modules stay in the app entry.
29
+ plugins: portalPlugins(mode, { codeSplitting: false }),
30
+ resolve: {
31
+ ...baseResolve,
32
+ alias: [...reactShimAliases, ...(baseResolve.alias ?? [])],
33
33
  },
34
- rollupOptions: {
35
- external: Object.keys(vendorGlobals),
36
- output: {
37
- globals: vendorGlobals,
38
- inlineDynamicImports: true,
39
- assetFileNames: `app.${portalBuildId()}.css`,
34
+ define: portalDefine(mode),
35
+ build: {
36
+ outDir: resolve(root, 'dist/cdn'),
37
+ emptyOutDir: false,
38
+ copyPublicDir: false,
39
+ cssCodeSplit: false,
40
+ rollupOptions: {
41
+ input: resolve(root, 'src/cdn/app-entry.ts'),
42
+ output: {
43
+ format: 'es',
44
+ entryFileNames: `app.${buildId}.js`,
45
+ chunkFileNames: `chunks/[name].${buildId}.[hash].js`,
46
+ assetFileNames: (assetInfo) => {
47
+ if (assetInfo.name?.endsWith('.css')) {
48
+ return `app.${buildId}.css`
49
+ }
50
+ return `assets/[name].[hash][extname]`
51
+ },
52
+ },
40
53
  },
54
+ minify: true,
41
55
  },
42
- minify: true,
43
- },
44
- }))
56
+ }
57
+ })
@@ -0,0 +1,34 @@
1
+ /**
2
+ * CDN app bundle audit — rollup visualizer treemap for dist/cdn/app.*.js graph.
3
+ * Usage: yarn vite build --config vite.config.cdn-audit.mjs --mode prod
4
+ */
5
+ import { defineConfig, mergeConfig } from 'vite'
6
+ import { resolve } from 'node:path'
7
+ import { importConsumerDep } from '../scripts/resolve-consumer-dep.mjs'
8
+ import { root } from '../scripts/vite/portal-build-shared.js'
9
+ import cdnAppConfig from './vite.config.cdn-app.mjs'
10
+
11
+ const { default: visualizer } = await importConsumerDep('rollup-plugin-visualizer')
12
+
13
+ export default defineConfig((env) =>
14
+ mergeConfig(typeof cdnAppConfig === 'function' ? cdnAppConfig(env) : cdnAppConfig, {
15
+ build: {
16
+ sourcemap: true,
17
+ rollupOptions: {
18
+ plugins: [
19
+ visualizer({
20
+ filename: resolve(root, 'docs/audit/cdn-bundle-stats.html'),
21
+ gzipSize: true,
22
+ brotliSize: true,
23
+ template: 'treemap',
24
+ }),
25
+ visualizer({
26
+ filename: resolve(root, 'docs/audit/cdn-bundle-visualizer.json'),
27
+ json: true,
28
+ gzipSize: true,
29
+ }),
30
+ ],
31
+ },
32
+ },
33
+ }),
34
+ )
@@ -10,7 +10,7 @@ import {
10
10
 
11
11
  /** Phase 2: ESM CDN build with route code-splitting (not used for HubSpot module.js). */
12
12
  export default defineConfig(({ mode }) => ({
13
- plugins: portalPlugins(mode, { codeSplitting: true }),
13
+ plugins: portalPlugins(mode, { codeSplitting: false }),
14
14
  resolve: portalResolve(mode),
15
15
  define: portalDefine(mode),
16
16
  build: {