You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Webpack动态导入:能否将chunks分发至不同子文件夹?

实现Webpack Chunks分发到不同子路径的方案

嘿,我之前刚好碰到过类似的需求,给你分享个亲测有效的方法——虽然不算常规操作,但借助绝对路径可以实现把Webpack的**chunks(注意不是输出bundles)**分发到不同子路径中:

const WEBPACK_CONFIG = {
  // 其他配置项...
  entry: {
    'open/js/testOpenEntryPoint': 'C:/.../example.loc/source/open/3_es6/testOpenEntryPoint',
    'admin/js/testAdminEntryPoint': 'C:/.../example.loc/source/admin/3_es6/testAdminEntryPoint'
  },
  output: {
    path: 'dest',
    filename: '[name].js',
    chunkFilename: '[name].js'
  }
}

简单说下逻辑:我们直接在entry的键名里定义了输出的子路径结构,Webpack会结合output.path指定的根目录,自动把对应的chunks输出到dest/open/js/和dest/admin/js/这类目标子路径下,刚好满足多路径分发的需求。

内容的提问来源于stack exchange,提问作者Takeshi Tokugawa YD

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:50:57