Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
najiu-admin-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
najiu-frontend
najiu-admin-template
Commits
b476e1c8
Commit
b476e1c8
authored
Mar 01, 2021
by
Vben
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: ensure that the correct components are dynamically imported
parent
3b8ca420
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
32 additions
and
5 deletions
+32
-5
.env
.env
+3
-0
utils.ts
build/utils.ts
+1
-0
routeHelper.ts
src/router/helper/routeHelper.ts
+17
-3
projectSetting.ts
src/settings/projectSetting.ts
+1
-1
window.d.ts
types/window.d.ts
+1
-0
vite.config.ts
vite.config.ts
+9
-1
No files found.
.env
View file @
b476e1c8
...
@@ -6,3 +6,6 @@ VITE_GLOB_APP_TITLE = Vben Admin
...
@@ -6,3 +6,6 @@ VITE_GLOB_APP_TITLE = Vben Admin
# spa shortname
# spa shortname
VITE_GLOB_APP_SHORT_NAME = vue_vben_admin
VITE_GLOB_APP_SHORT_NAME = vue_vben_admin
VITE_DYNAMIC_IMPORT = false
build/utils.ts
View file @
b476e1c8
...
@@ -30,6 +30,7 @@ export interface ViteEnv {
...
@@ -30,6 +30,7 @@ export interface ViteEnv {
VITE_BUILD_COMPRESS
:
'
gzip
'
|
'
brotli
'
|
'
none
'
;
VITE_BUILD_COMPRESS
:
'
gzip
'
|
'
brotli
'
|
'
none
'
;
VITE_LEGACY
:
boolean
;
VITE_LEGACY
:
boolean
;
VITE_USE_IMAGEMIN
:
boolean
;
VITE_USE_IMAGEMIN
:
boolean
;
VITE_DYNAMIC_IMPORT
:
boolean
;
}
}
// Read all environment variable configuration files to process.env
// Read all environment variable configuration files to process.env
...
...
src/router/helper/routeHelper.ts
View file @
b476e1c8
...
@@ -9,10 +9,22 @@ export type LayoutMapKey = 'LAYOUT';
...
@@ -9,10 +9,22 @@ export type LayoutMapKey = 'LAYOUT';
const
LayoutMap
=
new
Map
<
LayoutMapKey
,
()
=>
Promise
<
typeof
import
(
'
*.vue
'
)
>>
();
const
LayoutMap
=
new
Map
<
LayoutMapKey
,
()
=>
Promise
<
typeof
import
(
'
*.vue
'
)
>>
();
const
dynamicViewsModules
=
import
.
meta
.
glob
(
'
../../views/**/*.{vue,tsx}
'
);
let
dynamicViewsModules
:
Record
<
string
,
()
=>
Promise
<
{
[
key
:
string
]:
any
;
}
>
>
;
// 动态引入
// 动态引入
function
asyncImportRoute
(
routes
:
AppRouteRecordRaw
[]
|
undefined
)
{
function
asyncImportRoute
(
routes
:
AppRouteRecordRaw
[]
|
undefined
)
{
// TODO It may be a bug in Vite. When the conditions are not established, the dynamically imported files will still be packaged in.
if
(
!
__DYNAMIC_IMPORT__
)
{
dynamicViewsModules
=
{};
}
else
{
dynamicViewsModules
=
dynamicViewsModules
||
import
.
meta
.
glob
(
'
../../views/**/*.{vue,tsx}
'
);
}
if
(
!
routes
)
return
;
if
(
!
routes
)
return
;
routes
.
forEach
((
item
)
=>
{
routes
.
forEach
((
item
)
=>
{
const
{
component
,
name
}
=
item
;
const
{
component
,
name
}
=
item
;
...
@@ -37,8 +49,10 @@ function dynamicImport(
...
@@ -37,8 +49,10 @@ function dynamicImport(
)
{
)
{
const
keys
=
Object
.
keys
(
dynamicViewsModules
);
const
keys
=
Object
.
keys
(
dynamicViewsModules
);
const
matchKeys
=
keys
.
filter
((
key
)
=>
{
const
matchKeys
=
keys
.
filter
((
key
)
=>
{
const
k
=
key
.
replace
(
'
../../views
'
,
''
);
let
k
=
key
.
replace
(
'
../../views
'
,
''
);
return
k
.
startsWith
(
`
${
component
}
`
)
||
k
.
startsWith
(
`/
${
component
}
`
);
const
lastIndex
=
k
.
lastIndexOf
(
'
.
'
);
k
=
k
.
substring
(
0
,
lastIndex
);
return
k
===
component
;
});
});
if
(
matchKeys
?.
length
===
1
)
{
if
(
matchKeys
?.
length
===
1
)
{
const
matchKey
=
matchKeys
[
0
];
const
matchKey
=
matchKeys
[
0
];
...
...
src/settings/projectSetting.ts
View file @
b476e1c8
...
@@ -19,7 +19,7 @@ const setting: ProjectConfig = {
...
@@ -19,7 +19,7 @@ const setting: ProjectConfig = {
settingButtonPosition
:
SettingButtonPositionEnum
.
AUTO
,
settingButtonPosition
:
SettingButtonPositionEnum
.
AUTO
,
// Permission mode
// Permission mode
permissionMode
:
PermissionModeEnum
.
ROLE
,
permissionMode
:
PermissionModeEnum
.
BACK
,
// Permission-related cache is stored in sessionStorage or localStorage
// Permission-related cache is stored in sessionStorage or localStorage
permissionCacheType
:
CacheTypeEnum
.
SESSION
,
permissionCacheType
:
CacheTypeEnum
.
SESSION
,
...
...
types/window.d.ts
View file @
b476e1c8
import
type
{
App
}
from
'
vue
'
;
import
type
{
App
}
from
'
vue
'
;
declare
global
{
declare
global
{
declare
const
__DYNAMIC_IMPORT__
:
boolean
;
declare
interface
Window
{
declare
interface
Window
{
// Global vue app instance
// Global vue app instance
__APP__
:
App
<
Element
>
;
__APP__
:
App
<
Element
>
;
...
...
vite.config.ts
View file @
b476e1c8
...
@@ -21,7 +21,14 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
...
@@ -21,7 +21,14 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
// The boolean type read by loadEnv is a string. This function can be converted to boolean type
// The boolean type read by loadEnv is a string. This function can be converted to boolean type
const
viteEnv
=
wrapperEnv
(
env
);
const
viteEnv
=
wrapperEnv
(
env
);
const
{
VITE_PORT
,
VITE_PUBLIC_PATH
,
VITE_PROXY
,
VITE_DROP_CONSOLE
,
VITE_LEGACY
}
=
viteEnv
;
const
{
VITE_PORT
,
VITE_PUBLIC_PATH
,
VITE_PROXY
,
VITE_DROP_CONSOLE
,
VITE_LEGACY
,
VITE_DYNAMIC_IMPORT
,
}
=
viteEnv
;
const
isBuild
=
command
===
'
build
'
;
const
isBuild
=
command
===
'
build
'
;
...
@@ -68,6 +75,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
...
@@ -68,6 +75,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
define
:
{
define
:
{
// setting vue-i18-next
// setting vue-i18-next
// Suppress warning
// Suppress warning
__DYNAMIC_IMPORT__
:
VITE_DYNAMIC_IMPORT
,
__VUE_I18N_LEGACY_API__
:
false
,
__VUE_I18N_LEGACY_API__
:
false
,
__VUE_I18N_FULL_INSTALL__
:
false
,
__VUE_I18N_FULL_INSTALL__
:
false
,
__INTLIFY_PROD_DEVTOOLS__
:
false
,
__INTLIFY_PROD_DEVTOOLS__
:
false
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment