使用angular-cli webpack創(chuàng)建多個包的方法
當(dāng)我使用angular-cli構(gòu)建項目時,它會將所有項目文件捆綁到一個主要的主包中.
我在應(yīng)用程序中使用了懶惰路由,一旦應(yīng)用程序加載,我就可以導(dǎo)航.
有沒有一種方法可以將主包分為多個基于懶惰加載的路由模塊的文件?
下面是角度-cli.json中的配置
{
"project": {
"version": "1.0.0-beta.15",
"name": "maddy-test-project"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": "styles/content",
"index": "default.htm",
"main": "main.ts",
"test": "test.ts",
"tsconfig": "tsconfig.json",
"prefix": "",
"mobile": false,
"styles": [
"styles.less"
],
"scripts": [
"styles/wfa-myriad-pro-typekit.js"
],
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"addons": [],
"packages": [],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "less",
"prefixInterfaces": false
}
}
下面是package.json
{
"name": "maddy-test-project",
"version": "0.0.1",
"license": "MIT",
"angular-cli": {},
"scripts": {
"start": "ng serve",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@angular/common": "2.0.0",
"@angular/compiler": "2.0.0",
"@angular/core": "2.0.0",
"@angular/forms": "2.0.0",
"@angular/http": "2.0.0",
"@angular/platform-browser": "2.0.0",
"@angular/platform-browser-dynamic": "2.0.0",
"@angular/router": "3.0.0",
"d3": "^4.2.3",
"jquery": "^3.1.0",
"lodash": "^4.15.0",
"moment": "^2.15.0",
"core-js": "^2.4.1",
"rxjs": "5.0.0-beta.12",
"toastr": "^2.1.2",
"ts-helpers": "^1.1.1",
"zone.js": "^0.6.23",
"bootstrap-daterangepicker": "^2.1.24"
},
"devDependencies": {
"@types/d3": "^3.5.35",
"@types/google-maps": "^3.1.27",
"@types/jasmine": "^2.2.30",
"@types/jquery": "^1.10.31",
"@types/lodash": "^4.14.34",
"@types/toastr": "^2.1.29",
"angular-cli": "1.0.0-beta.15",
"codelyzer": "~0.0.26",
"jasmine-core": "2.4.1",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "4.0.5",
"ts-node": "1.2.1",
"tslint": "3.13.0",
"typescript": "2.0.2"
}
}
提前致謝?。?/p>
它是NgModule和RouterModule.forChild()的作用.這是一個非常好的文章,用于啟動大型角度2模塊化應(yīng)用開發(fā): http://blog.angular-university.io/angular2-ngmodule/
The first thing that we need to do is to remove every mention of the Home component or the HomeModule from the App component and the main routing configuration:
We can see here that the App component no longer imports HomeModule, instead the routing config uses loadChildren to say that if /home or any other url starting with it gets hit, then the file home.module should be loaded via an Ajax call.
很快,為了在一個懶惰模塊中移動一些邏輯和組件,您可以運行以下命令:
ng g module child --routing
然后angular-cli將生成一個NgModule(app / child / child.module.ts)和一個子路由器配置(app / child / child-routing.module.ts).
延遲加載此子路由器的路由將是:
{ path: 'child', loadChildren: 'app/child/child.module#ChildModule' }
最后用一個約束移動你想要的ChildModule:其他模塊(作為AppModule)將無法使用任何ChildModule依賴項(例如服務(wù)).如果你需要它,一個很好的做法是創(chuàng)建一個共享模塊.
http://stackoverflow.com/questions/39619003/creating-multiple-bundles-using-angular-cli-webpack
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Angularjs 實現(xiàn)動態(tài)添加控件功能
這篇文章主要介紹了Angularjs 實現(xiàn)動態(tài)添加控件功能,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-05-05
AngularJs1.x自定義指令獨立作用域的函數(shù)傳入?yún)?shù)方法
今天小編就為大家分享一篇AngularJs1.x自定義指令獨立作用域的函數(shù)傳入?yún)?shù)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-10-10
將angular.js項目整合到.net mvc中的方法詳解
這篇文章主要給大家介紹了將angular.js項目整合到.net mvc中的相關(guān)資料,文中通過示例代碼將實現(xiàn)的過程介紹的非常詳細(xì),對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面跟著小編來一起看看吧。2017-06-06
AngularJS基于ui-route實現(xiàn)深層路由的方法【路由嵌套】
這篇文章主要介紹了AngularJS基于ui-route實現(xiàn)深層路由的方法,涉及AngularJS路由嵌套操作相關(guān)實現(xiàn)步驟與技巧,需要的朋友可以參考下2016-12-12
Angularjs全局變量被作用域監(jiān)聽的正確姿勢
這篇文章主要介紹了Angularjs全局變量被作用域監(jiān)聽的正確姿勢的相關(guān)資料,需要的朋友可以參考下2016-02-02
AngularJS教程之MVC體系結(jié)構(gòu)詳解
本文主要講解AngularJS MVC體系結(jié)構(gòu),這里提供詳細(xì)的教程供大家學(xué)習(xí)參考,有需要的小伙伴可以參考下2016-08-08

