@nikoyo-spa/vite-config 1.0.0 → 1.0.2
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/dist/index.mjs +1 -1
- package/package.json +5 -4
- package/build.config.ts +0 -24
- package/src/index.ts +0 -227
- package/tsconfig.json +0 -42
package/dist/index.mjs
CHANGED
|
@@ -43,7 +43,7 @@ function defineConfig(userConfig = {}) {
|
|
|
43
43
|
base = VITE_BASE_URL;
|
|
44
44
|
singleSpaConfig = {
|
|
45
45
|
type: "root",
|
|
46
|
-
imo: () => "/shared/import-map-overrides@
|
|
46
|
+
imo: () => "/shared/import-map-overrides@6.1.0.js",
|
|
47
47
|
importMaps: {
|
|
48
48
|
dev: ["src/importMap.dev.json", "node_modules/@nikoyo-spa/import-map-shared/dist/shared/importMap.shared.json"],
|
|
49
49
|
build: ["src/importMap.json", "node_modules/@nikoyo-spa/import-map-shared/dist/shared/importMap.shared.json"]
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nikoyo-spa/vite-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"description": "Spa Vite Config",
|
|
6
6
|
"author": "qianyongdong <https://github.com/qianyongdong>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
19
|
-
"types": "./
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
20
|
"default": "./dist/index.mjs"
|
|
21
21
|
}
|
|
22
22
|
},
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"module": "./dist/index.mjs",
|
|
25
25
|
"types": "./dist/index.d.ts",
|
|
26
26
|
"files": [
|
|
27
|
-
"
|
|
27
|
+
"dist"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@iconify-json/carbon": "^1.2.15",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"vite-plugin-compression2": "^2.4.0",
|
|
48
48
|
"vite-plugin-inspect": "^11.1.0",
|
|
49
49
|
"vite-plugin-single-spa": "^1.1.0",
|
|
50
|
+
"vite-plugin-vue-devtools": "^8.0.5",
|
|
50
51
|
"vite-plugin-vue-layouts": "^0.11.0",
|
|
51
52
|
"vite-plugin-webfont-dl": "^3.11.1",
|
|
52
53
|
"vue": "^3.5.25",
|
|
@@ -54,8 +55,8 @@
|
|
|
54
55
|
"vue-router": "^4.6.4",
|
|
55
56
|
"@nikoyo-spa/components": "1.0.0",
|
|
56
57
|
"@nikoyo-spa/core": "1.0.0",
|
|
57
|
-
"@nikoyo-spa/icons": "1.0.0",
|
|
58
58
|
"@nikoyo-spa/import-map-shared": "1.0.0",
|
|
59
|
+
"@nikoyo-spa/icons": "1.0.0",
|
|
59
60
|
"@nikoyo-spa/metadata": "1.0.0",
|
|
60
61
|
"@nikoyo-spa/resolvers": "1.0.0"
|
|
61
62
|
},
|
package/build.config.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { defineBuildConfig } from 'unbuild'
|
|
2
|
-
|
|
3
|
-
export default defineBuildConfig({
|
|
4
|
-
clean: true,
|
|
5
|
-
declaration: true,
|
|
6
|
-
entries: ['src/index'],
|
|
7
|
-
externals: [
|
|
8
|
-
'@tailwindcss/vite',
|
|
9
|
-
'@unhead/vue',
|
|
10
|
-
'@vitejs/plugin-vue',
|
|
11
|
-
'unplugin-auto-import/vite',
|
|
12
|
-
'unplugin-icons',
|
|
13
|
-
'unplugin-vue-components',
|
|
14
|
-
'unplugin-vue-router',
|
|
15
|
-
'vite',
|
|
16
|
-
'unplugin-auto-import/vite',
|
|
17
|
-
'vite-plugin-compression2',
|
|
18
|
-
'vite-plugin-vue-devtools',
|
|
19
|
-
'vite-plugin-vue-layouts',
|
|
20
|
-
'vite-plugin-webfont-dl',
|
|
21
|
-
'vite-plugin-single-spa',
|
|
22
|
-
/@nikoyo-spa\/.*/
|
|
23
|
-
],
|
|
24
|
-
})
|
package/src/index.ts
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
import type { SingleSpaPluginOptions } from 'vite-plugin-single-spa'
|
|
2
|
-
import fs from 'node:fs'
|
|
3
|
-
|
|
4
|
-
import path from 'node:path'
|
|
5
|
-
import { VITE_BUILD_EXTERNAL } from '@nikoyo-spa/import-map-shared'
|
|
6
|
-
import { NikoyoSPAComponentsResolver, NikoyoSPACoreResolver } from '@nikoyo-spa/resolvers'
|
|
7
|
-
import Tailwindcss from '@tailwindcss/vite'
|
|
8
|
-
import { unheadVueComposablesImports } from '@unhead/vue'
|
|
9
|
-
import Vue from '@vitejs/plugin-vue'
|
|
10
|
-
import AutoImport from 'unplugin-auto-import/vite'
|
|
11
|
-
import { FileSystemIconLoader } from 'unplugin-icons/loaders'
|
|
12
|
-
import IconsResolver from 'unplugin-icons/resolver'
|
|
13
|
-
import Icons from 'unplugin-icons/vite'
|
|
14
|
-
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
|
15
|
-
import Components from 'unplugin-vue-components/vite'
|
|
16
|
-
import { VueRouterAutoImports } from 'unplugin-vue-router'
|
|
17
|
-
import VueRouter from 'unplugin-vue-router/vite'
|
|
18
|
-
import { loadEnv, mergeConfig, defineConfig as viteDefineConfig } from 'vite'
|
|
19
|
-
import { compression } from 'vite-plugin-compression2'
|
|
20
|
-
import VitePluginSingleSpa from 'vite-plugin-single-spa'
|
|
21
|
-
import VueDevTools from 'vite-plugin-vue-devtools'
|
|
22
|
-
import Layouts from 'vite-plugin-vue-layouts'
|
|
23
|
-
import WebfontDownload from 'vite-plugin-webfont-dl'
|
|
24
|
-
|
|
25
|
-
function defineConfig(userConfig: Record<string, any> = {}) {
|
|
26
|
-
return viteDefineConfig(({ command, mode }) => {
|
|
27
|
-
// 加载环境变量
|
|
28
|
-
const env = loadEnv(mode, process.cwd())
|
|
29
|
-
const {
|
|
30
|
-
VITE_BASE_URL = '/', // 打包路径
|
|
31
|
-
VITE_API_URL = '/', // 接口路径
|
|
32
|
-
VITE_DEV_PORT = 8081,
|
|
33
|
-
VITE_PROXY_HOST = 'http://localhost:8080',
|
|
34
|
-
} = env
|
|
35
|
-
const port = +VITE_DEV_PORT
|
|
36
|
-
const isBuild = command === 'build'
|
|
37
|
-
|
|
38
|
-
// 获取spa配置
|
|
39
|
-
const pkgPath = path.resolve(process.cwd(), 'package.json')
|
|
40
|
-
const pkg: { name: string } = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
|
|
41
|
-
const { name } = pkg
|
|
42
|
-
const isRoot = name.startsWith('@nikoyo-spa/root-')
|
|
43
|
-
let singleSpaConfig: SingleSpaPluginOptions
|
|
44
|
-
let base: string
|
|
45
|
-
|
|
46
|
-
if (isRoot) {
|
|
47
|
-
base = VITE_BASE_URL
|
|
48
|
-
singleSpaConfig = {
|
|
49
|
-
type: 'root',
|
|
50
|
-
imo: () => '/shared/import-map-overrides@3.1.1.js',
|
|
51
|
-
importMaps: {
|
|
52
|
-
dev: ['src/importMap.dev.json', 'node_modules/@nikoyo-spa/import-map-shared/dist/shared/importMap.shared.json'],
|
|
53
|
-
build: ['src/importMap.json', 'node_modules/@nikoyo-spa/import-map-shared/dist/shared/importMap.shared.json'],
|
|
54
|
-
},
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
const projectId = name.replace('@nikoyo-spa/app-', '')
|
|
59
|
-
base = `/modules/${projectId}/`
|
|
60
|
-
singleSpaConfig = {
|
|
61
|
-
type: 'mife',
|
|
62
|
-
serverPort: port,
|
|
63
|
-
spaEntryPoints: 'src/main.ts',
|
|
64
|
-
projectId,
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return mergeConfig(
|
|
69
|
-
{
|
|
70
|
-
base,
|
|
71
|
-
define: {
|
|
72
|
-
__BASE_URL__: JSON.stringify(VITE_BASE_URL),
|
|
73
|
-
__API_URL__: JSON.stringify(VITE_API_URL),
|
|
74
|
-
},
|
|
75
|
-
resolve: {
|
|
76
|
-
alias: {
|
|
77
|
-
'@': path.resolve(process.cwd(), './src'),
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
plugins: [
|
|
81
|
-
// https://github.com/vitejs/vite-plugin-vue
|
|
82
|
-
Vue(),
|
|
83
|
-
// https://github.com/posva/unplugin-vue-router
|
|
84
|
-
VueRouter({
|
|
85
|
-
extensions: ['.vue'],
|
|
86
|
-
routesFolder: [
|
|
87
|
-
'./src/pages',
|
|
88
|
-
],
|
|
89
|
-
dts: 'src/typed-router.d.ts',
|
|
90
|
-
}),
|
|
91
|
-
// https://github.com/johncampionjr/vite-plugin-vue-layouts
|
|
92
|
-
Layouts(),
|
|
93
|
-
// https://github.com/tailwindlabs/tailwindcss
|
|
94
|
-
Tailwindcss(),
|
|
95
|
-
// https://github.com/unplugin/unplugin-auto-import
|
|
96
|
-
AutoImport({
|
|
97
|
-
imports: [
|
|
98
|
-
'vue',
|
|
99
|
-
'vue-i18n',
|
|
100
|
-
'@vueuse/core',
|
|
101
|
-
'pinia',
|
|
102
|
-
unheadVueComposablesImports,
|
|
103
|
-
VueRouterAutoImports,
|
|
104
|
-
NikoyoSPACoreResolver(),
|
|
105
|
-
{
|
|
106
|
-
'vue-router/auto': ['useLink'],
|
|
107
|
-
'element-plus': ['ElMessage', 'ElLoading'],
|
|
108
|
-
},
|
|
109
|
-
],
|
|
110
|
-
resolvers: [
|
|
111
|
-
ElementPlusResolver({ importStyle: false }),
|
|
112
|
-
IconsResolver({
|
|
113
|
-
prefix: 'Icon',
|
|
114
|
-
}),
|
|
115
|
-
],
|
|
116
|
-
dirs: ['src/apis/**', 'src/constants/**', 'src/composables/**', 'src/stores/**', 'src/utils/**'],
|
|
117
|
-
dts: 'src/auto-imports.d.ts',
|
|
118
|
-
vueTemplate: true,
|
|
119
|
-
}),
|
|
120
|
-
// https://github.com/unplugin/unplugin-vue-components
|
|
121
|
-
Components({
|
|
122
|
-
resolvers: [
|
|
123
|
-
ElementPlusResolver({ importStyle: false }),
|
|
124
|
-
NikoyoSPAComponentsResolver(),
|
|
125
|
-
IconsResolver({
|
|
126
|
-
enabledCollections: ['ep', 'mdi', 'carbon'],
|
|
127
|
-
customCollections: ['custom', 'nikoyo'],
|
|
128
|
-
}),
|
|
129
|
-
],
|
|
130
|
-
extensions: ['vue'],
|
|
131
|
-
include: [/\.vue$/, /\.vue\?vue/],
|
|
132
|
-
dts: 'src/components.d.ts',
|
|
133
|
-
}),
|
|
134
|
-
// https://github.com/unplugin/unplugin-icons
|
|
135
|
-
Icons({
|
|
136
|
-
autoInstall: true,
|
|
137
|
-
customCollections: {
|
|
138
|
-
custom: FileSystemIconLoader(
|
|
139
|
-
path.resolve(process.cwd(), './src/assets/icons'),
|
|
140
|
-
svg => svg.replace(/^<svg /, '<svg fill="currentColor" '),
|
|
141
|
-
),
|
|
142
|
-
nikoyo: async (iconName) => {
|
|
143
|
-
const icons = await import('@nikoyo-spa/icons')
|
|
144
|
-
// @ts-ignore
|
|
145
|
-
const icon = icons.default?.[kebabToPascalCase(iconName)]
|
|
146
|
-
if (!icon) {
|
|
147
|
-
throw new Error(`[nikoyo-icons] Icon "${iconName}" not found`)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return renderAntdAstToSvg(icon.icon)
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
}),
|
|
154
|
-
// https://github.com/feat-agency/vite-plugin-webfont-dl
|
|
155
|
-
WebfontDownload(),
|
|
156
|
-
// https://github.com/nonzzz/vite-plugin-compression
|
|
157
|
-
compression(),
|
|
158
|
-
// https://github.com/vuejs/devtools
|
|
159
|
-
VueDevTools(),
|
|
160
|
-
// https://github.com/WJSoftware/vite-plugin-single-spa
|
|
161
|
-
VitePluginSingleSpa(singleSpaConfig),
|
|
162
|
-
],
|
|
163
|
-
build: {
|
|
164
|
-
rollupOptions: {
|
|
165
|
-
external: VITE_BUILD_EXTERNAL,
|
|
166
|
-
},
|
|
167
|
-
cssCodeSplit: true,
|
|
168
|
-
esbuild: isBuild
|
|
169
|
-
? { drop: ['console', 'debugger'] }
|
|
170
|
-
: {},
|
|
171
|
-
},
|
|
172
|
-
server: {
|
|
173
|
-
hmr: true,
|
|
174
|
-
host: true,
|
|
175
|
-
port,
|
|
176
|
-
proxy: {
|
|
177
|
-
'/svc': VITE_PROXY_HOST,
|
|
178
|
-
'/token': VITE_PROXY_HOST,
|
|
179
|
-
'/login': VITE_PROXY_HOST,
|
|
180
|
-
'/pub': VITE_PROXY_HOST,
|
|
181
|
-
},
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
userConfig,
|
|
185
|
-
)
|
|
186
|
-
})
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function kebabToPascalCase(str: string) {
|
|
190
|
-
return str
|
|
191
|
-
.split('-')
|
|
192
|
-
.map(s => s.charAt(0).toUpperCase() + s.slice(1))
|
|
193
|
-
.join('')
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function renderAntdAstToSvg(icon: any): string {
|
|
197
|
-
const { tag, attrs = {}, children = [] } = icon
|
|
198
|
-
|
|
199
|
-
return `
|
|
200
|
-
<svg
|
|
201
|
-
${renderAttrs({
|
|
202
|
-
...attrs,
|
|
203
|
-
fill: 'currentColor',
|
|
204
|
-
xmlns: 'http://www.w3.org/2000/svg',
|
|
205
|
-
})}
|
|
206
|
-
>
|
|
207
|
-
${children.map(renderNode).join('')}
|
|
208
|
-
</svg>
|
|
209
|
-
`
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function renderNode(node: any): string {
|
|
213
|
-
const { tag, attrs = {}, children = [] } = node
|
|
214
|
-
return `
|
|
215
|
-
<${tag} ${renderAttrs(attrs)}>
|
|
216
|
-
${children.map(renderNode).join('')}
|
|
217
|
-
</${tag}>
|
|
218
|
-
`
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function renderAttrs(attrs: Record<string, any>) {
|
|
222
|
-
return Object.entries(attrs)
|
|
223
|
-
.map(([k, v]) => `${k}="${v}"`)
|
|
224
|
-
.join(' ')
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
export { defineConfig }
|
package/tsconfig.json
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"composite": false,
|
|
4
|
-
"target": "ESNext",
|
|
5
|
-
|
|
6
|
-
"lib": ["ESNext"],
|
|
7
|
-
"moduleDetection": "force",
|
|
8
|
-
"experimentalDecorators": true,
|
|
9
|
-
|
|
10
|
-
"baseUrl": "./",
|
|
11
|
-
"module": "ESNext",
|
|
12
|
-
|
|
13
|
-
"moduleResolution": "bundler",
|
|
14
|
-
"resolveJsonModule": true,
|
|
15
|
-
|
|
16
|
-
"types": ["node"],
|
|
17
|
-
"strict": true,
|
|
18
|
-
"strictNullChecks": true,
|
|
19
|
-
"noFallthroughCasesInSwitch": true,
|
|
20
|
-
"noImplicitAny": true,
|
|
21
|
-
"noImplicitOverride": true,
|
|
22
|
-
"noImplicitThis": true,
|
|
23
|
-
"noUncheckedIndexedAccess": true,
|
|
24
|
-
"noUnusedLocals": true,
|
|
25
|
-
"noUnusedParameters": true,
|
|
26
|
-
|
|
27
|
-
"inlineSources": false,
|
|
28
|
-
"noEmit": true,
|
|
29
|
-
"removeComments": true,
|
|
30
|
-
"sourceMap": false,
|
|
31
|
-
"allowSyntheticDefaultImports": true,
|
|
32
|
-
"esModuleInterop": true,
|
|
33
|
-
"forceConsistentCasingInFileNames": true,
|
|
34
|
-
"isolatedModules": true,
|
|
35
|
-
"verbatimModuleSyntax": true,
|
|
36
|
-
"skipLibCheck": true,
|
|
37
|
-
"preserveWatchOutput": true,
|
|
38
|
-
"ignoreDeprecations": "6.0"
|
|
39
|
-
},
|
|
40
|
-
"include": ["src"],
|
|
41
|
-
"exclude": ["node_modules"]
|
|
42
|
-
}
|