webpack 共用文件抽离?

发布于 2022-09-04 12:11:49 字数 2201 浏览 17 评论 0

先声明
不要给我贴什么官方文档和demo。

问题
1、比如我使用vue-resource进行ajax请求。(当然我还用了很多第三方的插件)。但是问题是我基于vue-resource对ajax进行了业务层的封装。(当然还有其他自行封装的业务模块)。
2、然后是我使用webpack打包。可以抽离vue-resource等第三方插件(在入口app.js中引用)。问题是具体的页面使用封装的组件时是通过import moduleObj from module。这样导致每个页面js中都含有module.js。

备注:我使用了路由懒加载。所以每个页面都会产生一个chunk.js文件。现在打包之后chunk.js文件中包含有很多共用的业务模块代码。

{
  name: string, // or
  names: string[],
  // The chunk name of the commons chunk. An existing chunk can be selected by passing a name of an existing chunk.
  // If an array of strings is passed this is equal to invoking the plugin multiple times for each chunk name.
  // If omitted and `options.async` or `options.children` is set all chunks are used,
  // otherwise `options.filename` is used as chunk name.

  filename: string,
  // The filename template for the commons chunk. Can contain the same placeholder as `output.filename`.
  // If omitted the original filename is not modified (usually `output.filename` or `output.chunkFilename`).

  minChunks: number|Infinity|function(module, count) -> boolean,
  // The minimum number of chunks which need to contain a module before it's moved into the commons chunk.
  // The number must be greater than or equal 2 and lower than or equal to the number of chunks.
  // Passing `Infinity` just creates the commons chunk, but moves no modules into it.
  // By providing a `function` you can add custom logic. (Defaults to the number of chunks)

  chunks: string[],
  // Select the source chunks by chunk names. The chunk must be a child of the commons chunk.
  // If omitted all entry chunks are selected.

  children: boolean,
  // If `true` all children of the commons chunk are selected

  async: boolean|string,
  // If `true` a new async commons chunk is created as child of `options.name` and sibling of `options.chunks`.
  // It is loaded in parallel with `options.chunks`. It is possible to change the name of the output file
  // by providing the desired string instead of `true`.

  minSize: number,
  // Minimum size of all common module before a commons chunk is created.
}
 The deprecated webpack 1 constructor

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文