我正在尝试创建Angular 6库并在Angular 6应用程序中使用它。我将其简化为一个最小的测试用例。(更新:自从Angular 7发布以来,我也尝试过这样做。)
ng new workspace # accept the defaults
ng new product # accept the defaults
cd workspace
ng generate library widgets
ng build --prod widgets # leave out "--prod" for Angular 7
cd ../product
ng build
名为“工作区”的应用程序托管一个名为“ widgets”的库。另一个名为“产品”的应用程序独立存在。至此一切都很好。
现在,让我们尝试在“产品”应用中使用“小部件”库。打开product/src/app/app.module.ts
由CLI生成的文件。如下所示添加两行。
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { WidgetsModule } from '../../../workspace/dist/widgets'; // added
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
WidgetsModule // added
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
更改之后,当我ng build
从产品目录运行时,我从Webpack收到警告。
Date: 2018-07-31T13:13:08.001Z
Hash: 8a6f58d2ae959edb3cc8
Time: 8879ms
chunk {main} main.js, main.js.map (main) 15.9 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 227 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 5.22 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 15.6 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 4.59 MB [initial] [rendered]
WARNING in ../workspace/node_modules/@angular/core/fesm5/core.js
4997:15-36 Critical dependency: the request of a dependency is an expression
WARNING in ../workspace/node_modules/@angular/core/fesm5/core.js
5009:15-102 Critical dependency: the request of a dependency is an expression
“依赖的结果是表达式”是什么意思?我究竟做错了什么?
这是
BrowserModule
导致出现这样的警告。我不知道原因,但似乎这是警告的来源。