在 webpack 中包含一个大的生成文件 [英] Include a big generated file in webpack

查看:28
本文介绍了在 webpack 中包含一个大的生成文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试 Webpack 功能并且有一个我不知道如何处理的有趣用例.也就是说,我有:

I'm testing Webpack capabilities and have a funny use case that I don't know how to handle. Namely, I've got:

  1. File A.js:一个使用 Webpack 导入并定义了很多变量和实用函数的 JS 模块.
  2. File B.js:从另一种编程语言生成的大(> 10mb)JS文件,它应该使用A.js中定义的变量和函数,但是,它不是 Webpack 模块,也不使用 Webpack 导入.
  1. File A.js: a JS module that uses Webpack imports and defines a lot of variables and utility functions.
  2. File B.js: a big (>10mb) JS file generated from another programming language, which is supposed to use variables and functions defined in A.js, however, it is not a Webpack module and does not use Webpack imports.

现在我想在一个环境中同时使用它们,但是:

Now I want to use both them in a single environment, but:

  1. 我不想将它们编译成单个文件(它花费的时间太长,而且显然没有必要).我很想从 A.js(以及 A 使用的其他本​​地 JS 文件)生成包,并且只想使用 B.js 而无需进行不必要的转换.
  2. 我不希望 Webpack 甚至解析 B.js 以寻找导入等以最小化构建时间.我只是想告诉Webpack,B.js应该可以访问A.js的范围.

有可能吗?:)

推荐答案

如果你在 webpack 旁边已经有任何额外的构建工具,我建议让该构建/组装工具处理 B.js并将其保留在 webpack 捆绑之外.这样 webpack 甚至不知道有 B.js.这也意味着 webpack 不会处理那个大的 B.js.

If you already have any additional build tool along side webpack, i would suggest to let that build/assembly tool handle B.js and keep it outside webpack bundling. This way webpack doesnt even know there is B.js. It also means no processing on that big B.js by webpack.

如果不是这样(即只有 webpack 到位),那么我建议使用 脚本加载器.然而,这意味着 webpack 会打包整个 B.js.使用 webpack 预计这里的速度会很慢.

If thats not the case (i.e. only webpack is in place) then i would suggest to use script-loader. However, this would mean webpack will make a bundle of that entire B.js. Expect things to be slow here with webpack.

在我的 Mac 上,使用 脚本加载器.没有大 js 文件需要 100 毫秒.

On my mac, webpack takes 2+ seconds for a 17 MB js file with script-loader. Without the big js file it takes 100 ms.

这篇关于在 webpack 中包含一个大的生成文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