Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

打包报dynamic import will not move module into another chunk #82

Closed
SyanH opened this issue Mar 30, 2024 · 2 comments
Closed

打包报dynamic import will not move module into another chunk #82

SyanH opened this issue Mar 30, 2024 · 2 comments

Comments

@SyanH
Copy link

SyanH commented Mar 30, 2024

打包有警告,看着挺闹心, 搜了下,也没找到原因,麻烦指点迷津~

[plugin:vite:reporter] 
(!) /Users/syan/FrondEnd/elseshop-vue/src/config/index.js is dynamically imported by /Users/syan/FrondEnd/elseshop-vue/src/pluginLoader.js but also statically imported by /Users/syan/FrondEnd/elseshop-vue/src/layout/index.vue, /Users/syan/FrondEnd/elseshop-vue/src/router/index.js, /Users/syan/FrondEnd/elseshop-vue/src/utils/request.js, /Users/syan/FrondEnd/elseshop-vue/src/utils/tool.js, dynamic import will not move module into another chunk.

[plugin:vite:reporter] 
(!) /Users/syan/FrondEnd/elseshop-vue/src/utils/tool.js is dynamically imported by /Users/syan/FrondEnd/elseshop-vue/src/pluginLoader.js but also statically imported by /Users/syan/FrondEnd/elseshop-vue/src/components/editor/Index.vue, /Users/syan/FrondEnd/elseshop-vue/src/components/tabs/Index.vue, /Users/syan/FrondEnd/elseshop-vue/src/layout/SearchMenu.vue, /Users/syan/FrondEnd/elseshop-vue/src/layout/index.vue, /Users/syan/FrondEnd/elseshop-vue/src/router/dynamic.js, /Users/syan/FrondEnd/elseshop-vue/src/router/index.js, /Users/syan/FrondEnd/elseshop-vue/src/utils/request.js, /Users/syan/FrondEnd/elseshop-vue/src/views/login/Index.vue, dynamic import will not move module into another chunk.

[plugin:vite:reporter] 
(!) /Users/syan/FrondEnd/elseshop-vue/src/router/pluginViews.js is dynamically imported by /Users/syan/FrondEnd/elseshop-vue/src/pluginLoader.js but also statically imported by /Users/syan/FrondEnd/elseshop-vue/src/router/dynamic.js, dynamic import will not move module into another chunk.

pluginLoader.js

import { initMiniStar, regDependency, regSharedModule } from 'mini-star'

export function initPlugins() {
	regDependency('vue', () => import('vue'))

	regSharedModule(
		'@capital/config',
		() => import('@/config')
	)

	regSharedModule(
		'@capital/utils/request',
		() => import('@/utils/request')
	)

  regSharedModule(
		'@capital/utils/tool',
		() => import('@/utils/tool')
	)

  regSharedModule(
		'@capital/pluginViews',
		() => import('@/router/pluginViews')
	)

  regSharedModule(
		'@capital/editor',
		() => import('@/components/Editor/Index.vue')
	)

	return initMiniStar({
		plugins: ['test'].map((plugin) => ({
			name: plugin,
			url: `/plugins/${plugin}/index.js`
		}))
	})
}

main.js

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import elseshop from './elseshop'
import 'element-plus/dist/index.css'
import 'element-plus/theme-chalk/display.css'
import 'element-plus/theme-chalk/dark/css-vars.css'
import './assets/css/main.css'
import './assets/css/toastui-editor.css'
import './assets/css/toastui-editor-dark.css'
import '@toast-ui/editor/dist/i18n/zh-cn'
import { initPlugins } from './pluginLoader'

initPlugins().finally(() => {
  const app = createApp(App)
  app.use(createPinia())
  app.use(router)
  app.use(ElementPlus)
  app.use(elseshop)

  app.mount('#app')
})
@moonrailgun
Copy link
Owner

I this this warning just tell you your dynamic import is invalid.
I think you can safe ignore it. or change those package to direct import

from:

regSharedModule(
  '@capital/utils/tool',
  () => import('@/utils/tool')
)

to:

import * as tools from '@/utils/tool'

regSharedModule(
  '@capital/utils/tool',
  () => tools 
)

@SyanH
Copy link
Author

SyanH commented Mar 30, 2024

果然有效,感谢!


It really works, thank you!

@SyanH SyanH closed this as completed Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants