@x-wave/blog 1.1.1 → 1.1.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.
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@x-wave/blog",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
7
7
  "import": "./index.js",
8
8
  "types": "./index.d.ts"
9
9
  },
10
+ "./vite": {
11
+ "import": "./vite/index.js"
12
+ },
10
13
  "./locales": {
11
14
  "import": "./locales/index.js",
12
15
  "types": "./locales/index.d.ts"
@@ -41,12 +44,10 @@
41
44
  "react": "^19.0.0",
42
45
  "react-dom": "^19.0.0",
43
46
  "react-i18next": "^15.7.3",
44
- "react-router-dom": "^7.9.1",
45
- "react-helmet-async": "^2.0.5"
47
+ "react-router-dom": "^7.9.1"
46
48
  },
47
49
  "devDependencies": {
48
50
  "@vitejs/plugin-react-swc": "^3.10.1",
49
- "react-helmet-async": "^2.0.5",
50
51
  "sass": "^1.97.3",
51
52
  "vite": "^6.3.5",
52
53
  "vite-tsconfig-paths": "^5.1.4"
package/vite/index.js ADDED
@@ -0,0 +1,143 @@
1
+ import fs from 'node:fs'
2
+ import { createRequire } from 'node:module'
3
+ import path from 'node:path'
4
+ import react from '@vitejs/plugin-react-swc'
5
+ import { defineConfig } from 'vite'
6
+ import checker from 'vite-plugin-checker'
7
+ import svgr from 'vite-plugin-svgr'
8
+ import tsconfigPaths from 'vite-tsconfig-paths'
9
+
10
+ const require = createRequire(import.meta.url)
11
+ const vitePrerender = require('vite-plugin-prerender')
12
+
13
+ const normalizeBasePath = (basePath) => {
14
+ const value = basePath || '/'
15
+ if (value === '/') return '/'
16
+ const withLeadingSlash = value.startsWith('/') ? value : `/${value}`
17
+ return withLeadingSlash.endsWith('/')
18
+ ? withLeadingSlash.slice(0, -1)
19
+ : withLeadingSlash
20
+ }
21
+
22
+ const normalizeRoute = (route) => {
23
+ if (route === '/') return '/'
24
+ const withLeadingSlash = route.startsWith('/') ? route : `/${route}`
25
+ return withLeadingSlash.endsWith('/')
26
+ ? withLeadingSlash.slice(0, -1)
27
+ : withLeadingSlash
28
+ }
29
+
30
+ const resolvePrerenderRoutes = (docsAbsolutePath, additionalRoutes = []) => {
31
+ const routes = new Set(['/'])
32
+
33
+ for (const route of additionalRoutes) {
34
+ routes.add(normalizeRoute(route))
35
+ }
36
+
37
+ if (!fs.existsSync(docsAbsolutePath)) {
38
+ return Array.from(routes)
39
+ }
40
+
41
+ const languageDirs = fs
42
+ .readdirSync(docsAbsolutePath, { withFileTypes: true })
43
+ .filter((entry) => entry.isDirectory())
44
+ .map((entry) => entry.name)
45
+
46
+ for (const language of languageDirs) {
47
+ routes.add(`/${language}`)
48
+
49
+ const languageDir = path.join(docsAbsolutePath, language)
50
+ const mdxFiles = fs
51
+ .readdirSync(languageDir, { withFileTypes: true })
52
+ .filter((entry) => entry.isFile() && entry.name.endsWith('.mdx'))
53
+
54
+ for (const file of mdxFiles) {
55
+ if (file.name.endsWith('-advanced.mdx')) continue
56
+ const slug = file.name.replace(/\.mdx$/, '')
57
+ routes.add(`/${language}/${slug}`)
58
+ }
59
+ }
60
+
61
+ return Array.from(routes)
62
+ }
63
+
64
+ export function createBlogViteConfig(options = {}) {
65
+ const {
66
+ basePath = process.env.VITE_BASE_PATH || '/',
67
+ docsDir = 'src/docs',
68
+ renderTarget = '#root',
69
+ renderAfterTime = 1200,
70
+ additionalPrerenderRoutes = [],
71
+ enableTypeChecker = true,
72
+ baseConfig = {},
73
+ } = options
74
+
75
+ const base = normalizeBasePath(basePath)
76
+ const docsAbsolutePath = path.resolve(process.cwd(), docsDir)
77
+ const routes = resolvePrerenderRoutes(
78
+ docsAbsolutePath,
79
+ additionalPrerenderRoutes,
80
+ )
81
+
82
+ const plugins = [react(), svgr(), tsconfigPaths()]
83
+
84
+ if (enableTypeChecker) {
85
+ plugins.push(checker({ typescript: true }))
86
+ }
87
+
88
+ plugins.push(
89
+ vitePrerender({
90
+ staticDir: path.join(process.cwd(), 'dist'),
91
+ renderTarget,
92
+ routes,
93
+ renderer: new vitePrerender.PuppeteerRenderer({
94
+ renderAfterTime,
95
+ }),
96
+ }),
97
+ )
98
+
99
+ const blogConfig = {
100
+ base,
101
+ plugins,
102
+ css: {
103
+ preprocessorOptions: {
104
+ scss: {
105
+ api: 'modern-compiler',
106
+ },
107
+ },
108
+ modules: {
109
+ localsConvention: 'camelCase',
110
+ },
111
+ },
112
+ optimizeDeps: {
113
+ include: ['react/jsx-runtime'],
114
+ },
115
+ }
116
+
117
+ // Merge with base config
118
+ return defineConfig({
119
+ ...baseConfig,
120
+ ...blogConfig,
121
+ plugins: [...(baseConfig.plugins || []), ...plugins],
122
+ css: {
123
+ ...(baseConfig.css || {}),
124
+ ...blogConfig.css,
125
+ preprocessorOptions: {
126
+ ...(baseConfig.css?.preprocessorOptions || {}),
127
+ ...blogConfig.css.preprocessorOptions,
128
+ },
129
+ modules: {
130
+ ...(baseConfig.css?.modules || {}),
131
+ ...blogConfig.css.modules,
132
+ },
133
+ },
134
+ optimizeDeps: {
135
+ ...(baseConfig.optimizeDeps || {}),
136
+ ...blogConfig.optimizeDeps,
137
+ include: [
138
+ ...(baseConfig.optimizeDeps?.include || []),
139
+ ...(blogConfig.optimizeDeps?.include || []),
140
+ ],
141
+ },
142
+ })
143
+ }