angular.js - Angular 2: 如何在運(yùn)行時(shí)自動(dòng)引入 normalize.css 文件?
問(wèn)題描述
最近學(xué)習(xí) Angular 2 的時(shí)候發(fā)現(xiàn) HTML 5 的通病 body margin:8px 依然存在,就像引入 normalize.css 丟棄這些不需要的樣式。
傳統(tǒng)的方式是直接引入 .css 文件,如:<link rel='stylesheet' href='http://www.lshqa.cn/wenda/node_modules/normalize.css/normalize.css' /> ,但是我現(xiàn)在想讓 Angular 通過(guò) import 模塊的方式自動(dòng)為 index.html 引入 normalize.css 樣式表。
我先是按照之前引入 Material 2 的方式:
// angular-cli-build.jsmodule.exports = function(defaults) { return new Angular2App(defaults, { vendorNpmFiles: [ ’normalize-path/index.js’, ] });};
// system-config.ts const map: any = { ’normalize’: ’vendor/normalize-path’,};/** User packages configuration. */const packages: any = { ’normalize’: {main: ’index.js’},};
// app.component.tsimport { normalize } from ’normalize-path’;
這時(shí)編輯器會(huì)提示:
Cannot find module ’normalize-path’.
并且編譯也不通過(guò),也許我的出發(fā)點(diǎn)是錯(cuò)的。
我嘗試去 stackoverflow 尋找答案但是沒(méi)有找到,Google 也沒(méi)找到相關(guān)問(wèn)題的博文或討論。
問(wèn)題解答
回答1:oc.lazyLoad試試
回答2:建議使用angular-cli來(lái)開(kāi)發(fā)在.angular-cli.json中配置:
'styles': ['styles.css','../node_modules/normalize.css/normalize.css' ]
相關(guān)文章:
1. Python爬蟲(chóng)如何爬取span和span中間的內(nèi)容并分別存入字典里?2. mysql - 把一個(gè)表中的數(shù)據(jù)count更新到另一個(gè)表里?3. 請(qǐng)教使用PDO連接MSSQL數(shù)據(jù)庫(kù)插入是亂碼問(wèn)題?4. python - 爬蟲(chóng)模擬登錄后,爬取csdn后臺(tái)文章列表遇到的問(wèn)題5. visual-studio - Python OpenCV: 奇怪的自動(dòng)補(bǔ)全問(wèn)題6. linux - Ubuntu下編譯Vim8(+python)無(wú)數(shù)次編譯失敗7. node.js - nodejs開(kāi)發(fā)中常用的連接mysql的庫(kù)8. mysql 查詢身份證號(hào)字段值有效的數(shù)據(jù)9. 視頻文件不能播放,怎么辦?10. mysql - 分庫(kù)分表、分區(qū)、讀寫(xiě)分離 這些都是用在什么場(chǎng)景下 ,會(huì)帶來(lái)哪些效率或者其他方面的好處
