-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
icejs x vite mode support custom chunkName #4818
Comments
vite 模式下生成 chunkName 主要包括以下两个问题:
css 在 rollup 中属于 assets 如需定制名称可以通过 导致上述原因的一些讨论: 代码层面无法直接通过 generateBundle 分析出主要 css bundle 的原因: https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/css.ts#L489-L505 在 vite 工程内部对 bundle 的信息进行了过滤,并通过 对于后端输出的资源地址,vite 官方推荐结合 manifest 进行输出确定 index 和 css 的地址 https://vitejs.dev/guide/backend-integration.html#backend-integration <!-- if production -->
<link rel="stylesheet" href="/assets/{{ manifest['main.js'].css }}" />
<script type="module" src="/assets/{{ manifest['main.js'].file }}"></script> 解决方案问题一:定制 chunkName如果上图所示 chunkFileNames 中的信息包含 facadeModuleId 和 isDynamicEntry 字段,开发者可以定制相应的方法实现自定义 bundle 的诉求。
问题二:无法确定主 css 地址通过 manifest 中的信息获取主 css 地址,manifest 信息无法直接通过 generateBundle 获取,可以通过劫持其执行的逻辑获取到 manifest 信息: {
buildStart({ plugins }) {
viteManifest = plugins.find(
({ name }) => name === 'vite:manifest',
);
},
generateBundle: async (options, bundle, isWrite) => {
// 记录 manifest 信息
let filesData;
await viteManifest.generateBundle.call(
{
...this,
emitFile: (file) => {
if (file.type === 'chunk') return 'chunk id'
filesData = JSON.parse(file.source as string)
return 'asset id'
},
},
options,
bundle,
isWrite,
)
},
} 默认情况下主 css 地址会直接输出到 html 页面中,不依赖 js 动态进行挂载,因此在确定主 css 资源内容后,生成一个指定的文件即可(比如默认以 index-main.css 命名) |
问一下问题2的解决方案能使用了吗? |
已支持配置 cssChunkNames |
What is the current behavior? 发生了什么?
vitejs/vite#745 (comment)
What is the expected behavior? 期望的结果是什么?
Any additional comments? 相关环境信息?
The text was updated successfully, but these errors were encountered: