标签: angular-cli

如何在angular-cli中生成dist文件夹中的延迟加载组件?

我angular-cli用于开发,我使用以下命令和代码来构建我的项目.

npm install angular-cli (angular-cli:1.0.0-beta.10)

ng new my-app

ng g component lazy-me

然后添加一个app.router.ts包含以下脚本的文件

import { provideRouter, RouterConfig } from '@angular/router';
import { AppComponent } from './app.component';
// import { LazyMeComponent } from './+lazy-me/lazy-me.component';

const appRoutes : RouterConfig = [
  {path: '', component: AppComponent},
//   {path: 'lazyme', component: LazyMeComponent}
  {path: 'lazyme', component: 'app/+lazy-me#LazyMeComponent'}
];

export const APP_ROUTER_PROVIDER = [
    provideRouter(appRoutes)
];
Run Code Online (Sandbox Code Playgroud)

并改变了我的主要内容如下

import { bootstrap } from '@angular/platform-browser-dynamic';
import { enableProdMode,
    SystemJsComponentResolver, 
    ComponentResolver } from '@angular/core';
import …
Run Code Online (Sandbox Code Playgroud)

systemjs angular-cli angular

14
推荐指数
1
解决办法
694
查看次数

ctorParameters.map不是angular2-mdl中的函数

我正在尝试使用angular2-mdl和angular-cli.我MdlModule在app.module.ts中导入.

当我尝试使用时<mdl-textfield type="text" label="Text..." floating-label></mdl-textfield>,它会出错:

ctorParameters.map不是angular2-mdl中的函数

我不知道该怎么做.

