@wix/origami-site 0.1.33 → 0.1.35

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/origami-site",
3
- "version": "0.1.33",
3
+ "version": "0.1.35",
4
4
  "description": "Runs an exported Wix origami site: file-based routing, Wix dynamic pages, popups and build checks. Use with @wix/origami-site-astro or @wix/origami-site-express.",
5
5
  "type": "module",
6
6
  "files": [
@@ -93,5 +93,5 @@
93
93
  "optional": true
94
94
  }
95
95
  },
96
- "falconPackageHash": "f699993cd6dc0b08545a5b50b04d801776a7b77e10c81bd7ac6cd6e7"
96
+ "falconPackageHash": "15a773590435c36921b5af40b57a5210751db2d3a126e709581c9e33"
97
97
  }
@@ -0,0 +1,8 @@
1
+ /** The interactions service (v2) reads `process.env.browser` to tell the browser build from the SSR one.
2
+ * @returns {import('vite').Plugin} */
3
+ export function browserEnv() {
4
+ return {
5
+ name: 'origami:browser-env',
6
+ configEnvironment: name => name === 'client' ? { define: { 'process.env.browser': 'true' } } : undefined,
7
+ }
8
+ }
@@ -0,0 +1,30 @@
1
+ // Every generated stylesheet compiles on its own and imports the theme, so each gets the fonts plugin's `@font-face`
2
+ // rules: a page with a header and a footer would carry them three times. In the build, a CSS file keeps the first
3
+ // copy of each rule. A rule has no nested braces, so it ends at its first `}`.
4
+
5
+ const FONT_FACE = /@font-face\s*\{[^}]*\}/g
6
+
7
+ /** `css` with each `@font-face` rule only where it first appears.
8
+ * @param {string} css */
9
+ export const dedupeFontFaceRules = css => {
10
+ const seen = new Set()
11
+ return css.replace(FONT_FACE, rule => {
12
+ if (seen.has(rule)) return ''
13
+ seen.add(rule)
14
+ return rule
15
+ })
16
+ }
17
+
18
+ /** @returns {import('vite').Plugin} */
19
+ export const dedupeFontFaces = () => ({
20
+ name: 'origami:dedupe-font-faces',
21
+ apply: /** @type {const} */ ('build'),
22
+ /** @param {unknown} _ @param {Record<string, { type: string, fileName: string, source?: unknown }>} bundle */
23
+ generateBundle(_, bundle) {
24
+ for (const output of Object.values(bundle)) {
25
+ if (output.type === 'asset' && output.fileName.endsWith('.css') && typeof output.source === 'string') {
26
+ output.source = dedupeFontFaceRules(output.source)
27
+ }
28
+ }
29
+ },
30
+ })
@@ -3,6 +3,8 @@ import { globalImports } from './globalImports.js'
3
3
  import { pageList } from './pageList.js'
4
4
  import { sharedPackages } from './sharedPackages.js'
5
5
  import { wrapperAliases } from './wrapperAliases.js'
6
+ import { browserEnv } from './browserEnv.js'
7
+ import { dedupeFontFaces } from './dedupeFontFaces.js'
6
8
 
7
9
  /** @param {import('./index.js').OrigamiVitePluginsOptions} options
8
10
  * @returns {import('vite').Plugin[]} */
@@ -13,5 +15,7 @@ export function origamiVitePlugins({ root, siteTree }) {
13
15
  ...transforms({ root }),
14
16
  sharedPackages(),
15
17
  wrapperAliases(root),
18
+ browserEnv(),
19
+ dedupeFontFaces(),
16
20
  ]
17
21
  }