简体   繁体   English

Browserify捆绑包

[英]Browserify bundles

Every time we release a new version of our software which is bundled using Browserify, we are finding that we need to ask our users to clear their cache using the regular methods of CTRL+F5 or diving into the browser settings. 每次发布与Browserify捆绑在一起的软件的新版本时,我们都发现我们需要要求用户使用常规CTRL + F5方法清除其缓存或进入浏览器设置。 It is not ideal when there are a thousand or so users. 当有一千个左右的用户时,这是不理想的。 We are trying to work out a way that we can perhaps get around this. 我们正在设法找到一种可能解决这个问题的方法。 I am open to all sorts of options. 我愿意接受各种选择。

Our project is ReactJS based, so runs in the browser and connects to back end services via a RESTful API. 我们的项目基于ReactJS,因此在浏览器中运行,并通过RESTful API连接到后端服务。 We do track which version is loaded and this is visible from within the console. 我们确实跟踪加载了哪个版本,这在控制台中可见。 Using the version number we can compare on two different machines that one user is running the latest version whereas someone else may not be. 使用版本号,我们可以在两台不同的计算机上比较一个用户正在运行最新版本,而其他用户可能没有。

The code is bundled into two separate files and I feel that this is where we should be looking. 该代码捆绑在两个单独的文件中,我认为这是我们应该寻找的地方。

You need to change the file name on each new release. 您需要在每个新发行版中更改文件名。 A hash of the file is an appropriate thing you could add. 您可以添加文件的哈希值。

Check out md5ify to add this to your project build. md5ify将此添加到您的项目版本。

If you implement this yourself, make sure to also load the correct filename in your index.html file. 如果您自己实施此操作,请确保也将正确的文件名加载到index.html文件中。

Edit: 编辑:

To automatically load the correct file you need to have a placeholder in your main html. 要自动加载正确的文件,您需要在主html中有一个占位符。

Then you need a manifest.json file that looks like following: 然后,您需要一个manifest.json如下的manifest.json文件:

{
 "main.js": "main.[HASH].js"
}

This has to be created automatically after the bundling. 捆绑后必须自动创建它。 Now you can replace the placeholder with correct asset by doing a lookup in the manifest file. 现在,您可以通过在manifest文件中进行查找,将占位符替换为正确的资产。

You either have to write your own scripts for this or use something like gulp together with browserify . 您要么为此编写自己的脚本,要么将gulpbrowserify一起使用。

Another solution would be webpack 另一个解决方案是webpack

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM