如何生成一个角度项目的构建?

时间:2019-01-09 20:14:23

标签: angular

我正在尝试在Angular中构建项目的构建,但是每次为它运行命令 ng build 时,都会看到一些错误,但是搜索无法解决,有人可以点灯吗?

E:\ Sistemas \ sourcecode> ng build --source-map = false --prod --deploy-url = client /

Date: 2019-01-09T17:29:00.855Z
Hash: 00b6ba86f5c09a5273e8
Time: 121743ms
chunk {0} runtime.8004edb872d7c3b82213.js (runtime) 1.41 kB [entry] [rendered]
chunk {1} main.9868d9b237c3a48c54da.js (main) 128 bytes [initial] [rendered]
chunk {2} polyfills.85f47f0bf59079cbc23a.js (polyfills) 130 bytes [initial] [rendered]
chunk {3} styles.0befdcbdc7f0c4753cdc.css (styles) 75.2 kB [initial] [rendered]

ERROR in src/common/uploads/utils/upload-progress-event.ts(47,17): error TS2322: Type 'HttpEventType.UploadProgress | HttpEventType.DownloadProgress' is not assignable to type 'HttpEventType.Sent | HttpEventType.UploadProgress | HttpEventType.Response'.
  Type 'HttpEventType.DownloadProgress' is not assignable to type 'HttpEventType.Sent | HttpEventType.UploadProgress | HttpEventType.Response'.
src/common/uploads/uploaded-file.ts(19,34): error TS2339: Property 'webkitRelativePath' does not exist on type 'File'.
src/common/uploads/uploaded-file.ts(27,25): error TS2345: Argument of type 'string | ArrayBuffer' is not assignable to parameter of type 'string | PromiseLike<string>'.
  Type 'ArrayBuffer' is not assignable to type 'string | PromiseLike<string>'.
    Type 'ArrayBuffer' is not assignable to type 'string'.
src/common/uploads/utils/create-upload-input.ts(31,15): error TS2339: Property 'webkitdirectory' does not exist on type 'HTMLInputElement'.
src/common/uploads/utils/read-uploaded-folders.ts(3,52): error TS2304: Cannot find name 'WebKitEntry'.
src/common/uploads/utils/read-uploaded-folders.ts(10,58): error TS2304: Cannot find name 'WebKitFileEntry'.
src/common/uploads/utils/read-uploaded-folders.ts(12,66): error TS2304: Cannot find name 'WebKitDirectoryEntry'.
src/common/uploads/utils/read-uploaded-folders.ts(19,40): error TS2304: Cannot find name 'WebKitDirectoryEntry'.
src/common/uploads/utils/read-uploaded-folders.ts(26,50): error TS2304: Cannot find name 'WebKitDirectoryEntry'.
src/common/uploads/utils/read-uploaded-folders.ts(28,63): error TS2304: Cannot find name 'WebKitFileEntry'.
src/common/uploads/utils/read-uploaded-folders.ts(35,27): error TS2304: Cannot find name 'WebKitDirectoryEntry'.
src/common/uploads/utils/read-uploaded-folders.ts(35,58): error TS2304: Cannot find name 'WebKitEntry'.
src/common/uploads/utils/read-uploaded-folders.ts(42,36): error TS2304: Cannot find name 'WebKitFileEntry'.

这是我的tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./src",
    "paths": {
      "common": [
        "common/"
      ]
    },
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "skipLibCheck": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

这是我的read-uploaded-folders.ts

import { UploadedFile } from '../uploaded-file';

export async function readUploadedFolders(entries: WebKitEntry[]): Promise<UploadedFile[]> {
    let files = [];

    for (const key in entries) {
        const entry = entries[key];

        if ( ! entry.isDirectory) {
            files.push(await transformFileEntry(entry as WebKitFileEntry));
        } else {
            files = files.concat(await readDirRecursive(entry as WebKitDirectoryEntry));
        }
    }

    return files;
}

async function readDirRecursive(entry: WebKitDirectoryEntry, files = []) {
    const entries = await readEntries(entry);

    for (const key in entries) {
        const childEntry = entries[key];

        if (childEntry.isDirectory) {
            await readDirRecursive(childEntry as WebKitDirectoryEntry, files);
        } else {
            files.push(await transformFileEntry(childEntry as WebKitFileEntry));
        }
    }

    return files;
}

function readEntries(dir: WebKitDirectoryEntry): Promise<WebKitEntry[]> {
    return new Promise(resolve => {
        const reader = dir.createReader();
        reader.readEntries(entries => resolve(entries as any));
    });
}

function transformFileEntry(entry: WebKitFileEntry) {
    return new Promise(resolve => {
        entry.file((file: any) => {
            resolve(new UploadedFile(file as File, entry.fullPath));
        });
    });
}

这是我的upload-progress-event.ts

import { HttpEvent, HttpEventType } from '@angular/common/http';
import { getUploadProgress } from './get-upload-progress';
import { getUploadSpeed } from './get-upload-speed';
import { getUploadETA } from './get-upload-eta';
import { prettyUploadETA } from './pretty-upload-eta';
import { prettyBytes } from '../../core/utils/pretty-bytes';
import { FileEntry } from '../file-entry';
import { BackendResponse } from '../../core/types/backend-response';

export enum UploadEventTypes {
    STARTED = 'uploadStarted',
    PROGRESS = 'uploadProgress',
    COMPLETED = 'uploadCompleted',
    OTHER = 'unrecognizedEvent'
}

export interface UploadCompletedEvent {
    type: HttpEventType.Response;
    name: UploadEventTypes.COMPLETED;
    fileEntry: FileEntry;
}

export interface UploadProgressEvent {
    type: HttpEventType.UploadProgress;
    name: UploadEventTypes.PROGRESS;
    totalBytes: number;
    completedBytes: number;
    progress: number;
    speed: string;
    eta: string;
}

export interface UploadStartedEvent {
    type: HttpEventType.Sent;
    name: UploadEventTypes.STARTED;
    time: number;
}

export type UploadEvent = UploadStartedEvent | UploadCompletedEvent | UploadProgressEvent;

export function transformAngularUploadEvent<T>(e: HttpEvent<{fileEntry: FileEntry}>, uploadStarted: number): UploadEvent {
    switch (e.type) {
        case HttpEventType.Sent:
            return {type: e.type, name: UploadEventTypes.STARTED, time: uploadStarted};
        case HttpEventType.UploadProgress:
            return {
                type: e.type,
                name: UploadEventTypes.PROGRESS,
                totalBytes: e.total,
                completedBytes: e.loaded,
                progress: getUploadProgress(e),
                speed: prettyBytes(getUploadSpeed(e, uploadStarted)),
                eta: prettyUploadETA(getUploadETA(e, uploadStarted)),
            };
        case HttpEventType.Response:
            return {type: e.type, name: UploadEventTypes.COMPLETED, fileEntry: e.body.fileEntry};
        default:
            return null;
    }
}

1 个答案:

答案 0 :(得分:0)

默认情况下,当您为生产# Notice I removed the () after up_right so it doesn't make the function call on this line choose = (up_right, down_right) # random.choice will return one of the two, and then the () will call whatever function was chosen random.choice(choose)() 进行构建时,角度编译器会使用ng build --prod标志(在aot: true节点下的angular.json文件中指定)。您可以检查configurations\production的要求https://angular.io/guide/aot-compiler(要注意的是模板中使用的属性/方法必须是公共的)