使用 Webpack 将 PrimeNG 添加到 Angular2 应用程序中
Add PrimeNG into Angular2 app using Webpack
我正在尝试将 PrimeNG 加载到我的 Webpack 捆绑 Angular2 应用程序中。
首先我安装了一个 npm:
npm install primeng --save
npm install primeui --save
这向我的 package.json 添加了以下两行:
+ "primeng": "^1.0.0-beta.8",
+ "primeui": "^4.1.12",
接下来,如 angular2-webpack-starter 中的 github commit 所示,我将导入添加到 venders.ts
:
import 'script!primeui/primeui-ng-all.min.js';
似乎script!
是我的webpack 不知道该怎么做的某种特殊的东西。我得到这个:
ERROR in ./src/vendor.ts
Module not found: Error: Cannot resolve module 'script' in /SomeDir/src
@ ./src/vendor.ts 14:0-47
Child html-webpack-plugin for "index.html":
chunk {0} index.html 570 kB
+ 4 hidden modules
webpack: bundle is now VALID.
我不确定这是否有问题。我的应用程序仍在加载...
继续,我将以下两个导入添加到我的 AppComponent 中:
import {TabView} from 'primeng/primeng';
import {TabPanel} from 'primeng/primeng';
这会生成以下附加警告:
webpack: bundle is now VALID.
[default] Checking started in a separate process...
[default] /.../node_modules/primeng/components/breadcrumb/breadcrumb.d.ts:3:24
Cannot find module '@angular/router'.
[default] /.../someDir/node_modules/primeng/components/contextmenu/contextmenu.d.ts:4:24
Cannot find module '@angular/router'.
[default] /.../someDir/node_modules/primeng/components/megamenu/megamenu.d.ts:4:24
Cannot find module '@angular/router'.
[default] /.../someDir/node_modules/primeng/components/menu/menu.d.ts:4:24
Cannot find module '@angular/router'.
[default] /.../someDir/node_modules/primeng/components/menubar/menubar.d.ts:4:24
Cannot find module '@angular/router'.
[default] /.../someDir/node_modules/primeng/components/panelmenu/panelmenu.d.ts:3:24
Cannot find module '@angular/router'.
[default] /.../someDir/node_modules/primeng/components/slidemenu/slidemenu.d.ts:4:24
Cannot find module '@angular/router'.
[default] /.../someDir/node_modules/primeng/components/splitbutton/splitbutton.d.ts:4:24
Cannot find module '@angular/router'.
[default] /.../someDir/node_modules/primeng/components/tabmenu/tabmenu.d.ts:3:24
Cannot find module '@angular/router'.
[default] /.../someDir/node_modules/primeng/components/tieredmenu/tieredmenu.d.ts:5:24
Cannot find module '@angular/router'.
问题:
- 如何使用 Webpack 将 PrimeNg 添加到 Angular2 项目中?
- 为什么我的
import 'script!'...
不工作?
- 为什么primeng找不到angular?
似乎我有两个独立的问题,它们都与我 package.json
中丢失的东西有关
第 1 期
It seems like script! is some kind of special thing that my webpack
doesn't know how to do. I am getting this:
ERROR in ./src/vendor.ts
Module not found: Error: Cannot resolve module 'script' in /SomeDir/src
@ ./src/vendor.ts 14:0-47
Child html-webpack-plugin for "index.html":
chunk {0} index.html 570 kB
+ 4 hidden modules
webpack: bundle is now VALID.
第 2 期
这里的问题是我遗漏了 script-loader
。我通过执行以下操作解决了这个问题:
npm install script-loader --save
参见 - Using Loaders
This generates the following additional warnings:
webpack: bundle is now VALID. [default] Checking started in a separate
process... [default]
/.../node_modules/primeng/components/breadcrumb/breadcrumb.d.ts:3:24
Cannot find module '@angular/router'. [default] /.../someDir/node_modules/primeng/components/contextmenu/contextmenu.d.ts:4:24
Cannot find module '@angular/router'. [default] /.../someDir/node_modules/primeng/components/megamenu/megamenu.d.ts:4:24
Cannot find module '@angular/router'. [default] /.../someDir/node_modules/primeng/components/menu/menu.d.ts:4:24
Cannot find module '@angular/router'. [default] /.../someDir/node_modules/primeng/components/menubar/menubar.d.ts:4:24
Cannot find module '@angular/router'. [default] /.../someDir/node_modules/primeng/components/panelmenu/panelmenu.d.ts:3:24
Cannot find module '@angular/router'. [default] /.../someDir/node_modules/primeng/components/slidemenu/slidemenu.d.ts:4:24
Cannot find module '@angular/router'. [default] /.../someDir/node_modules/primeng/components/splitbutton/splitbutton.d.ts:4:24
Cannot find module '@angular/router'. [default] /.../someDir/node_modules/primeng/components/tabmenu/tabmenu.d.ts:3:24
Cannot find module '@angular/router'. [default] /.../someDir/node_modules/primeng/components/tieredmenu/tieredmenu.d.ts:5:24
Cannot find module '@angular/router'.
将路由器添加到我的 package.json
解决了这个问题:
"@angular/router": "2.0.0-rc.1",
我正在尝试将 PrimeNG 加载到我的 Webpack 捆绑 Angular2 应用程序中。
首先我安装了一个 npm:
npm install primeng --save
npm install primeui --save
这向我的 package.json 添加了以下两行:
+ "primeng": "^1.0.0-beta.8",
+ "primeui": "^4.1.12",
接下来,如 angular2-webpack-starter 中的 github commit 所示,我将导入添加到 venders.ts
:
import 'script!primeui/primeui-ng-all.min.js';
似乎script!
是我的webpack 不知道该怎么做的某种特殊的东西。我得到这个:
ERROR in ./src/vendor.ts
Module not found: Error: Cannot resolve module 'script' in /SomeDir/src
@ ./src/vendor.ts 14:0-47
Child html-webpack-plugin for "index.html":
chunk {0} index.html 570 kB
+ 4 hidden modules
webpack: bundle is now VALID.
我不确定这是否有问题。我的应用程序仍在加载...
继续,我将以下两个导入添加到我的 AppComponent 中:
import {TabView} from 'primeng/primeng';
import {TabPanel} from 'primeng/primeng';
这会生成以下附加警告:
webpack: bundle is now VALID.
[default] Checking started in a separate process...
[default] /.../node_modules/primeng/components/breadcrumb/breadcrumb.d.ts:3:24
Cannot find module '@angular/router'.
[default] /.../someDir/node_modules/primeng/components/contextmenu/contextmenu.d.ts:4:24
Cannot find module '@angular/router'.
[default] /.../someDir/node_modules/primeng/components/megamenu/megamenu.d.ts:4:24
Cannot find module '@angular/router'.
[default] /.../someDir/node_modules/primeng/components/menu/menu.d.ts:4:24
Cannot find module '@angular/router'.
[default] /.../someDir/node_modules/primeng/components/menubar/menubar.d.ts:4:24
Cannot find module '@angular/router'.
[default] /.../someDir/node_modules/primeng/components/panelmenu/panelmenu.d.ts:3:24
Cannot find module '@angular/router'.
[default] /.../someDir/node_modules/primeng/components/slidemenu/slidemenu.d.ts:4:24
Cannot find module '@angular/router'.
[default] /.../someDir/node_modules/primeng/components/splitbutton/splitbutton.d.ts:4:24
Cannot find module '@angular/router'.
[default] /.../someDir/node_modules/primeng/components/tabmenu/tabmenu.d.ts:3:24
Cannot find module '@angular/router'.
[default] /.../someDir/node_modules/primeng/components/tieredmenu/tieredmenu.d.ts:5:24
Cannot find module '@angular/router'.
问题:
- 如何使用 Webpack 将 PrimeNg 添加到 Angular2 项目中?
- 为什么我的
import 'script!'...
不工作? - 为什么primeng找不到angular?
似乎我有两个独立的问题,它们都与我 package.json
中丢失的东西有关第 1 期
It seems like script! is some kind of special thing that my webpack doesn't know how to do. I am getting this:
ERROR in ./src/vendor.ts Module not found: Error: Cannot resolve module 'script' in /SomeDir/src @ ./src/vendor.ts 14:0-47 Child html-webpack-plugin for "index.html": chunk {0} index.html 570 kB + 4 hidden modules webpack: bundle is now VALID.
第 2 期
这里的问题是我遗漏了 script-loader
。我通过执行以下操作解决了这个问题:
npm install script-loader --save
参见 - Using Loaders
This generates the following additional warnings:
webpack: bundle is now VALID. [default] Checking started in a separate process... [default] /.../node_modules/primeng/components/breadcrumb/breadcrumb.d.ts:3:24 Cannot find module '@angular/router'. [default] /.../someDir/node_modules/primeng/components/contextmenu/contextmenu.d.ts:4:24
Cannot find module '@angular/router'. [default] /.../someDir/node_modules/primeng/components/megamenu/megamenu.d.ts:4:24 Cannot find module '@angular/router'. [default] /.../someDir/node_modules/primeng/components/menu/menu.d.ts:4:24 Cannot find module '@angular/router'. [default] /.../someDir/node_modules/primeng/components/menubar/menubar.d.ts:4:24 Cannot find module '@angular/router'. [default] /.../someDir/node_modules/primeng/components/panelmenu/panelmenu.d.ts:3:24 Cannot find module '@angular/router'. [default] /.../someDir/node_modules/primeng/components/slidemenu/slidemenu.d.ts:4:24 Cannot find module '@angular/router'. [default] /.../someDir/node_modules/primeng/components/splitbutton/splitbutton.d.ts:4:24 Cannot find module '@angular/router'. [default] /.../someDir/node_modules/primeng/components/tabmenu/tabmenu.d.ts:3:24 Cannot find module '@angular/router'. [default] /.../someDir/node_modules/primeng/components/tieredmenu/tieredmenu.d.ts:5:24 Cannot find module '@angular/router'.
将路由器添加到我的 package.json
解决了这个问题:
"@angular/router": "2.0.0-rc.1",