我想在Asp.Net Core上使用Angular 2的語義UI。我已經從JavaScript services官方Yeoman模板開始使用aspnetcore-spa
項目模板,該模板已經配置了Asp.Net MVC Core,Webpack,Angular 2和Bootstrap。在Asp.Net Core Spa模板上使用帶有webpack的語義UI
然後,我試着按照this GitHub上描述的步驟安裝Semantic UI。我做
步驟:
- 安裝使用NPM
npm install semantic-ui --save
- 在設置語義UI,我安裝了所有的功能和選擇的安裝文件夾
wwwroot/lib/semantic/
- 在設置語義UI,我安裝了所有的功能和選擇的安裝文件夾
- 去了
wwwroot/lib/semantic
文件夾並運行gulp build
這就是我開始真的不確定的地方,在模板結構中沒有,所以我不確定將語義CSS和js導入到哪裏。
我唯一能找到的是webpack.config.vendor.js
,它包含Bootstrap的一些條目,所以我修改了vendor
屬性併爲語義js和css添加了導入。
以下是我修改了它:
entry: {
vendor: [
'@angular/common',
'@angular/compiler',
'@angular/core',
'@angular/http',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'@angular/router',
'@angular/platform-server',
'angular2-universal',
'angular2-universal-polyfills',
'es6-shim',
'es6-promise',
'event-source-polyfill',
'jquery',
'zone.js',
'wwwroot/lib/semantic/dist/semantic.min.js',
'wwwroot/lib/semantic/dist/semantic.min.css',
'ng-semantic'
]
}
我刪除引用來引導和增加,semantic.min.css
和ng-semantic
。
最後,我使用NPM安裝了Ng-Semantic
,並將import { NgSemanticModule } from 'ng-semantic'
加入了app.module.ts
。
現在,當我嘗試運行應用程序時,我收到以下錯誤:
System.Exception: Call to Node module failed with error: Prerendering failed because of error: ReferenceError: jQuery is not defined
我得到的這個錯誤是由系統試圖預渲染一些代碼依賴於jQuery的這是造成一個很大的禁忌,它可能是semantic-ui.js。但我完全不知道如何解決這個問題。
爲了便於參考和排除故障,我將代碼的當前狀態推送到GitHub上,它的地址爲this address。
在此先感謝!
嘗試刪除'應用-prerenderer-module'屬性https://stackoverflow.com/questions/40257514/call-to-node-module-failed-with-errors-with-angular2-asp-net – yurzui
那麼,確保刪除預渲染將肯定解決問題,但我想要一個解決方案,我可以保持預渲染。 – Gimly