对Angular 2应用程序进行版本控制 [英] Versioning an Angular 2 App
问题描述
如何标记Angular 2应用程序的版本?
How can one mark versions of an Angular 2 app?
存在一些问题,例如视图(通过templateUrl
)在路线视图(子组件)中未得到更新.我已经尝试过类似的事情
There are some problems like views (via templateUrl
) are not getting updated in route views (child components). I've tried things like
<script>
System.config({
// baseURL: '/',
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('v1/app/boot')
.then(null, console.error.bind(console));
</script>
或者app/v1/boot
并与base
一起玩,但是它不起作用.
Or app/v1/boot
and playing with base
but it's not working.
注意:仅作记录,在开发时,缓存的模板(通过templateUrl
引入)会令人讨厌地变慢.人们应该使用隐身会话或清除浏览器等.我已经通过在export var fileVersion = '?tmplv=' + Date.now();
之类的模块中引入全局var并将其用于诸如以下的组件中来解决了此问题:
Note: Just for the record, at development time, cached templates (introduces via templateUrl
) do annoyingly slow things. One should use incognito sessions or clear up the browser and the like. I've solved this by introducing a global var in a module like export var fileVersion = '?tmplv=' + Date.now();
and use it in components like:
@Component({
selector: 'my-component',
templateUrl: '/app/templates/my-component.html' + fileVersion,
})
因此,我只需要刷新浏览器即可查看更改.在生产中,使用fileVersion = '';
或类似export var fileVersion = '?tmplv=v3';
.
So I have just to refresh the browser to see the changes. In production use either fileVersion = '';
or like export var fileVersion = '?tmplv=v3';
.
推荐答案
我正在处理同一问题. 我正在寻找类似filerev Node包的东西. 现在,我的解决方案是使用angular 2清除缓存:
I am dealing with the same issue. I am looking for something like filerev Node package. For now, my solution is to use angular 2 to clear the cache:
首先导入RuntimeCompiler.
First import the RuntimeCompiler.
import { RuntimeCompiler} from '@angular/compiler/src/runtime_compiler';
接下来将RuntimeCompiler注入您的构造函数中.
Next inject the RuntimeCompiler in your constructor.
constructor(private _runtimeCompiler: RuntimeCompiler)
最后使用它来清除缓存.请注意,这将清除所有模板.
constructor(private _runtimeCompiler: RuntimeCompiler)
Finally use that to clear the cache. Note this clears all templates.
this._runtimeCompiler.clearCache();
这篇关于对Angular 2应用程序进行版本控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!