这是我的angular-cli.json.

  "dependencies": {
    "@angular/common": "~2.0.0",
    "@angular/compiler": "~2.0.0",
    "@angular/core": "~2.0.0",
    "@angular/forms": "~2.0.0",
    "@angular/http": "~2.0.0",
    "@angular/material": "^2.0.0-alpha.9-3",
    "@angular/platform-browser": "~2.0.0",
    "@angular/platform-browser-dynamic": "~2.0.0",
    "@angular/router": "~3.0.0",
    "@types/moment-timezone": "^0.2.33",
    "angular-cli": "^1.0.0-beta.17",
    "angular2-jwt": "^0.1.25",
    "angular2-mdl": "^2.9.0",
    "bootstrap": "^3.3.7",
    "bourbon": "^4.2.7",
    "core-js": "^2.4.1",
    "font-awesome": "^4.7.0",
    "hammerjs": "^2.0.8",
    "moment": "^2.17.1",
    "moment-timezone": "^0.5.10",
    "node-sass": "^3.13.0",
    "primeng": "^1.1.0",
    "rxjs": "5.0.0-beta.12",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.6.23"
  },
  "devDependencies": {
    "@types/jasmine": "^2.2.30",
    "@types/moment": "^2.13.0",
    "@types/moment-timezone": "^0.2.33",
    "@types/node": "^6.0.42",
    "angular-cli": "1.0.0-beta.17",
    "bootstrap-sass": "^3.3.7",
    "codelyzer": …
Run Code Online (Sandbox Code Playgroud)

angular-cli angular2-mdl angular

14
推荐指数
2
解决办法
1万
查看次数

在angular-cli中使用的.map文件是什么,并且可以构建不创建这些文件?

ng build of angular-cli创建3个文件:

inline.bundle.js
vendor.bundle.js
main.bundle.js
Run Code Online (Sandbox Code Playgroud)

以及每个人自己的地图文件.做什么的?

我也问是否有办法改变这种行为,不是创建这3个文件而是复制到dist目录中的所有js文件,而不是捆绑任何东西.那可能吗?

angular-cli angular

14
推荐指数
2
解决办法
1万
查看次数

如何在Jenkins构建批处理命令中在Windows Server上使用angular cli

在安装Jenkins之前我运行了这个: npm install -g @ angular/cli

但我也在package.json中的devDependencies中为项目提供了这个:

"@ angular/cli":"1.0.0-beta.32.3",


在运行Jenkins构建时,我在日志中收到此消息:

'ng'不被识别为内部或外部命令,可操作程序或批处理文件.

=======================================

这是Jenkins中的Windows批处理命令:

cmd/c调用npm install

设置路径=%WORKSPACE%\node_modules\@angular\cli\bin;%PATH%

echo%PATH%

ng build -prod

========================================

这是Jenkins的更多日志输出:

C:\ Program Files(x86)\ Jenkins\workspace\UiUnitTests> ng build -prod

'ng'不被识别为内部或外部命令,可操作程序或批处理文件.

C:\ Program Files(x86)\ Jenkins\workspace\UiUnitTests>退出9009构建步骤'执行Windows批处理命令'将构建标记为失败


但是当我从命令行运行时(不是在Jenkins工作中),这很好用:

C:\ Program Files(x86)\ Jenkins\workspace\UiUnitTests> ng build -prod

您的全局Angular CLI版本(1.0.0-rc.1)大于您的本地版本

版本(1.0.0-beta.32.3).使用本地Angular CLI版本.

要禁用此警告,请使用"ng set --global warnings.versionMismatch = false".哈希:7853ecb5a81a25eadbeb时间:61317ms chunk {0} polyfills.7aaf5284cd5921eea40b.bundle.js(polyfills)278 kB {4} [initial] [rendered] chunk {1} main.3380f71d3e71966aea27.bundle.js(main)371 kB {3} [initial] [rendered] chunk {2} styles.9db1bafdfc989b37db97.bundle.css(styles)69 bytes {4} [initial] [rendered] chunk {3} vendor.24574fc8320129058fac.bundle.js(vendor)2.18 MB [initial] [rendering] …

windows path batch-file jenkins angular-cli

14
推荐指数
1
解决办法
9957
查看次数

如何将sass-lint添加到angular-cli.json文件中?

我正在使用这个种子应用程序:https://github.com/2sic/app-tutorial-angular4-hello-dnn

我已经安装了sass-lint:https://www.npmjs.com/package/sass-lint

但不知道如何将其添加到我的angular-cli.json文件中.

我一直在使用的角度版本4,的WebPack,以打字稿和青菜的这个例子.

我已经使用默认设置向我的root添加了"sass-lint.yml"文件.

这是我的angular-cli.json文件:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "my-app"
  },
  "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.scss"
      ],
      "scripts": [
        "../node_modules/lodash/lodash.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)

sass webpack angular-cli sass-lint angular

14
推荐指数
1
解决办法
4623
查看次数

找不到Angular4.x模块:错误:无法解析'classlist.js'

当我删除polyfills.ts中的注释部分以便在Internet Explorer中加载页面时填充页面

/** IE9, IE10 and IE11 requires all of the following polyfills. **/
 import 'core-js/es6/symbol';
 import 'core-js/es6/object';
 import 'core-js/es6/function';
 import 'core-js/es6/parse-int';
 import 'core-js/es6/parse-float';
 import 'core-js/es6/number';
 import 'core-js/es6/math';
 import 'core-js/es6/string';
 import 'core-js/es6/date';
 import 'core-js/es6/array';
 import 'core-js/es6/regexp';
 import 'core-js/es6/map';
 import 'core-js/es6/weak-map';
 import 'core-js/es6/set';
 import 'reflect-metadata';
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
 import 'classlist.js';  // Run `npm install --save classlist.js`.

/** Evergreen browsers require these. **/
import 'core-js/es6/reflect';
import 'core-js/es7/reflect';


/**
 * Required to …
Run Code Online (Sandbox Code Playgroud)

typescript angular-cli angular

14
推荐指数
2
解决办法
1万
查看次数

如何使用角度示意图覆盖文件?

我想写一个Rule每次都覆盖一个文件.在下面并MergeStrategy设置为Overwrite:

collection.json

{
  "$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
  "schematics": {
    "function": {
      "aliases": [ "fn" ],
      "factory": "./function",
      "description": "Create a function.",
      "schema": "./function/schema.json"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

function/index.ts

export default function(options: FunctionOptions): Rule {
  options.path = options.path ? normalize(options.path) : options.path;
  const sourceDir = options.sourceDir;
  if (!sourceDir) {
    throw new SchematicsException(`sourceDir option is required.`);
  }

  const templateSource: Source = apply(
    url('./files'),
    [
      template({
        ...strings,
        ...options,
      }),
      move(sourceDir),
    ]
  )

  return mergeWith(templateSource, MergeStrategy.Overwrite);

}
Run Code Online (Sandbox Code Playgroud)

files/__path__/__name@dasherize__.ts

export function <%= …
Run Code Online (Sandbox Code Playgroud)

angular-cli angular angular-schematics

14
推荐指数
2
解决办法
3058
查看次数

ng serve --prod throws"ERROR TypeError:(void 0)不是函数"

所以当在Angular-CLI app中遇到麻烦时.

这是发生的事情: ng serve,不ng serve --aot产生例外,一切正常.只ng serve --prod在浏览应用程序时运行休息时间.

错误TypeError:(void 0)不是函数

正在寻找答案,并发现这些不是,所以我在应用程序中的每个属性之前写了'public'并检查提供程序中是否有函数调用,但没有任何改变.

接下来我尝试用--aot旗帜运行它并且工作得很好,但是在--prod出现相同错误时仍然崩溃.

它在runnig登录过程中完全崩溃,这是:

  • 使用登录名和密码数据发送http POST
  • 如果请求解析,则调度ngRx-Store自定义登录事件(简单标志)
  • 然后router.navigateByUrl到另一个页面

奇怪的是,我到处都有类似的过程,但它在确切的位置崩溃了.

可以请有人给我一些信息,我应该在哪下挖?干杯!


更新:我在登录过程的每个部分都在切断代码,然后用--prod它构建它,结果发现来自@ angular/material的MatDialog产生了错误.在MatDialog登录组件使用afterClosed()挂钩到其父级解析后触发登录,并以某种方式产生异常.

因此,触发弹出窗口的父级是HeaderComponent,其中包含方法:

    openLoginDialog(): void {
        this.authService.login();
         const dialogRef = this.dialog.open(LoginDialogComponent);
         dialogRef.afterClosed().subscribe(result => {
           if (result) {
             this.authService.login();
           }
        });
      }
Run Code Online (Sandbox Code Playgroud)

在LoginDialogComponent里面是简单解决的方法:

    login(login, password) {
      this.authService.tryLogin(login, password).subscribe(data => {
        this.dialogRef.close(true);
      });
    }
Run Code Online (Sandbox Code Playgroud)

在我删除MatDialog后,另一个单词摆脱了项目中唯一的弹出窗口,错误消失了.我已经创建了另一个具有自己的Login表单路由的组件,但仍然认为删除整个工作模块是因为构建错误不是解决方案.

我的package.json:

    "dependencies": {
        "@angular/animations": "^5.0.2",
        "@angular/cdk": "^5.0.0-rc.1",
        "@angular/common": "^5.0.0",
        "@angular/compiler": "^5.0.0",
        "@angular/core": "^5.0.0",
        "@angular/flex-layout": …
Run Code Online (Sandbox Code Playgroud)

typeerror aot angular-cli angular

14
推荐指数
1
解决办法
2739
查看次数

如何使用Webpack或Angular CLI将角元素编译为Web组件?

我使用Pascal Precht的教程通过Angular构建了一个简单的Web组件,您可以在这里看到它.它自动神奇地编译链接中的Stackblitz,但不是本地.

我的最终目标是将生成的Web组件的代码放在本地的单独文件中.最终,我会将其上传到某处并通过单个<script>标签将其拉入,就像普通的raw-html/javascript Web Components一样.我认为问题不言自明,但如果您愿意,可以阅读以下详细信息:


细节:

要在上面的链接中总结我的代码,我有一个非常基本的组件:

import { Component } from '@angular/core';

@Component({
  selector: 'hello-world',
  template: `<h1>Hello world</h1>`
})

export class HelloComponent  {}
Run Code Online (Sandbox Code Playgroud)

我有一个模块:

import { NgModule, Injector } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { createCustomElement } from '@angular/elements'
import { HelloComponent } from './hello.component';

@NgModule({
  imports: [BrowserModule],
  declarations: [HelloComponent],
  entryComponents: [HelloComponent]
})

export class AppModule { 
  constructor(private injector: Injector) {}
  ngDoBootstrap() {
    const HelloElement = createCustomElement(HelloComponent, …
Run Code Online (Sandbox Code Playgroud)

webpack angular-cli angular angular-elements

14
推荐指数
2
解决办法
1890
查看次数

如何在Angular应用程序中包含其他ES6源代码

我有一个用ES6语法编写的自定义模式模块,我包含在我的角度应用程序中,当我尝试构建-prod启用了标志的应用程序时,我遇到了问题(来自uglifyjs):

Unexpected token: punc ()
Run Code Online (Sandbox Code Playgroud)

这是一个使用angular-cli 1.7.4的角度5 app.

我的节点模块的条目文件如下:

const MyModule = require('./src/index.js');

const myModule = new MyModule();

module.exports = {
  doStuff: myModule.doStuff,
  doOtherStuff: myModule.doOtherStuff
}
Run Code Online (Sandbox Code Playgroud)

然后这需要进入我的一个ts文件,如下所示:

import MyModule = require('@acme/mymodule');
Run Code Online (Sandbox Code Playgroud)

运行ng serve任务时,我没有问题,可以按预期使用该应用程序.

它在尝试生产生产构建时,我看到了这个问题.

在./src/index.js文件中,定义了许多使用const\let\async\await的函数.

阅读,我相信这是由我使用ES6和源角度cli执行构建步骤时与uglifyjs不兼容的源.

从我也读过,webpack配置可以从angular-cli配置控制,至少不在1.x中,否则我会尝试其中一个插件来帮助我解决这个问题.

我假设我需要在它遇到angular-cli之前通过额外的步骤运行代码,例如,使用babel来转换我的es6代码.

我正在努力寻找如何与angular和cli相关的示例,我可以找到如何使用babel并且能够在我的一个节点模块源上测试它并且可以看到这个生成的es5版本.

我实际上有4个节点模块,其中一些需要彼此,所以我想确保它们在被转换后仍然可以相互要求.

顺便说一句,不知道它有多相关,但在我的polyfills.ts文件中启用了以下polyfill:

import "core-js/es5";
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/weak-map';
import 'core-js/es6/set';
Run Code Online (Sandbox Code Playgroud)

我感谢您提供的任何建议!

谢谢

UPDATE

我已经制作了一个最小的Angular 5应用程序,它使用了1.x的angular-cli.我已在此复制了构建行为,这也会从UglifyJS生成错误. …

uglifyjs ecmascript-6 webpack angular-cli angular

14
推荐指数
1
解决办法
638
查看次数