对 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();
这样的模块中引入一个全局变量来解决这个问题,并在像这样的组件中使用它:
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屋!