RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 623075
Accepted
Kostiantyn Okhotnyk
Kostiantyn Okhotnyk
Asked:2020-02-04 00:19:44 +0000 UTC2020-02-04 00:19:44 +0000 UTC 2020-02-04 00:19:44 +0000 UTC

Angular2 应用程序缩小。加载时间优化

  • 772

请帮助我了解应用程序的优化。Angular2上有应用。我按照这篇文章做了最小化。没有网络包。团队

 browserify -s main dist/main.js > dist/bundle.js

和

uglifyjs dist/bundle.js --screw-ie8 --compress --mangle --output dist/bundle.min.js

结果是最小化束,但需要 1.7 米。该项目的 app.module.ts 结构在我看来非常大。

@NgModule({
  imports: [
    BrowserModule,
    CommonModule,
    FormsModule,
    Ng2PaginationModule,
    HttpModule,
    FormsModule,
    DatePickerModule,
    Ng2GoogleChartsModule,
    routing,
    AgmCoreModule.forRoot({
      apiKey: 'AIzaSyAqIBAiCeLH9A5I5lqEK3iK1j3gAmL3yIg',
      libraries:['geometry', 'places']
    })
  ],
  declarations: [
    MainComponent,
    AuthComponent,
    RecoveryComponent,
    BaseComponent,
    IndexComponent,
    UsersComponent,
    ActiveDriversComponent,
    AdminsComponent,
    ClientComponent,
    DriversApplicationsComponent,
    ActiveDriverComponent,
    ActivationComponent,
    OrdersCanceledComponent,
    AllOrderForDriverComponent,
    NewUserComponent,
    DriverRateComponent,
    DeterminationErrors,
    HttpPopupErrors,
    TranslatePipe,
    CKEditorComponent,
    OrdersComponent,
    SelectLanguageComponent,
    SelectRoleComponent,
    SelectNoticeComponent,
    CurrentOrdersComponent,
    NotConfirmedComponent,
    DeferredOrdersComponent,
    CompletedOrdersComponent,
    AbolishedOrdersComponent,
    DriversOffersComponent,
    EvaluationEditorComponent,
    NewOrderComponent,
    OrderInfoComponent,
    PermissionDeniedComponent,
    SelectBoxComponent,
    NewsComponent,
    CreateNewsComponent,
    EditNewsComponent,
    PublishedNewsComponent,
    SelectFilterComponent,
    ChangeStatusComponent,
    PaymentsTemplatesComponent,
    PaymentsComponent,
    NewTemplateComponent,
    NewTemplateComponent,
    ChangePasswordComponent,
    EditTemplateComponent,
    SupportComponent,
    TemplatesComponent,
    DraftsComponent,
    AppealsMessagesComponent,
    NotificationsComponent,
    NotificationComponent,
    CountriesComponent,
    AddCountryComponent,
    AddCityComponent,
    EditCountryComponent,
    EditCityComponent,
    CurrentBalanceComponent,
    MarkerClusterDirective,
    DriverMapDirective,
    PersonalDirective,
    AllInfoDirective,
    StatisticDirective,
    SearchDirective,
    DateRangePickerDirective,
    PersonalAutoDirective,
    DocumentsDirective,
    PaginationDirective,
    HelpersDirective,
    SimpleRateDirective,
    FilterPipe,
    PluralPipe
  ],
  providers: [
    Urls,
    User,
    SearchModel,
    HttpService,
    CurrencyService,
    Md5,
    DeterminationErrorService,
    TRANSLATION_PROVIDERS,
    TranslateService,
    LocationService
  ],
  schemas: [ CUSTOM_ELEMENTS_SCHEMA ],
  bootstrap:    [ MainComponent ]
})

与此相关,有一些问题。在这种情况下,模块的延迟加载是否有帮助,如果有帮助,那么如何将这个结构分解成单独的模块(原理本身不清楚)?
有没有其他方法可以优化应用程序?

angular2
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    Kostiantyn Okhotnyk
    2020-02-08T00:58:03Z2020-02-08T00:58:03Z

    问题就这样解决了。首先我决定用拐杖,然后我用 angular-cli 创建了一个新项目并将我的模块添加到它

    解决方法(拐杖)

    由于无法在没有 angular-cli 的情况下编译项目,因此我不得不使用加载程序制作一个 html 主干并将其插入 index.html。

    索引.html

    <body>
    
    <div id="auth_" style="display: none; height: 100%;">
      <div class="start-wrapper">
        <div class="popup-main-wrapper">
          <div class="tax-wrapper">
    
          </div>
          <div class="popup-title-wrapper">
            <p class="popup-title">Авторизация</p>
          </div>
          <div class="popup-body-wrapper" style="position: relative">
            <div id="ajax-loader__auth" class="ajax-loader__auth">
              <img src="/img/3.gif" />
            </div>
          </div>
        </div>
      </div>
    </div>
     .....
     <my-app></my-app>
     ...
    
      $(document).ready(function() {$('#auth_').show();)} // Показывает html блок с лоудер
    

    我在文件中隐藏了auth.component.ts块

    ngOnInit() {
        $('#auth_').hide();
    }
    

    这个解决方案很快,不需要很多时间。

    第二种方式更复杂,更耗时。

    使用 angular-cli 构建应用程序

    在本地安装 angular-cli。为此,请在控制台中运行。

    npm install -g @angular/cli
    

    第二步是移植代码。这是最困难和最常规的阶段,因为项目的版本是 2.0.0,而创建项目的版本是 2.3。因此,我们不得不重写一些组件的导入。但结果,为了释放

    创建 AOT 构建

    ng build --prod --aot
    ng serve --prod --aot
    
    • 5

相关问题

  • 如何摆脱错误“类型‘订阅者[]’上不存在属性‘数据’”?角度 2

  • 根据角色删除页面元素?

  • 如何将多个订阅者订阅到一个观察者

  • 在 Heroku 上部署 Spring Boot+Angular2 应用程序

  • 在angular2 + web audio api上听音乐

  • Angular 2无法匹配任何路线

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    Python 3.6 - 安装 MySQL (Windows)

    • 1 个回答
  • Marko Smith

    C++ 编写程序“计算单个岛屿”。填充一个二维数组 12x12 0 和 1

    • 2 个回答
  • Marko Smith

    返回指针的函数

    • 1 个回答
  • Marko Smith

    我使用 django 管理面板添加图像,但它没有显示

    • 1 个回答
  • Marko Smith

    这些条目是什么意思,它们的完整等效项是什么样的

    • 2 个回答
  • Marko Smith

    浏览器仍然缓存文件数据

    • 1 个回答
  • Marko Smith

    在 Excel VBA 中激活工作表的问题

    • 3 个回答
  • Marko Smith

    为什么内置类型中包含复数而小数不包含?

    • 2 个回答
  • Marko Smith

    获得唯一途径

    • 3 个回答
  • Marko Smith

    告诉我一个像幻灯片一样创建滚动的库

    • 1 个回答
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Алексей Шиманский 如何以及通过什么方式来查找 Javascript 代码中的错误? 2020-08-03 00:21:37 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    user207618 Codegolf——组合选择算法的实现 2020-10-23 18:46:29 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5