Versioning an Angular 2 App

旧街凉风 提交于 2019-12-05 02:47:11

问题


How can one mark versions of an Angular 2 app?

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>

Or app/v1/boot and playing with base but it's not working.

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,
})

So I have just to refresh the browser to see the changes. In production use either fileVersion = ''; or like export var fileVersion = '?tmplv=v3';.


回答1:


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:

First import the RuntimeCompiler.

import { RuntimeCompiler} from '@angular/compiler/src/runtime_compiler';

Next inject the RuntimeCompiler in your constructor.

constructor(private _runtimeCompiler: RuntimeCompiler) Finally use that to clear the cache. Note this clears all templates.

this._runtimeCompiler.clearCache();



来源:https://stackoverflow.com/questions/34967870/versioning-an-angular-2-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!