每次我在共享文件夹中生成内容时,都会重建index.ts文件,并按字母顺序放置导出.这似乎打破了我的依赖.手动更改顺序,以便在具有依赖项的类之前导出依赖项使其再次起作用.
如果我们有app/shared/auth.guard.ts:
import { Injectable } from '@angular/core';
import { CanActivate, Router, ActivatedRouteSnapshot } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import { AuthService, User } from './';
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private accountService: AuthService, private router: Router) { }
canActivate(next: ActivatedRouteSnapshot): Observable<boolean> {
let result = this.accountService.currentUser.first().map(user => user != null);
let route: any[] = ['/login'];
if (next.url.length) {
route.push({ redirectUrl: next.url });
}
result.subscribe(isLoggedIn => {
if (!isLoggedIn) {
this.router.navigate(route);
}
}); …Run Code Online (Sandbox Code Playgroud) angular-cli beta.16,使用webpack.使用CLI创建的项目
嗨,
这是我的项目结构:
- server
- server.js
- src
- app
- compoents & co
- assets
- index.html
我正在使用server.js来处理来自我的一个角度组件的上传请求.文件已上传,我想把它放在assets目录中,所以我可以在应用程序之后使用它.
问题是,当我做这样的工作(在资源文件夹中上传文件)使我的angular-cli重新构建整个应用程序(因为它检测到我的文件中的更改),所以应用程序在浏览器中重新加载,我不能用它.
有没有办法为CLI的"watch build"任务排除某些文件夹(对我来说是'assets'文件夹)?所以当我将新文件放入其中时,CLI不会再次构建应用程序?
感谢你们 !
我正在运行以下命令进行单元测试并生成代码覆盖率报告.
ng test --code-coverage
Run Code Online (Sandbox Code Playgroud)
它在coverage文件夹中编写代码覆盖率报告.
我需要查看整个项目的覆盖范围,而不仅仅是有测试的文件.
karma.conf.js
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', 'angular-cli'],
plugins: [
require('karma-jasmine'),
require('karma-jasmine-html-reporter'),
require('karma-chrome-launcher'),
require('karma-remap-istanbul'),
require('angular-cli/plugins/karma'),
require('karma-coverage'),
require('karma-sourcemap-loader')
],
files: [
{ pattern: './src/test.ts', watched: false }
],
preprocessors: {
'./src/test.ts': ['angular-cli']
},
mime: {
'text/x-typescript': ['ts','tsx']
},
remapIstanbulReporter: {
reports: {
html: 'coverage',
lcovonly: './coverage/coverage.lcov'
}
},
angularCli: {
config: './angular-cli.json',
environment: 'dev'
},
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'karma-remap-istanbul']
: ['progress', 'kjhtml'],
coverageReporter: {
includeAllSources: true
},
port: …Run Code Online (Sandbox Code Playgroud) 我认为在Angular-cli树抖动中排除组件的问题非常相似,但我似乎无法从中得到任何东西.
基本上我有一个动态组件工厂,如我如何使用/创建动态模板来编译动态组件与Angular 2.0?.
当我使用最新的Angular CLI和非生产设置构建它时,一切正常.但是,一旦我使用生产设置,我在尝试加载具有动态创建内容的页面时立即在浏览器中获得以下错误跟踪:
例外:找不到'e'的NgModule元数据.
ORIGINAL STACKTRACE:
main.dc05ae9 ... .bundle.js:格式:4731
错误:找不到'e'的NgModule元数据.
at t(vendor.c18e6df ... .bundle.js:格式化:76051)
at t.resolve(vendor.c18e6df ... .bundle.js:格式化:20624)
at t.getNgModuleMetadata(vendor.c18e6df ... .bundle.js:formatted: 20169)
在t._compileModuleAndAllComponents(vendor.c18e6df ... .bundle.js:格式化:40462)的t._loadModules(vendor.c18e6df ... .bundle.js:格式化:40474
)
at t.compileModuleAndAllComponentsSync(vendor.c18e6df ... .bundle. js:格式化:40436)
在e.createComponentFactory(main.dc05ae9 ... .bundle.js:格式:4789)
这是我的组件工厂类:
@Injectable()
export class DynamicTypeBuilder {
constructor() {
}
private _cacheOfFactories: {[templateKey: string]: ComponentFactory<any>} = {};
private compiler: Compiler = new JitCompilerFactory([{useDebug: false, useJit: true}]).createCompiler();
public createComponentFactory<COMPONENT_TYPE>(type: any, template: string, additionalModules: any[] = []): Observable<ComponentFactory<COMPONENT_TYPE>> {
let …Run Code Online (Sandbox Code Playgroud) 我是Angular 5项目的新手.我跑去ng build --prod生成一个dist/文件夹.
我注意到构建需要相当长的时间,当我打开我的dist/文件夹时,我看到它有近98%无用的东西,比如SVG,图像等等.
我如何控制进入我的内容dist/?
.angular-cli.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "web"
},
"apps": [{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.css",
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"../node_modules/ngx-toastr/toastr.css",
"../src/assets/css/style.css",
"../src/assets/css/colors/blue.css"
],
"scripts": [
"../node_modules/jquery/dist/jquery.min.js",
"../node_modules/popper.js/dist/umd/popper.min.js",
"../node_modules/bootstrap/dist/js/bootstrap.min.js",
"../node_modules/jquery-slimscroll/jquery.slimscroll.min.js",
"../node_modules/pace-js/pace.min.js"
],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}],
"e2e": {
"protractor": {
"config": "./protractor.conf.js" …Run Code Online (Sandbox Code Playgroud) 我的Angular项目是@ Angular4.3.3
ng build -prod
制作构建需要77秒
ng build --prod --build-optimizer = true
制作构建需要190秒,没有供应商块,尺寸较小(但是尺寸差别不大)
我读过Bundling&Tree-Shaking但是仍然没有得到这些命令创建的构建之间的明显区别.
为什么有这两种不同的方式,性能或其他方式有何不同?
我使用Visual Studio 2017构建了一个Angular-CLI .Net Core SPA
dotnet new angular -o my-new-app
Run Code Online (Sandbox Code Playgroud)
我正在努力寻找的是在写入时默认调用文件夹index.html内部的内容ClientApp/src
http://localhost:57782
Run Code Online (Sandbox Code Playgroud)
startup.cs文件如下:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SpaServices.AngularCli;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace angular_cli
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
//services.AddMvc();
// In production, the Angular files will be …Run Code Online (Sandbox Code Playgroud) 我正在转换库(ng-app-state)以使用angular cli,现在v6支持库(yay!).
尝试运行某些CLI命令时,它会失败,并显示如下错误:
$ ng test --source-map ng-app-state
Architect commands with multiple targets cannot specify overrides.'test' would be run on the following projects: ng-app-state-monorepo,ng-app-state
Error: Architect commands with multiple targets cannot specify overrides.'test' would be run on the following projects: ng-app-state-monorepo,ng-app-state
at TestCommand.validate (S:\Programming\git repositories\ng-app-state-monorepo\node_modules\@angular\cli\models\architect-command.js:91:23)
Run Code Online (Sandbox Code Playgroud) 我正在研究一个项目,将其更新为Angular 6.更新后,我在尝试运行服务器端渲染构建时遇到此错误
Module not found: Error: Can't resolve './dist/server/main.bundle'
Run Code Online (Sandbox Code Playgroud)
我尝试访问https://angular.io/guide/universal并将我的代码与Angular Universal中的SSR文件进行匹配.这不适合我.
似乎dist文件夹没有生成/ server文件夹,但正在创建/浏览器.我不确定为什么.
这是我的angular.json文件
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"xilo": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/browser",
"index": "src/index.html",
"main": "src/main.ts",
"tsConfig": "src/tsconfig.app.json",
"polyfills": "src/polyfills.ts",
"assets": [
"src/assets",
"src/favicon.ico"
],
"styles": [
"src/styles.css",
"node_modules/font-awesome/css/font-awesome.min.css"
],
"scripts": [
"node_modules/moment/min/moment.min.js"
]
},
"configurations": {
"production": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false, …Run Code Online (Sandbox Code Playgroud) 当我尝试使用gitlab CI / CD构建和部署项目时,Angluar CLI会问以下问题:
> @angular/cli@8.0.0 postinstall /workspace/node_modules/@angular/cli
> node ./bin/postinstall/script.js
? Would you like to share anonymous usage data with the Angular Team at Google u
nder
Google’s Privacy Policy at https://policies.google.com/privacy? For more details
and
how to change this setting, see http://angular.io/analytics. (y/N) Run Code Online (Sandbox Code Playgroud)
当然,我无法在CI / CD管道中输入任何内容。我怎样才能防止角度倾斜问这个问题?
angular-cli ×10
angular ×8
javascript ×2
webpack ×2
angular5 ×1
asp.net ×1
asp.net-core ×1
asp.net-mvc ×1
build ×1
jasmine ×1
server-side ×1
tree-shaking ×1
typescript ×1